Quantum¶
Quantum-classical hybrid spiking layers: hardware backend bridge, hybrid quantum-spiking circuits, quantum error correction, noise modelling, and parameter-shift gradient optimization.
Hardware Bridge¶
sc_neurocore.quantum.hardware_bridge
¶
Hardware Bridge for Quantum-Classical Hybrid execution.
This module provides the interface to offload the simulated quantum stochastic logic to actual quantum hardware via Qiskit, or to high-fidelity tensor-network simulators via PennyLane.
Usage::
from sc_neurocore.quantum.hardware_bridge import QuantumHardwareLayer
layer = QuantumHardwareLayer(n_qubits=4, backend_type="aer_simulator")
out_bits = layer.forward(input_bitstreams)
QuantumHardwareLayer
dataclass
¶
Executes a Quantum-Classical Hybrid Layer on Qiskit/PennyLane. Maps bitstream probability -> Qubit Rotation -> True Measurement.
Source code in src/sc_neurocore/quantum/hardware_bridge.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
forward(input_bitstreams)
¶
input_bitstreams: (n_qubits, length) Returns: output_bitstreams: (n_qubits, length)
Source code in src/sc_neurocore/quantum/hardware_bridge.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
Hybrid Layer¶
sc_neurocore.quantum.hybrid
¶
QuantumStochasticLayer
dataclass
¶
Simulates a Quantum-Classical Hybrid Layer. Input bitstream probability -> Qubit Rotation -> Measurement Probability.
Mapping: p_in -> theta = p_in * pi P_out = |<0|Ry(theta)|0>|^2 = cos^2(theta/2) This non-linearity is useful for classification.
Source code in src/sc_neurocore/quantum/hybrid.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
forward(input_bitstreams)
¶
input_bitstreams: (n_qubits, length)
Source code in src/sc_neurocore/quantum/hybrid.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
Noise Models¶
IBM Heron r2 noise model with depolarizing, amplitude damping, phase damping channels, and asymmetric readout error.
sc_neurocore.quantum.noise_models
¶
HeronR2NoiseParams
dataclass
¶
IBM Heron r2 calibration parameters (2024).
Source code in src/sc_neurocore/quantum/noise_models.py
14 15 16 17 18 19 20 21 22 23 24 25 | |
HeronR2NoiseModel
¶
Source code in src/sc_neurocore/quantum/noise_models.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
depolarizing_channel(p)
¶
Kraus operators for single-qubit depolarizing channel.
Source code in src/sc_neurocore/quantum/noise_models.py
32 33 34 35 36 37 38 39 40 41 42 43 | |
amplitude_damping(gamma)
¶
Kraus operators for amplitude damping (T1 decay).
Source code in src/sc_neurocore/quantum/noise_models.py
45 46 47 48 49 | |
phase_damping(gamma)
¶
Kraus operators for phase damping (T2 decay).
Source code in src/sc_neurocore/quantum/noise_models.py
51 52 53 54 55 | |
apply_single_qubit_noise(rho)
¶
Apply single-qubit noise channel to density matrix.
Source code in src/sc_neurocore/quantum/noise_models.py
57 58 59 60 | |
apply_readout_noise(measurement)
¶
Apply asymmetric readout error.
Source code in src/sc_neurocore/quantum/noise_models.py
62 63 64 65 66 67 | |
Parameter-Shift Gradient¶
Exact gradient computation for parameterized quantum circuits.
sc_neurocore.quantum.param_shift
¶
parameter_shift_gradient(circuit_fn, params, shift=np.pi / 2)
¶
Gradient via parameter-shift rule.
f'(θ_i) = [f(θ_i + s) - f(θ_i - s)] / (2 sin(s))
Source code in src/sc_neurocore/quantum/param_shift.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Hybrid Pipeline¶
VQE-style quantum-classical optimization pipeline.
sc_neurocore.quantum.hybrid_pipeline
¶
HybridQuantumClassicalPipeline
¶
Source code in src/sc_neurocore/quantum/hybrid_pipeline.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
circuit(params)
¶
Parameterized Ry-CNOT circuit → ⟨Z⊗Z⟩ expectation.
Source code in src/sc_neurocore/quantum/hybrid_pipeline.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
train(n_steps=100, lr=0.01)
¶
VQE-style optimization: minimize ⟨Z⊗Z⟩.
Source code in src/sc_neurocore/quantum/hybrid_pipeline.py
84 85 86 87 88 89 90 91 92 93 | |
QEC¶
sc_neurocore.quantum.qec
¶
Quantum Error Correction (QEC) Shield for sc-neurocore.
Provides classical-stochastic implementations of QEC codes (Repetition, Surface) to protect quantum-classical bitstreams from noise during IBMQ hardware execution.
QecShield
¶
Repetition code QEC shield for stochastic-quantum bitstreams.
Source code in src/sc_neurocore/quantum/qec.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
encode(bitstream)
¶
repetition code (d=3): 0 -> 000, 1 -> 111
Source code in src/sc_neurocore/quantum/qec.py
27 28 29 30 31 | |
SurfaceCodeShield
¶
Distance-d rotated surface code for stochastic-quantum bitstreams.
Encodes 1 logical qubit into d² physical data qubits. X and Z stabilizers detect bit-flip and phase-flip errors. Decoding uses a lookup table for d=3.
Ref: Fowler et al., "Surface codes: Towards practical large-scale quantum computation", Phys. Rev. A 86, 032324 (2012).
Source code in src/sc_neurocore/quantum/qec.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
encode(bitstream)
¶
Encode logical bitstream into surface code physical qubits.
Input: (n_logical, length) — each row is one logical qubit's bitstream. Output: (n_logical, n_data, length) — repeated into d² data qubits.
Source code in src/sc_neurocore/quantum/qec.py
115 116 117 118 119 120 121 122 | |
measure_syndrome(physical_bits)
¶
Measure X and Z stabilizer syndromes.
Input: (n_logical, n_data, length) Returns: (x_syndrome, z_syndrome) each (n_logical, n_stabilizers, length)
Source code in src/sc_neurocore/quantum/qec.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
decode(physical_bits)
¶
Decode surface code: measure syndromes, correct single-qubit errors, majority vote.
Input: (n_logical, n_data, length) Output: (n_logical, length)
Source code in src/sc_neurocore/quantum/qec.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
get_error_rate(x_syn, z_syn)
¶
Estimated error rate from syndrome density.
Source code in src/sc_neurocore/quantum/qec.py
182 183 184 | |
SC→Quantum Compiler (Conjecture C1+C4)¶
Compiles SC operations to quantum circuits. SC probability p encodes as Ry(2·arcsin(√p)) rotation; AND gate maps to joint measurement; Born rule recovers P(|1⟩) = p exactly. Includes noisy simulation via HeronR2NoiseModel.
sc_neurocore.quantum.sc_quantum_compiler.sc_prob_to_statevector(p)
¶
Encode SC probability as a single-qubit state vector.
|ψ⟩ = √(1-p)|0⟩ + √p|1⟩ → P(measure |1⟩) = p exactly.
Source code in src/sc_neurocore/quantum/sc_quantum_compiler.py
38 39 40 41 42 43 44 | |
sc_neurocore.quantum.sc_quantum_compiler.compile_sc_multiply(p_a, p_b)
¶
Compile SC AND gate (multiplication) to a quantum circuit.
SC: P(a AND b) = P(a) * P(b) for independent streams. Quantum: encode probabilities as Ry rotations, use CNOT for correlation.
Source code in src/sc_neurocore/quantum/sc_quantum_compiler.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
sc_neurocore.quantum.sc_quantum_compiler.compile_sc_layer(weights, input_probs)
¶
Compile an SC dense layer to quantum gate descriptions.
Parameters¶
weights : np.ndarray Shape (n_neurons, n_inputs), values in [0, 1]. input_probs : np.ndarray Shape (n_inputs,), SC input probabilities.
Returns¶
list of dicts, one per neuron, each containing: 'neuron_idx': int 'ry_angles': list of (input_angle, weight_angle) pairs 'expected_output': float — SC computation result 'quantum_output': float — quantum simulation result
Source code in src/sc_neurocore/quantum/sc_quantum_compiler.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
sc_neurocore.quantum.sc_quantum_compiler.SCQuantumCircuit
dataclass
¶
Quantum circuit compiled from SC operations.
Source code in src/sc_neurocore/quantum/sc_quantum_compiler.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
simulate()
¶
Simulate the circuit and return the full statevector.
Source code in src/sc_neurocore/quantum/sc_quantum_compiler.py
88 89 90 91 92 93 94 95 96 97 | |
output_probability()
¶
Simulate and return P(output_qubit = |1⟩).
Source code in src/sc_neurocore/quantum/sc_quantum_compiler.py
99 100 101 102 103 104 105 106 | |
simulate_noisy(noise_model)
¶
Simulate with noise: evolve density matrix through Kraus channels.
Parameters¶
noise_model : HeronR2NoiseModel or compatible Must provide apply_single_qubit_noise(rho) and apply_readout_noise(measurement).
Returns¶
np.ndarray Final density matrix of shape (2^n, 2^n).
Source code in src/sc_neurocore/quantum/sc_quantum_compiler.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
output_probability_noisy(noise_model, n_shots=1000)
¶
Simulate with noise and return P(output=1) via measurement sampling.
Parameters¶
noise_model : HeronR2NoiseModel or compatible n_shots : int Number of measurement shots.
Source code in src/sc_neurocore/quantum/sc_quantum_compiler.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |