![]() |
Q2NSViz 0.1.0
Q2NS trace visualizer
|
Replays a Q2NS simulation event stream and exposes the quantum state. More...
Public Member Functions | |
| reset (self) | |
| Clear all loaded state. | |
| load_events (self, str|Path|list[dict[str, Any]] source) | |
| Ingest a trace and build the simulation timeline. | |
| None | seek (self, int t_ns) |
Position the replay state at t_ns without packaging a Snapshot. | |
| Snapshot | snapshot_at (self, int t_ns) |
Advance or restore the replay state to t_ns and return a Snapshot. | |
| dict[str, list[str]] | get_entanglement_groups (self) |
Return all entanglement components as {root: [members]}. | |
| dict[str, list[str]] | get_entangled_states (self) |
| Return entanglement components with two or more qubits. | |
| int | log_count_at (self, int t_ns) |
Return how many traceText events have a timestamp <= t_ns. | |
| list[dict[str, Any]] | get_log_events (self, int t_ns) |
Return all traceText events with timestamp <= t_ns, in time order. | |
Public Attributes | |
| log_events | |
| t_max | |
| events | |
| events_by_type | |
| time_array | |
| qubits | |
| cbits | |
| ent_graph | |
| measured_qubits | |
| removed_qubits | |
| discarded_qubits | |
| removed_cbits | |
Replays a Q2NS simulation event stream and exposes the quantum state.
Usage pattern::
sm = SimulationStateManager() sm.load_events(parsed_events) snap = sm.snapshot_at(t_ns) groups = snap.entangled_states
snapshot_at(t_ns) returns an immutable Snapshot carrying all per-instant state; prefer its fields over the query helpers. The helpers reflect the state positioned by the most recent snapshot_at() call; calling them on a fresh instance returns empty results silently.ent_graph is restored or advanced to the requested time on every snapshot_at() call. Do not cache pointers to its contents.createNode, createChannel, createQubit, sendQubit, removeQubit, createCbit, sendCbit, removeCbit, entangle, measure, graphMeasure, sendPacket, traceText.
| dict[str, list[str]] q2nsviz.logic.SimulationStateManager.get_entangled_states | ( | self | ) |
Return entanglement components with two or more qubits.
Traverses only the entanglement graph, so the cost scales with the number of live entanglement edges rather than with every qubit created so far (get_entanglement_groups() also enrolls singleton components and therefore scans the full qubit registry).
{root: members} for every component with two or more qubits; equal, as member sets, to filtering get_entanglement_groups() by len(members) >= 2. Definition at line 1222 of file logic.py.
References q2nsviz.logic._StateSnapshot.ent_graph, q2nsviz.logic.Snapshot.ent_graph, q2nsviz.logic.SimulationStateManager.ent_graph, q2nsviz.logic._StateSnapshot.measured_qubits, q2nsviz.logic.Snapshot.measured_qubits, q2nsviz.logic.SimulationStateManager.measured_qubits, q2nsviz.logic._StateSnapshot.removed_qubits, q2nsviz.logic.Snapshot.removed_qubits, q2nsviz.logic.SimulationStateManager.removed_qubits, and q2nsviz.ui.canvas.NetworkCanvas.removed_qubits.
| dict[str, list[str]] q2nsviz.logic.SimulationStateManager.get_entanglement_groups | ( | self | ) |
Return all entanglement components as {root: [members]}.
Must be called after snapshot_at(t_ns) so that ent_graph and qubits reflect the desired simulation time.
Computes connected components of ent_graph via UnionFind, excluding measured and removed qubits. The result therefore correctly reflects graph-state measurements (X/Y/Z) and any bridge qubits whose removal splits the graph.
Definition at line 1195 of file logic.py.
References q2nsviz.logic._StateSnapshot.ent_graph, q2nsviz.logic.Snapshot.ent_graph, q2nsviz.logic.SimulationStateManager.ent_graph, q2nsviz.logic._StateSnapshot.measured_qubits, q2nsviz.logic.Snapshot.measured_qubits, q2nsviz.logic.SimulationStateManager.measured_qubits, q2nsviz.logic._StateSnapshot.qubits, q2nsviz.logic.Snapshot.qubits, q2nsviz.logic.SimulationStateManager.qubits, q2nsviz.logic._StateSnapshot.removed_qubits, q2nsviz.logic.Snapshot.removed_qubits, q2nsviz.logic.SimulationStateManager.removed_qubits, and q2nsviz.ui.canvas.NetworkCanvas.removed_qubits.
| list[dict[str, Any]] q2nsviz.logic.SimulationStateManager.get_log_events | ( | self, | |
| int | t_ns | ||
| ) |
Return all traceText events with timestamp <= t_ns, in time order.
| t_ns | Cut-off time in nanoseconds. |
type == "traceText". Definition at line 1256 of file logic.py.
References q2nsviz.logic.SimulationStateManager.log_count_at(), and q2nsviz.logic.SimulationStateManager.log_events.
| q2nsviz.logic.SimulationStateManager.load_events | ( | self, | |
| str | Path | list[dict[str, Any]] | source | ||
| ) |
Ingest a trace and build the simulation timeline.
Accepts either an already-parsed event list or a path to a trace file; a path is parsed with EventFileParser first, with any parse errors logged as warnings. Processes createNode and createChannel events immediately; all other event types are deferred to snapshot_at(). Runs _validate_events() and logs any detected issues as warnings.
| source | List of raw event dictionaries from EventFileParser, or the path of a JSON/NDJSON trace file to load. |
Calls reset() before loading, so any previously loaded state is discarded. Each call to load_events() always starts from a clean slate.
Definition at line 342 of file logic.py.
References q2nsviz.logic.SimulationStateManager.reset(), q2nsviz.ui.canvas.NetworkCanvas.reset(), and q2nsviz.ui.window.PlaybackController.reset().
| int q2nsviz.logic.SimulationStateManager.log_count_at | ( | self, | |
| int | t_ns | ||
| ) |
Return how many traceText events have a timestamp <= t_ns.
The log grows monotonically with time, so the GUI uses this count to append only the new lines instead of rebuilding the whole log view.
| t_ns | Cut-off time in nanoseconds. |
log_events one past the last visible entry. Definition at line 1245 of file logic.py.
References q2nsviz.logic.SimulationStateManager._log_times.
Referenced by q2nsviz.logic.SimulationStateManager.get_log_events().
| q2nsviz.logic.SimulationStateManager.reset | ( | self | ) |
Clear all loaded state.
Definition at line 324 of file logic.py.
References q2nsviz.logic.Snapshot.channels, q2nsviz.logic.SimulationStateManager.events, q2nsviz.logic.SimulationStateManager.events_by_type, and q2nsviz.logic.Snapshot.nodes.
Referenced by q2nsviz.logic.SimulationStateManager.load_events().
| q2nsviz.logic.SimulationStateManager.cbits |
Definition at line 807 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.snapshot_at().
| q2nsviz.logic.SimulationStateManager.discarded_qubits |
Definition at line 811 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.snapshot_at().
| q2nsviz.logic.SimulationStateManager.ent_graph |
Definition at line 808 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.get_entangled_states(), q2nsviz.logic.SimulationStateManager.get_entanglement_groups(), and q2nsviz.logic.SimulationStateManager.snapshot_at().
| q2nsviz.logic.SimulationStateManager.events |
Definition at line 367 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.reset(), and q2nsviz.logic.SimulationStateManager.snapshot_at().
| q2nsviz.logic.SimulationStateManager.events_by_type |
Definition at line 420 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.reset().
| q2nsviz.logic.SimulationStateManager.log_events |
Definition at line 330 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.get_log_events().
| q2nsviz.logic.SimulationStateManager.measured_qubits |
Definition at line 809 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.get_entangled_states(), q2nsviz.logic.SimulationStateManager.get_entanglement_groups(), and q2nsviz.logic.SimulationStateManager.snapshot_at().
| q2nsviz.logic.SimulationStateManager.qubits |
Definition at line 806 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.get_entanglement_groups(), and q2nsviz.logic.SimulationStateManager.snapshot_at().
| q2nsviz.logic.SimulationStateManager.removed_cbits |
Definition at line 812 of file logic.py.
Referenced by q2nsviz.ui.canvas.NetworkCanvas.mouseMoveEvent(), q2nsviz.ui.canvas.NetworkCanvas.reset(), and q2nsviz.logic.SimulationStateManager.snapshot_at().
| q2nsviz.logic.SimulationStateManager.removed_qubits |
Definition at line 810 of file logic.py.
Referenced by q2nsviz.logic.SimulationStateManager.get_entangled_states(), q2nsviz.logic.SimulationStateManager.get_entanglement_groups(), q2nsviz.ui.canvas.NetworkCanvas.mouseMoveEvent(), q2nsviz.ui.canvas.NetworkCanvas.paintEvent(), q2nsviz.ui.canvas.NetworkCanvas.reset(), and q2nsviz.logic.SimulationStateManager.snapshot_at().