uniqc.simulator.originir_ext_simulator module

Higher-level simulator for dynamic OriginIR-ext programs.

OriginIR_ext_Simulator sits above OpcodeSimulator and interprets the non-opcode control flow (QIF/QWHILE) of a classical / control-flow program tree, driving the OpcodeSimulator — which owns the CREG store — for the linear opcodes (gates, MEASURE → CREG, RESET, and the classical instructions AND/OR/XOR/MOV/NOT).

Because mid-circuit measurement + classical feedback make each run stochastic, results are produced by per-shot re-execution: every shot runs the whole program from a fresh |0...0> state and reads the final CREG bitstring (c[0] = LSB). The exact aggregate paths (simulate_pmeasure / simulate_stateprob) are therefore ill-defined and raise.

exception uniqc.simulator.originir_ext_simulator.LoopWatchdogError[source]

Bases: RuntimeError

Raised when a QWHILE loop exceeds its configured max_iterations.

class uniqc.simulator.originir_ext_simulator.OriginIR_ext_Simulator(backend_type='statevector', available_qubits=None, available_topology=None, seed=None, max_while_iterations=None, **extra_kwargs)[source]

Bases: BaseSimulator

Interpreter for dynamic OriginIR-ext programs (CREG + control flow).

Accepts a Circuit (with or without a structured dynamic_program) or an OriginIR-ext string. Ordinary flat circuits are executed as a single linear opcode sequence followed by their terminal measurements.

Parameters:
  • backend_type"statevector" or "density_matrix" (see uniqc.simulator.opcode_simulator.backend_alias()).

  • available_qubits – Optional list of available qubit indices.

  • available_topology – Optional list of available qubit pairs.

  • seed – Optional RNG seed (applied once before a shot loop / single run) for deterministic mid-circuit measurement outcomes.

  • max_while_iterations – Optional global override of every QWHILE block’s internal iteration watchdog. None honours each block’s own max_iterations.

simulate_density_matrix(quantum_code)[source]

Run the program once and return the resulting density matrix.

For programs with mid-circuit measurement this is a single stochastic sample’s density matrix.

simulate_pmeasure(quantum_code)[source]

Blocked: exact measurement probabilities are ill-defined here.

simulate_shots(quantum_code, shots)[source]

Run the program shots times and tally final CREG bitstrings.

Returns:

Dict mapping outcome bitstring (int, c[0] = LSB) to its count.

simulate_single_shot(quantum_code)[source]

Run the program once and return the final CREG bitstring as an int (c[0] = LSB).

simulate_stateprob(quantum_code)[source]

Blocked: exact state probabilities are ill-defined here.

simulate_statevector(quantum_code)[source]

Run the program once and return the resulting statevector.

Note: for programs with mid-circuit measurement this is a single stochastic sample (the post-collapse state of one run), not a deterministic object.