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
Bloch vectors over time. |
Functions
Bloch vector of one qubit. |
|
Density matrix of a Bloch vector. |
|
Reduced density matrix of one qubit. |
|
Reduced density matrix of two qubits. |
|
Wootters concurrence of a two-qubit state. |
|
Entanglement overview of a pure multi-qubit state. |
|
Bloch vectors of every qubit. |
|
Smooth Bloch-sphere trajectory of every qubit of a Qiskit circuit, gate by gate. |
|
Trajectory of the belief qubit of the trust model over a sequence of events. |
|
Rotation of a Bloch vector about an axis (for demonstrations). |
|
Bloch vectors estimated from measurements on a simulator or quantum hardware. |
|
Circuits for single-qubit state tomography. |
- class Trajectory(vectors, labels=<factory>, names=<factory>, title='', states=<factory>)[source]#
Bases:
objectBloch vectors over time.
- Parameters:
vectors (
array_like) – Shape(frames, qubits, 3)(or(frames, 3)for one qubit).labels (
listofstr, optional) – One label per frame (for example the gate being applied).title (
str, optional) – Title for plots.states (
listofnumpy.ndarray, optional) – Full state per frame (circuit trajectories), needed forconcurrence().
- concurrence(a=0, b=1)[source]#
Concurrence of two qubits in every frame.
- Parameters:
- Returns:
- 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_likeorqiskit.quantum_info.StatevectororDensityMatrix) – 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 (
sequenceoffloat) –(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:
- Returns:
numpy.ndarray– 2 x 2 density matrix.
- reduced_density_pair(state, a, b, n)[source]#
Reduced density matrix of two qubits.
- Parameters:
- 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).
- 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
stepsfractional 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:
- Returns:
- rotation_trajectory(axis, angle, start=(0, 0, 1), steps=60)[source]#
Rotation of a Bloch vector about an axis (for demonstrations).
- Parameters:
- Returns:
- bloch_tomography(qc, backend='aer', shots=4000, seed=7)[source]#
Bloch vectors estimated from measurements on a simulator or quantum hardware.
- Parameters:
- Returns:
numpy.ndarray– Shape(n, 3).