uniqc.algorithmics.circuits.entangled_states module#

Entangled state preparation circuits: GHZ, W, and Cluster states.

uniqc.algorithmics.circuits.entangled_states.cluster_state(circuit, qubits=None, edges=None)[source]#

Prepare a cluster state (graph state).

A cluster state is prepared by:

  1. Applying Hadamard to all qubits: \(H^{\otimes n}\)

  2. Applying CZ (controlled-Z) on each edge of the graph

The resulting state is:

\[\frac{1}{\sqrt{2^n}} \sum_{x \in \{0,1\}^n} (-1)^{\sum_{(i,j) \in E} x_i x_j} |x\rangle\]
Parameters:
  • circuit (Circuit) – Quantum circuit to operate on (mutated in-place).

  • qubits (List[int] | None) – Qubit indices. None means all qubits of circuit.

  • edges (List[Tuple[int, int]] | None) – List of (source, target) pairs defining the entanglement graph. Indices refer to positions in qubits. None uses a linear nearest-neighbor chain: (0,1), (1,2), (2,3), ....

Raises:

ValueError – Fewer than 1 qubit.

Return type:

None

Example

>>> from uniqc.circuit_builder import Circuit
>>> from uniqc.algorithmics.circuits import cluster_state
>>> c = Circuit(4)
>>> cluster_state(c)  # linear chain
>>> # Custom graph (square)
>>> c2 = Circuit(4)
>>> cluster_state(c2, edges=[(0,1), (1,2), (2,3), (3,0)])
uniqc.algorithmics.circuits.entangled_states.ghz_state(circuit, qubits=None)[source]#

Prepare a GHZ (Greenberger–Horne–Zeilinger) state.

Produces the state:

\[\frac{1}{\sqrt{2}}(|00\ldots0\rangle + |11\ldots1\rangle)\]

Implementation:

  1. Hadamard on the first qubit: \(\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)\)

  2. Chain of CNOT gates: CNOT(q[0], q[1]), CNOT(q[1], q[2]), …

Parameters:
  • circuit (Circuit) – Quantum circuit to operate on (mutated in-place).

  • qubits (List[int] | None) – Qubit indices. None means all qubits of circuit.

Raises:

ValueError – Fewer than 2 qubits.

Return type:

None

Example

>>> from uniqc.circuit_builder import Circuit
>>> from uniqc.algorithmics.circuits import ghz_state
>>> c = Circuit(3)
>>> ghz_state(c)
uniqc.algorithmics.circuits.entangled_states.w_state(circuit, qubits=None)[source]#

Prepare a W state.

Produces the state:

\[\frac{1}{\sqrt{n}}(|10\ldots0\rangle + |01\ldots0\rangle + \ldots + |00\ldots1\rangle)\]

Implemented as a Dicke state \(|D(n,1)\rangle\) (equal superposition of all single-excitation computational basis states) via dicke_state_circuit() with k=1.

Parameters:
  • circuit (Circuit) – Quantum circuit to operate on (mutated in-place).

  • qubits (List[int] | None) – Qubit indices. None means all qubits of circuit.

Raises:

ValueError – Fewer than 2 qubits.

Return type:

None

Example

>>> from uniqc.circuit_builder import Circuit
>>> from uniqc.algorithmics.circuits import w_state
>>> c = Circuit(4)
>>> w_state(c)