qcircuits.state module¶
The state module contains the State class, instances of which represent quantum states of multiqubit systems, and factory functions for creating specific quantum states.
Each of the factory functions (but not the State class) is aliased at the toplevel module, so that, for example, one can call qcircuits.zeros()
instead of qcircuits.state.zeros()
.

class
qcircuits.state.
State
(tensor)¶ Bases:
qcircuits.tensors.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. Return type: 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. Returns: The dot product with State arg. Return type: 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.
Returns: 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.
Return type: 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. Return type: 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 twoqubit 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.
Returns: A rank 2 tensor describing one of the four twoqubit Bell states. E.g., \(\beta_{00}⟩ = \frac{1}{\sqrt{2}} (00⟩ + 11⟩)\)
Return type: See also
qubit()
,zeros()
,ones()
,bitstring()
,positive_superposition()

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}. Returns: If d arguments are supplied, returns a rank d tensor describing the computational basis state given by the sequence of input bits. Return type: State See also
qubit()
,zeros()
,ones()
,positive_superposition()
,bell_state()

qcircuits.state.
ones
(d=1)¶ Produce the allone 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. Returns: A drank tensor describing the allone dqubit computational basis vector, \(1⟩^{\otimes d}\) Return type: State See also
qubit()
,zeros()
,bitstring()
,positive_superposition()
,bell_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. Returns: A drank tensor describing the positive superposition for a dqubit system, \(+⟩^{\otimes d}.\) Return type: State See also

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.
Returns: A rank 1 tensor describing the state of a single qubit.
Return type: See also
zeros()
,ones()
,bitstring()
,positive_superposition()
,bell_state()

qcircuits.state.
zeros
(d=1)¶ Produce the allzero 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. Returns: A drank tensor describing the allzero dqubit computational basis vector, \(0⟩^{\otimes d}\) Return type: State See also
qubit()
,ones()
,bitstring()
,positive_superposition()
,bell_state()