Quantum metrics and distance measures for quantum states and circuits.
This namespace provides algorithms for measuring similarity and overlap between quantum states using various quantum metrics:
These metrics are fundamental for quantum state tomography, quantum metrology, variational quantum algorithms, and quantum machine learning applications.
Quantum metrics and distance measures for quantum states and circuits. This namespace provides algorithms for measuring similarity and overlap between quantum states using various quantum metrics: - SWAP Test: Measures the inner product between two quantum states - Quantum Fisher Information Matrix (QFIM): Characterizes parameter sensitivity - Classical Fisher Information Matrix (CFIM): Characterizes measurement sensitivity These metrics are fundamental for quantum state tomography, quantum metrology, variational quantum algorithms, and quantum machine learning applications.
(classical-fisher-information-matrix
ansatz-fn
backend
parameters
&
{:keys [shots shift parallel? epsilon]
:or {shift (/ fm/PI 2) parallel? false epsilon 1.0E-10}
:as options})Calculates the Classical Fisher Information Matrix (CFIM) from measurement data.
The CFIM quantifies parameter sensitivity using measurement outcome probabilities instead of quantum state vectors. It is defined as:
F_ij = Σ_x [1/p(x|θ)] · [∂p(x|θ)/∂θᵢ] · [∂p(x|θ)/∂θⱼ]
where x ranges over all possible measurement outcomes and p(x|θ) is the probability of observing outcome x given parameters θ.
The CFIM is suitable for real quantum hardware (QPUs) where only measurement frequencies are available, not full state vectors. It provides a lower bound on the Quantum Fisher Information (QFIM ≥ CFIM).
Use Cases:
Parameters:
Returns: Classical Fisher Information Matrix as a vector of vectors (NxN matrix). The matrix is real-valued, symmetric, and positive semi-definite.
Example:
(defn my-ansatz [params]
(-> (circuit/create-circuit 2 "Ansatz")
(circuit/ry-gate 0 (nth params 0))
(circuit/ry-gate 1 (nth params 1))
(circuit/cnot-gate 0 1)
(circuit/measure-all-operation)))
(def cfim (classical-fisher-information-matrix
my-ansatz
qpu-backend
[0.5 1.0]
{:shots 8192}))
;=> [[1.95 0.02] [0.02 1.98]] ; With shot noise
References:
Calculates the Classical Fisher Information Matrix (CFIM) from measurement data.
The CFIM quantifies parameter sensitivity using measurement outcome probabilities
instead of quantum state vectors. It is defined as:
F_ij = Σ_x [1/p(x|θ)] · [∂p(x|θ)/∂θᵢ] · [∂p(x|θ)/∂θⱼ]
where x ranges over all possible measurement outcomes and p(x|θ) is the
probability of observing outcome x given parameters θ.
The CFIM is suitable for real quantum hardware (QPUs) where only measurement
frequencies are available, not full state vectors. It provides a lower bound
on the Quantum Fisher Information (QFIM ≥ CFIM).
Use Cases:
- Parameter optimization on real quantum hardware
- Natural gradient methods when state vector access is unavailable
- Quantum metrology with shot-limited measurements
- Variational algorithms on cloud-based QPUs (IBM, Rigetti, IonQ, etc.)
Parameters:
- ansatz-fn: Function that creates a quantum circuit from parameters.
Takes parameter vector, returns circuit with measurements.
- backend: Quantum backend for circuit execution (real QPU or shot-based simulator).
- parameters: Current parameter vector (vector of numbers).
- options: Map with:
- :shots - Number of measurements (required, e.g., 8192)
- :shift - Parameter shift for probability derivatives (default: π/2)
- :parallel? - Use parallel computation (default: false)
- :epsilon - Regularization for zero probabilities (default: 1e-10)
- Additional backend execution options
Returns:
Classical Fisher Information Matrix as a vector of vectors (NxN matrix).
The matrix is real-valued, symmetric, and positive semi-definite.
Example:
```clojure
(defn my-ansatz [params]
(-> (circuit/create-circuit 2 "Ansatz")
(circuit/ry-gate 0 (nth params 0))
(circuit/ry-gate 1 (nth params 1))
(circuit/cnot-gate 0 1)
(circuit/measure-all-operation)))
(def cfim (classical-fisher-information-matrix
my-ansatz
qpu-backend
[0.5 1.0]
{:shots 8192}))
;=> [[1.95 0.02] [0.02 1.98]] ; With shot noise
```
References:
- Stokes et al., "Quantum Natural Gradient", Quantum 4, 269 (2020)
- Cerezo et al., "Variational Quantum Algorithms", Nat. Rev. Phys. 3, 625 (2021)
- Liu et al., "Parameter Estimation on Quantum Hardware", arXiv:2107.09737(quantum-fisher-information-matrix
ansatz-fn
backend
parameters
&
{:keys [shift parallel?] :or {shift (/ fm/PI 2) parallel? false} :as options})Calculates the Quantum Fisher Information Matrix (QFIM) for a parameterized quantum state.
The QFIM characterizes the distinguishability of quantum states under parameter variations. It is defined as:
F_ij = 4 · Re[⟨∂ψ/∂θᵢ|∂ψ/∂θⱼ⟩ - ⟨∂ψ/∂θᵢ|ψ⟩⟨ψ|∂ψ/∂θⱼ⟩]
The QFIM provides the optimal metric for parameter updates in quantum optimization, and is used in quantum metrology to achieve the quantum Cramér-Rao bound for parameter estimation.
This implementation uses the parameter shift rule to compute state derivatives efficiently, requiring 2N circuit evaluations where N is the number of parameters.
Use Cases:
Parameters:
Returns: Quantum Fisher Information Matrix as a vector of vectors (NxN matrix where N = parameter count). The matrix is real-valued, symmetric, and positive semi-definite.
Example:
(defn my-ansatz [params]
(-> (circuit/create-circuit 2 "Ansatz")
(circuit/ry-gate 0 (nth params 0))
(circuit/ry-gate 1 (nth params 1))
(circuit/cnot-gate 0 1)))
(def qfim (quantum-fisher-information-matrix
my-ansatz
simulator
[0.5 1.0]
{:shift (/ Math/PI 2)}))
;=> [[4.0 0.0] [0.0 4.0]] ; For independent rotations
References:
Calculates the Quantum Fisher Information Matrix (QFIM) for a parameterized quantum state.
The QFIM characterizes the distinguishability of quantum states under parameter variations.
It is defined as:
F_ij = 4 · Re[⟨∂ψ/∂θᵢ|∂ψ/∂θⱼ⟩ - ⟨∂ψ/∂θᵢ|ψ⟩⟨ψ|∂ψ/∂θⱼ⟩]
The QFIM provides the optimal metric for parameter updates in quantum optimization,
and is used in quantum metrology to achieve the quantum Cramér-Rao bound for
parameter estimation.
This implementation uses the parameter shift rule to compute state derivatives
efficiently, requiring 2N circuit evaluations where N is the number of parameters.
Use Cases:
- Quantum Natural Gradient optimization (faster convergence than standard gradients)
- Quantum Metrology (optimal parameter estimation bounds)
- Variational Quantum Algorithms (VQE, QAOA optimization)
- Quantum Machine Learning (training quantum neural networks)
Parameters:
- ansatz-fn: Function that creates a quantum circuit from parameters.
Takes parameter vector, returns circuit.
- backend: Quantum backend for circuit execution (simulator with state vector access).
- parameters: Current parameter vector (vector of numbers).
- options: Optional map with:
- :shift - Parameter shift for derivatives (default: π/2)
- :parallel? - Use parallel computation (default: false)
- Backend execution options: :shots, :initial-state, :result-specs
Returns:
Quantum Fisher Information Matrix as a vector of vectors (NxN matrix where N = parameter count).
The matrix is real-valued, symmetric, and positive semi-definite.
Example:
```clojure
(defn my-ansatz [params]
(-> (circuit/create-circuit 2 "Ansatz")
(circuit/ry-gate 0 (nth params 0))
(circuit/ry-gate 1 (nth params 1))
(circuit/cnot-gate 0 1)))
(def qfim (quantum-fisher-information-matrix
my-ansatz
simulator
[0.5 1.0]
{:shift (/ Math/PI 2)}))
;=> [[4.0 0.0] [0.0 4.0]] ; For independent rotations
```
References:
- Nielsen & Chuang, "Quantum Computation and Quantum Information", Chapter 9
- Stokes et al., "Quantum Natural Gradient", Quantum 4, 269 (2020)
- Liu et al., "Efficient Learning of Quantum States", Nat. Phys. 17, 1349 (2021)(swap-test-circuit n-qubits)Constructs a SWAP test circuit for measuring overlap between two quantum states.
The SWAP test is a quantum algorithm that uses an ancilla qubit and a controlled-SWAP (Fredkin) gate to measure the inner product |⟨ψ|φ⟩|² between two quantum states.
Circuit structure:
The probability of measuring |0⟩ on the ancilla is: P(0) = (1 + |⟨ψ|φ⟩|²)/2 From this, we can extract: |⟨ψ|φ⟩|² = 2·P(0) - 1
Parameters:
Returns: A quantum circuit that performs the SWAP test. The circuit has 2n+1 qubits total:
Usage: To use this circuit, prepare the initial state as |0⟩⊗|ψ⟩⊗|φ⟩ where |ψ⟩ and |φ⟩ are the states to compare. Execute the circuit and measure the ancilla qubit.
Example: (def swap-test (swap-test-circuit 2)) ; Compare two 2-qubit states ; Prepare initial state |0⟩⊗|ψ⟩⊗|φ⟩ (5 qubits total) ; Execute circuit and measure ancilla (qubit 0) ; If P(0) ≈ 1, states are identical; if P(0) ≈ 0.5, states are orthogonal
References:
Constructs a SWAP test circuit for measuring overlap between two quantum states. The SWAP test is a quantum algorithm that uses an ancilla qubit and a controlled-SWAP (Fredkin) gate to measure the inner product |⟨ψ|φ⟩|² between two quantum states. Circuit structure: 1. Ancilla qubit (qubit 0) is initialized to |0⟩ and Hadamard applied 2. State 1 (|ψ⟩) occupies qubits 1 to n 3. State 2 (|φ⟩) occupies qubits n+1 to 2n 4. Controlled-SWAP (Fredkin) gates swap corresponding qubits of states 1 and 2, controlled by the ancilla 5. Final Hadamard applied to ancilla 6. Measure ancilla qubit The probability of measuring |0⟩ on the ancilla is: P(0) = (1 + |⟨ψ|φ⟩|²)/2 From this, we can extract: |⟨ψ|φ⟩|² = 2·P(0) - 1 Parameters: - n-qubits: Number of qubits in each state to compare (positive integer) Returns: A quantum circuit that performs the SWAP test. The circuit has 2n+1 qubits total: - Qubit 0: Ancilla qubit for measurement - Qubits 1 to n: First quantum state |ψ⟩ - Qubits n+1 to 2n: Second quantum state |φ⟩ Usage: To use this circuit, prepare the initial state as |0⟩⊗|ψ⟩⊗|φ⟩ where |ψ⟩ and |φ⟩ are the states to compare. Execute the circuit and measure the ancilla qubit. Example: (def swap-test (swap-test-circuit 2)) ; Compare two 2-qubit states ; Prepare initial state |0⟩⊗|ψ⟩⊗|φ⟩ (5 qubits total) ; Execute circuit and measure ancilla (qubit 0) ; If P(0) ≈ 1, states are identical; if P(0) ≈ 0.5, states are orthogonal References: - Nielsen & Chuang, "Quantum Computation and Quantum Information", Section 9.3 - Buhrman, Cleve, Watrous, de Wolf, "Quantum Fingerprinting" (2001)
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |