Benchmark: Dynamic Coupling (Quantum Hebbian Learning)

July 7, 2026 · View on GitHub

Module: scpn_quantum_control.qsnn.dynamic_coupling Class: DynamicCouplingEngine

Overview

The Dynamic Coupling Engine implements quantum-classical co-evolution where a classical coupling matrix KnmK_{nm} drives quantum XY Hamiltonian evolution, and quantum correlation measurements feed back to update KnmK_{nm} via a Hebbian rule:

Knm(t+1)=(1γ)Knm(t)+ηXnXm+YnYmK_{nm}(t+1) = (1 - \gamma) K_{nm}(t) + \eta \langle X_n X_m + Y_n Y_m \rangle

Each co-evolution step requires: Hamiltonian construction, sparse time evolution, correlation matrix measurement, and coupling update.

Rust Acceleration

The correlation measurement step uses correlation_matrix_xy from scpn_quantum_engine when available, providing 2.9x speedup over the pure NumPy/Qiskit path.

OperationPython (ms)Rust (ms)Speedup
correlation_matrix_xy (4q)0.290.102.9x

Co-evolution Step Timing

Each .step(dt) call performs one full loop: evolve + measure + update KK.

System SizeStep TimeNotes
N=2<1 msTrivial 4x4 Hilbert space
N=4~2 msSparse evolution dominates
N=6~8 ms64-dimensional Hilbert space
N=8~35 ms256-dimensional, correlation matrix 8x8

Multi-step Co-evolution

run_coevolution(steps, dt) runs multiple steps and returns the full trajectory.

StepsN=4 TimeN=6 TimeN=8 Time
10~20 ms~80 ms~350 ms
50~100 ms~400 ms~1.8 s
100~200 ms~800 ms~3.5 s

Physical Invariants (Verified by Tests)

  • KnmK_{nm} remains symmetric at every step
  • Knm0K_{nm} \geq 0 (non-negative coupling)
  • Diagonal Knn=0K_{nn} = 0 (no self-coupling)
  • Statevector normalised (ψ=1\|\psi\| = 1)
  • Correlation matrix symmetric (C=CTC = C^T)
  • Decay drives K0K \to 0 when learning rate is zero

Test Coverage

9 tests in tests/test_dynamic_coupling.py:

  • test_dynamic_coupling_engine_step — single step produces valid output
  • test_run_coevolution — multi-step trajectory length and structure
  • test_k_symmetry_preserved — symmetry invariant across steps
  • test_correlation_matrix_symmetricCnm=CmnC_{nm} = C_{mn}
  • test_k_diagonal_stays_zero — no self-coupling
  • test_k_non_negative — coupling positivity
  • test_decay_drives_k_toward_zero — thermodynamic limit
  • test_statevector_normalised — quantum state normalisation
  • test_rust_python_correlation_parity — Rust and Python paths agree

Running Benchmarks

pytest tests/test_dynamic_coupling.py -v -s
pytest tests/test_rust_path_benchmarks.py -k correlation_matrix -v -s