# qcircuits.state module¶

The state module contains the State class, instances of which represent quantum states of multi-qubit systems, and factory functions for creating specific quantum states.

Each of the factory functions (but not the State class) is aliased at the top-level module, so that, for example, one can call qcircuits.zeros() instead of qcircuits.state.zeros().

class qcircuits.state.State(tensor)

A container class for a tensor representing the state of a quantum system, and associated methods.

Parameters: tensor (numpy complex128 multidimensional array) – The tensor representing the quantum state, giving the probability amplitudes.
amplitudes

Get the state tensor, i.e., the probability amplitudes.

Returns: The probability amplitudes of the state. numpy complex128 multidimensional array
dot(arg)

Give the dot product between this and another State.

Parameters: arg (State) – The state with which we take the dot product. The dot product with State arg. complex
measure(qubit_indices=None, remove=False)

Measure the state with respect to the computational bases of the qubits indicated by qubit_indices. Unlike operator application, with returns the resulting state, measuring a state will modify the state itself. If no indices are indicated, the whole state is measured.

Parameters: qubit_indices (int or iterable) – An index or indices indicating the qubit(s) whose computational bases the measurement of the state will be made with respect to. If no qubit_indices are given, the whole state is measured. remove (bool) – Indicates whether the measured qubits should be removed from the state vector. The measurement outcomes for the measured qubit(s). If the qubit_indices parameter is supplied as an int, an int is returned, otherwise a tuple. int or tuple of int
permute_qubits(axes, inverse=False)

Permute the qubits in the state. Equivalent to crossing wires in a circuit.

Parameters: axes (list of int) – Permute the qubits according to the values given. inverse (bool) – If true, perform the inverse permutation of the qubits.
probabilities

Get the probability of observing each computational basis vector upon making a measurement.

Returns: The probability associated with each computational basis vector. numpy float64 multidimensional array
swap_qubits(axis1, axis2)

Swap two qubits in the state. Equivalent to crossing wires in a circuit.

Parameters: axis1 (int) – First axis. axis2 (int) – Second axis.
qcircuits.state.bell_state(a=0, b=0)

Produce one of the four Bell states for a two-qubit system, $$|\beta_{ab}⟩$$.

Parameters: a ({0, 1}) – The computational basis state of the first qubit before entanglement. b ({0, 1}) – The computational basis state of the second qubit before entanglement. A rank 2 tensor describing one of the four two-qubit Bell states. E.g., $$|\beta_{00}⟩ = \frac{1}{\sqrt{2}} (|00⟩ + |11⟩)$$ State
qcircuits.state.bitstring(*bits)

Produce a computational basis state from a given bit sequence.

Parameters: bits – A variable number of arguments each in {0, 1}. If d arguments are supplied, returns a rank d tensor describing the computational basis state given by the sequence of input bits. State
qcircuits.state.ones(d=1)

Produce the all-one computational basis vector for d qubits. I.e., produces $$|1⟩^{\otimes d}$$.

Parameters: d (int) – The number of qubits d for which we produce a computational basis vector, and the rank of the produced tensor. A d-rank tensor describing the all-one d-qubit computational basis vector, $$|1⟩^{\otimes d}$$ State
qcircuits.state.positive_superposition(d=1)

Produce the positive superposition for a d qubit system, i.e., the state resulting from applying the Hadamard() gate to each of d |0⟩ computational basis states, $$H^{\otimes d}(|0⟩^{\otimes d}) = |+⟩^{\otimes d}.$$

Parameters: d (int) – The number of qubits d for the state. A d-rank tensor describing the positive superposition for a d-qubit system, $$|+⟩^{\otimes d}.$$ State
qcircuits.state.qubit(*, alpha=None, beta=None, theta=None, phi=None, global_phase=0.0)

Produce a given state for a single qubit.

Parameters: alpha (float) – The probability amplitude for the |0⟩ basis vector. Should not be specified in conjunction with theta or phi. beta (float) – The probability amplitude for the |1⟩ basis vector. Should not be specified in conjunction with theta or phi. theta (float) – The angle of the state between |0⟩ and |1⟩ on the Bloch sphere. Should not be specified in conjunction with alpha or beta. phi (float) – The phase of the |1⟩ component. Should not be specified in conjunction with alpha or beta. global_phase (float) – A global phase applied to the state. A rank 1 tensor describing the state of a single qubit. State
qcircuits.state.zeros(d=1)

Produce the all-zero computational basis vector for d qubits. I.e., produces $$|0⟩^{\otimes d}$$.

Parameters: d (int) – The number of qubits d for which we produce a computational basis vector, and the rank of the produced tensor. A d-rank tensor describing the all-zero d-qubit computational basis vector, $$|0⟩^{\otimes d}$$ State