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.

The State class and each of the factory functions used to create states are 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)

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
density_operator()

Compute the density operator for this pure state.

Returns:The density operator of this pure state.
Return type:DensityOperator
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
static from_column_vector(v)

QCircuits represents d-qubit states by type (d, 0) tensors. This function constructs a state from the more common column vector Kronecker-product representation of the state.

Parameters:complex128 multidimensional array (numpy) – The column vector representation of the state, of size 2**d.
Returns:A d-qubit state.
Return type:State
measure(qubit_indices=None, remove=False)

Measure the state with respect to the computational bases of the qubits indicated by qubit_indices. Measuring a state will modify the state in-place. 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. This method modifies the state in-place, but also returns the resulting state to allow chaining of operations.

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

The resulting state.

Return type:

State

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
reduced_density_operator(qubit_indices)

Compute the reduced density operator of the given qubits by tracing out the qubits not given.

Parameters:qubit_indices (iterable) – Indices indicating the qubit(s) that we compute the reduced density operator of.
Returns:The reduced density operator of the sub-system.
Return type:DensityOperator
renormalize_()

Renormalize the state so that the sum of squared amplitude magnitudes is 1.

schmidt_number(indices)

For a d-qubit state (d>1) in vector space \(A\otimes B\), get the Schmidt number, a measure of entanglement, for the Schmidt decomposition of that state for the subsystems A and B.

Parameters:indices (list of int) – The qubit indices for one of the subsystems. This should include at least one qubit index and also exclude at least one index.
Returns:The Schmidt number.
Return type:int
swap_qubits(axis1, axis2)

Swap two qubits in the state. Equivalent to crossing wires in a circuit. This method modifies the state in-place, but also returns the resulting state to allow chaining of operations.

Parameters:
  • axis1 (int) – First axis.
  • axis2 (int) – Second axis.
Returns:

The resulting state.

Return type:

State

to_column_vector()

QCircuits represents d-qubit states by type (d, 0) tensors. This function returns the more common column vector Kronecker-product representation of the state.

Returns:The column vector representation of the state.
Return type:numpy complex128 multidimensional array
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.
Returns:

A rank 2 tensor describing one of the four two-qubit Bell states. E.g., \(|\beta_{00}⟩ = \frac{1}{\sqrt{2}} (|00⟩ + |11⟩)\)

Return type:

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}.
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
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.
Returns:A d-rank tensor describing the all-one d-qubit computational basis vector, \(|1⟩^{\otimes d}\)
Return type: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 d-rank tensor describing the positive superposition for a d-qubit system, \(|+⟩^{\otimes d}.\)
Return type: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.
Returns:

A rank 1 tensor describing the state of a single qubit.

Return type:

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.
Returns:A d-rank tensor describing the all-zero d-qubit computational basis vector, \(|0⟩^{\otimes d}\)
Return type:State