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.
from dashboard_core.engine import run_circuit_from_qasm
qasm = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];
h q[0];
cx q[0],q[1];
measure q -> c;
"""
result = run_circuit_from_qasm(qasm, n_shots=1000, seed=0)
print(result.probabilities.round(3)) # [0.5 0. 0. 0.5] -- Bell pair
print(result.counts) # e.g. {'00': 473, '11': 527}
For circuits too large for a dense statevector, run_large_circuit_mps finds the
top-k most probable basis states via MPS instead:
from dashboard_core.engine import run_large_circuit_mps
result = run_large_circuit_mps(qasm, k=4, seed=0)
print(result.top_k_states[:2]) # [('00', 0.5), ('11', 0.5)] -- the rest are ~0
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.
Examples:
>>> from dashboard_core.engine import run_circuit_from_qasm
>>> qasm = '''
... OPENQASM 2.0;
... include "qelib1.inc";
... qreg q[2];
... creg c[2];
... h q[0];
... cx q[0],q[1];
... measure q -> c;
... '''
>>> result = run_circuit_from_qasm(qasm, n_shots=1000, seed=0)
>>> result.probabilities.round(3).tolist() # Bell pair: only |00> and |11> populated
[0.5, 0.0, 0.0, 0.5]
>>> set(result.counts.keys()) <= {'00', '11'} # shot counts only land on those two states
True
Source code in tools/dashboard/core/engine.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
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.
Examples:
>>> from dashboard_core.engine import run_large_circuit_mps
>>> qasm = '''
... OPENQASM 2.0;
... include "qelib1.inc";
... qreg q[5];
... creg c[5];
... h q[0];
... cx q[0],q[1];
... cx q[1],q[2];
... cx q[2],q[3];
... cx q[3],q[4];
... measure q -> c;
... '''
>>> result = run_large_circuit_mps(qasm, k=4, seed=0) # a 5-qubit GHZ state
>>> top2 = sorted(result.top_k_states, key=lambda t: -t[1])[:2]
>>> [bits for bits, _ in top2]
['00000', '11111']
>>> all(abs(p - 0.5) < 1e-9 for _, p in top2)
True
Source code in tools/dashboard/core/engine.py
run_bond_convergence_check ¶
Runs the circuit at every bond dimension in bonds and checks
whether each observable's expectation value has actually converged
as bond dimension grows -- a single MPS run's own diagnostics
(avg_jsd, budget_violations) say nothing about whether a specific
observable has settled, since they are truncation-error proxies
averaged over the whole state, not the observable itself.
Thin wrapper around dense_evolution.backends.mps.bond_convergence: parses qasm_text the same way as every other entry point here, then delegates. See that function's own docstring for the "undecidable" verdict (fires when chi_used at the top bond already equals its own cap, i.e. truncation never had headroom to demonstrate convergence).