uniqc.simulator.opcode_simulator module#

Opcode simulator, a fundamental simulator for UnifiedQuantum. It simulates from a basic opcode

class uniqc.simulator.opcode_simulator.OpcodeSimulator(backend_type='statevector')[source]#

Bases: object

A quantum circuit simulator based on C++ that runs locally.

Parameters:

backend_type – Backend type for simulation. Supported: ‘statevector’, ‘density_matrix’, ‘density_matrix_qutip’. Defaults to ‘statevector’.

Variables:

simulator – The underlying C++ simulator instance. typestr: Human-readable backend type string.

simulate_gate(operation, qubit, cbit, parameter, is_dagger, control_qubits_set)[source]#

Apply a single gate opcode to the simulator.

Parameters:
  • operation – Gate name string.

  • qubit – Qubit index or list of indices.

  • cbit – Classical bit index.

  • parameter – Gate parameters.

  • is_dagger – Whether to apply the dagger version of the gate.

  • control_qubits_set – Set of control qubits.

simulate_opcodes_density_operator(n_qubit, program_body)[source]#

Compute the density matrix after executing a list of opcodes.

Parameters:
  • n_qubit – Number of qubits.

  • program_body – List of opcodes to simulate.

Returns:

Density matrix as a 2D numpy array.

Raises:

ValueError – If simulator type is unknown.

simulate_opcodes_pmeasure(n_qubit, program_body, measure_qubits)[source]#

Compute measurement probabilities for a list of opcodes.

Parameters:
  • n_qubit – Number of qubits.

  • program_body – List of opcodes to simulate.

  • measure_qubits – Qubits to measure.

Returns:

List of probabilities for each measurement outcome.

simulate_opcodes_shot(n_qubit, program_body, measure_qubits)[source]#

Execute a list of opcodes and return a single measurement sample.

Parameters:
Returns:

Integer representing the measured bitstring (decimal).

Raises:

NotImplementedError – If backend is density_operator type.

simulate_opcodes_stateprob(n_qubit, program_body)[source]#

Compute state probabilities (|amplitude|^2) for all basis states.

Parameters:
  • n_qubit – Number of qubits.

  • program_body – List of opcodes to simulate.

Returns:

Array of probabilities for each basis state.

Raises:

ValueError – If simulator type is unknown.

simulate_opcodes_statevector(n_qubit, program_body)[source]#

Compute the final statevector after executing a list of opcodes.

Parameters:
  • n_qubit – Number of qubits.

  • program_body – List of opcodes to simulate.

Returns:

Statevector as a complex numpy array.

Raises:

ValueError – If backend is density_matrix type.

uniqc.simulator.opcode_simulator.backend_alias(backend_type)[source]#

Resolve backend type aliases to canonical names.

Supported backends: statevector, density_matrix

Note: Uppercase and lowercase are both supported.

Returns:

Canonical backend type string (“statevector” or “density_operator”).