Bloch vectors and trajectories#

Bloch-vector geometry and state trajectories (NumPy only).

A single-qubit density matrix \(\rho = (I + \vec r\cdot\vec\sigma)/2\) is represented by its Bloch vector \(\vec r\) with \(|\vec r| \le 1\): pure states lie on the sphere, mixed states inside, and the reduced state of an entangled qubit shrinks toward the centre.

Trajectories (Trajectory) hold arrays of shape (frames, qubits, 3) with one label per frame; every plotting function in quantum_mind.viz accepts them.

Examples

>>> import numpy as np
>>> from quantum_mind.viz import bloch_vector, bloch_vectors, concurrence
>>> bloch_vector([1, 1] / np.sqrt(2))                 # |+> points along +x
array([1., 0., 0.])
>>> bell = np.array([1, 0, 0, 1]) / np.sqrt(2)
>>> np.round(bloch_vectors(bell), 6)                 # both reduced states are maximally mixed
array([[0., 0., 0.],
       [0., 0., 0.]])
>>> round(concurrence(bell), 6)
1.0

Classes

Trajectory

Bloch vectors over time.

Functions

bloch_vector

Bloch vector of one qubit.

state_from_bloch

Density matrix of a Bloch vector.

reduced_density

Reduced density matrix of one qubit.

reduced_density_pair

Reduced density matrix of two qubits.

concurrence

Wootters concurrence of a two-qubit state.

entanglement_summary

Entanglement overview of a pure multi-qubit state.

bloch_vectors

Bloch vectors of every qubit.

circuit_trajectory

Smooth Bloch-sphere trajectory of every qubit of a Qiskit circuit, gate by gate.

belief_trajectory

Trajectory of the belief qubit of the trust model over a sequence of events.

rotation_trajectory

Rotation of a Bloch vector about an axis (for demonstrations).

bloch_tomography

Bloch vectors estimated from measurements on a simulator or quantum hardware.

tomography_circuits

Circuits for single-qubit state tomography.

class Trajectory(vectors, labels=<factory>, names=<factory>, title='', states=<factory>)[source]#

Bases: object

Bloch vectors over time.

Parameters:
  • vectors (array_like) – Shape (frames, qubits, 3) (or (frames, 3) for one qubit).

  • labels (list of str, optional) – One label per frame (for example the gate being applied).

  • names (list of str, optional) – Qubit names.

  • title (str, optional) – Title for plots.

  • states (list of numpy.ndarray, optional) – Full state per frame (circuit trajectories), needed for concurrence().

property frames#

number of frames.

Type:

int

property n_qubits#

number of qubits.

Type:

int

concurrence(a=0, b=1)[source]#

Concurrence of two qubits in every frame.

Parameters:
  • a (int, optional) – Qubits.

  • b (int, optional) – Qubits.

Returns:

numpy.ndarray

Raises:

ValueError – If the trajectory has no stored states (only circuit trajectories do).

purity()[source]#

Bloch-vector length per frame and qubit.

Returns:

numpy.ndarray – 1 for a pure (unentangled) qubit, 0 for a maximally mixed or maximally entangled one.

bloch_vector(state)[source]#

Bloch vector of one qubit.

Parameters:

state (array_like or qiskit.quantum_info.Statevector or DensityMatrix) – A 2-vector or a 2 x 2 density matrix.

Returns:

numpy.ndarray – (x, y, z) with \(r_k = \mathrm{tr}(\rho\,\sigma_k)\).

state_from_bloch(r)[source]#

Density matrix of a Bloch vector.

Parameters:

r (sequence of float) – (x, y, z).

Returns:

numpy.ndarray – \((I + \vec r\cdot\vec\sigma) / 2\).

reduced_density(state, q, n)[source]#

Reduced density matrix of one qubit.

Parameters:
  • state (array_like) – n-qubit state vector or density matrix (Qiskit order: qubit q = bit q of the basis index).

  • q (int) – Qubit to keep.

  • n (int) – Number of qubits.

Returns:

numpy.ndarray – 2 x 2 density matrix.

reduced_density_pair(state, a, b, n)[source]#

Reduced density matrix of two qubits.

Parameters:
  • state (array_like) – n-qubit state vector.

  • a (int) – Qubits to keep; index bit 0 of the result is qubit a.

  • b (int) – Qubits to keep; index bit 0 of the result is qubit a.

  • n (int) – Number of qubits.

Returns:

numpy.ndarray – 4 x 4 density matrix.

concurrence(rho)[source]#

Wootters concurrence of a two-qubit state.

Parameters:

rho (array_like) – 4 x 4 density matrix or 4-vector.

Returns:

float – 0 for separable states, 1 for maximally entangled ones (checked against Qiskit).

entanglement_summary(state, n=None)[source]#

Entanglement overview of a pure multi-qubit state.

Parameters:
  • state (array_like) – State vector.

  • n (int, optional) – Number of qubits (inferred from the length).

Returns:

dict – bloch_length: per-qubit Bloch-vector length (1 = not entangled with the rest); concurrence: n x n matrix of pairwise concurrences.

bloch_vectors(state, n=None)[source]#

Bloch vectors of every qubit.

Parameters:
  • state (array_like) – n-qubit state vector or density matrix.

  • n (int, optional) – Number of qubits.

Returns:

numpy.ndarray – Shape (n, 3).

circuit_trajectory(qc, steps=12, initial=None)[source]#

Smooth Bloch-sphere trajectory of every qubit of a Qiskit circuit, gate by gate.

Each unitary gate U is applied in steps fractional steps \(U^{k/\text{steps}}\), so rotations are drawn as arcs and entangling gates as vectors moving into the ball. Measurements, resets and barriers are skipped (the trajectory shows the coherent evolution); gates without a matrix (for example state preparation) are decomposed first.

Parameters:
  • qc (qiskit.QuantumCircuit)

  • steps (int, optional) – Frames per gate.

  • initial (array_like, optional) – Initial state (default all zeros).

Returns:

Trajectory – With the full state stored in every frame.

belief_trajectory(model, events, steps=12)[source]#

Trajectory of the belief qubit of the trust model over a sequence of events.

Each event (1 = success, 0 = failure) rotates the belief about the y axis of an OpenSystemBelief; dephasing of strength gamma then pulls the vector toward the z axis. The north pole \(|0\rangle\) means “yes, I trust the robot”.

Parameters:
  • model (OpenSystemBelief)

  • events (sequence of int)

  • steps (int, optional) – Frames per rotation and per dephasing.

Returns:

Trajectory

rotation_trajectory(axis, angle, start=(0, 0, 1), steps=60)[source]#

Rotation of a Bloch vector about an axis (for demonstrations).

Parameters:
  • axis (array_like) – Rotation axis.

  • angle (float) – Total angle.

  • start (array_like, optional) – Initial Bloch vector.

  • steps (int, optional) – Number of frames.

Returns:

Trajectory

bloch_tomography(qc, backend='aer', shots=4000, seed=7)[source]#

Bloch vectors estimated from measurements on a simulator or quantum hardware.

Parameters:
  • qc (qiskit.QuantumCircuit)

  • backend (str, optional) – Any backend string accepted by quantum_mind.circuits.run().

  • shots (int, optional) – Shots per basis.

  • seed (int, optional) – Simulator seed.

Returns:

numpy.ndarray – Shape (n, 3).

tomography_circuits(qc)[source]#

Circuits for single-qubit state tomography.

Parameters:

qc (qiskit.QuantumCircuit) – Circuit (final measurements are removed).

Returns:

dict – {'z': ..., 'x': ..., 'y': ...}: copies measured in the Z, X and Y bases on every qubit.