Dashboard Core — Engine¶
The real simulation engine for the dashboard: runs an actual
DenseSVSimulator circuit, not a mocked/placeholder
result, and is what Composer's UI and the MCP server's simulation tools
both call underneath.
engine ¶
Real simulation engine for the dashboard.
OpenQASM text -> dense_evolution's own QASMParser -> executed on dense_evolution's actual DenseSVSimulator/MPSSimulator (not Qiskit's own simulator, and not Qiskit's QASM parser either) -> statevector, probabilities and shot counts, all reordered into Qiskit's little-endian qubit convention so they line up with the Circuit tab's qubit labels and with qiskit.visualization's functions (which assume that convention).
No Qiskit QuantumCircuit is ever constructed here, not even for the Circuit-diagram panel: qiskit.circuit.QuantumCircuit.init itself segfaults (SIGSEGV, inside qiskit's own compiled extension) on macOS, independent of how the circuit is built or what's done with it afterwards -- see tests/integration/test_interop.py::TestQiskitInterop for the full reproduction story (QuantumCircuit(3) alone, no QASM, no method calls, still crashes there). SimulationResult/LargeScaleMPSResult below carry the plain gate tuples instead, and dashboard_core.circuit_diagram draws the diagram directly from those with plain matplotlib.
No synthetic/placeholder data anywhere here: every quantity returned is computed from a real run of the real engine.
run_circuit_from_qasm ¶
run_circuit_from_qasm(
qasm_text: str,
n_shots: int = 1000,
seed: Optional[int] = None,
noise_model: str = "ideal",
noise_p: float = 0.0,
backend: str = "dense",
) -> SimulationResult
Parse qasm_text and run it on a real dense_evolution engine,
returning every quantity the dashboard's tabs need.
noise_model/noise_p: one of dense_evolution.NoiseModel.MODELS
('ideal', 'depolarizing', 'bitflip', 'phaseflip', 'amplitude_damping',
'combined') applied as a real stochastic Kraus channel to the
statevector via NoiseModel.apply_to_sv -- not a fabricated decay
curve, the actual channel math. 'ideal'/p<=0 skips it entirely (and
leaves SimulationResult.fidelity_vs_ideal as None -- comparing a run
against itself is not a real quantity). Otherwise fidelity_vs_ideal
is the real dense_evolution.statevector_fidelity(|
backend: 'dense' (DenseSVSimulator, the default) or 'mps' (MPSSimulator -- adaptive SVD-truncated matrix product state, scales to far more qubits for low-entanglement circuits; contracted back to a dense statevector afterwards so the same Probabilities/Q-sphere/ Statevector panels work unchanged regardless of which engine ran the circuit). Verified to match 'dense' exactly (atol=1e-6) on every preset in QASM_LIBRARY, and to run a 12-qubit GHZ state in ~2.5s (max_bond=2) where 'dense' would need 2**12 complex amplitudes.
Source code in tools/dashboard_core/engine.py
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 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
run_large_circuit_mps ¶
run_large_circuit_mps(
qasm_text: str, k: int = 32, seed: Optional[int] = None
) -> LargeScaleMPSResult
For circuits beyond MPS_DENSE_CONTRACTION_LIMIT qubits, where no dense (2**n,) statevector/probabilities array can exist at all: runs the real MPS circuit and finds the top-k most probable basis states via MPSSimulator.get_top_k_probable_states -- a real greedy beam search, EXACT probabilities for the states it finds (not sampled or approximated). Verified directly against exact dense diagonalization at 10 qubits: every state with non-negligible probability was found, matching to 6 decimal places (recall isn't guaranteed complete for highly-entangled circuits at fixed k -- see MPSSimulator's own docstring -- but the probabilities reported are always exact, never estimated).
Chosen over MPSSimulator.get_probabilities_sampled for this UI: measured directly, sampling 2000 shots takes 130s/257s/582s at 30/50/100 qubits (grows with n -- roughly O(n_samples * n_qubits)), while get_top_k_probable_states stays under 2s even at 100 qubits.