qoqo_qiskit

Qoqo-qiskit backend package for compatibility and simulation purposes.

Translates qoqo operations and circuits to qiskit equivalents.

Registers(bit_register_dict, ...)

Registers.

RegistersWithLengths(registers, ...)

Registers, with classical registers lengths.

to_qiskit_circuit(circuit[, qubit_register_name])

Applies the qoqo Circuit -> Qiskit QuantumCircuit conversion.

QoqoQiskitBackend([qiskit_backend, memory, ...])

Run a Qoqo QuantumProgram on a Qiskit backend.

QueuedCircuitRun(job, memory, sim_type, ...)

Queued Result of the circuit.

QueuedProgramRun(measurement, queued_circuits)

Queued Result of the measurement.

Functions

to_qiskit_circuit(circuit[, qubit_register_name])

Applies the qoqo Circuit -> Qiskit QuantumCircuit conversion.

Classes

QoqoQiskitBackend([qiskit_backend, memory, ...])

Run a Qoqo QuantumProgram on a Qiskit backend.

QueuedCircuitRun(job, memory, sim_type, ...)

Queued Result of the circuit.

QueuedProgramRun(measurement, queued_circuits)

Queued Result of the measurement.

Registers(bit_register_dict, ...)

Registers.

RegistersWithLengths(registers, ...)

Registers, with classical registers lengths.

class qoqo_qiskit.QoqoQiskitBackend(qiskit_backend: Backend = None, memory: bool = False, compilation: bool = True)[source]

Run a Qoqo QuantumProgram on a Qiskit backend.

run_circuit(circuit: Circuit) Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]][source]

Run a Circuit on a Qiskit backend.

The default number of shots for the simulation is 200. Any kind of Measurement, Statevector or DensityMatrix instruction only works as intended if they are the last instructions in the Circuit. Currently only one simulation is performed, meaning different measurements on different registers are not supported.

Parameters:

circuit (Circuit) -- the Circuit to run.

Returns:

bit, float and complex registers dictionaries.

Return type:

Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]

Raises:

ValueError -- Incorrect Measurement or Pragma operations.

run_circuit_list(circuits: List[Circuit]) Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]][source]

Run a list of Circuit instances on a Qiskit backend.

The default number of shots for the simulation is 200. Any kind of Measurement, Statevector or DensityMatrix instruction only works as intended if they are the last instructions in the Circuit. Currently only one simulation is performed, meaning different measurements on different registers are not supported.

Parameters:

circuits (List[Circuit]) -- the list of Circuit instances to run.

Returns:

bit, float and complex registers dictionaries.

Return type:

Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]

Raises:

ValueError -- Incorrect Measurement or Pragma operations or incompatible run options between different circuits.

run_circuit_list_queued(circuits: List[Circuit]) List[QueuedCircuitRun][source]

Run a list of Circuit instances on a Qiskit backend and return a list of queued Runs.

The default number of shots for the simulation is 200. Any kind of Measurement, Statevector or DensityMatrix instruction only works as intended if they are the last instructions in the Circuit. Currently only one simulation is performed, meaning different measurements on different registers are not supported.

Parameters:

circuits (List[Circuit]) -- the list of Circuit instances to run.

Returns:

List[QueuedCircuitRun]

run_circuit_queued(circuit: Circuit) QueuedCircuitRun[source]

Run a Circuit on a Qiskit backend and return a queued Run.

The default number of shots for the simulation is 200. Any kind of Measurement, Statevector or DensityMatrix instruction only works as intended if they are the last instructions in the Circuit. Currently only one simulation is performed, meaning different measurements on different registers are not supported.

Parameters:

circuit (Circuit) -- the Circuit to run.

Returns:

QueuedCircuitRun

run_measurement(measurement: Any) Dict[str, float] | None[source]

Run a circuit with the Qiskit backend.

Parameters:

measurement -- The measurement that is run.

Returns:

Optional[Dict[str, float]]

run_measurement_queued(measurement: Any) QueuedProgramRun[source]

Run a qoqo measurement on a Qiskit backend and return a queued Job Result.

The default number of shots for the simulation is 200. Any kind of Measurement, Statevector or DensityMatrix instruction only works as intended if they are the last instructions in the Circuit. Currently only one simulation is performed, meaning different measurements on different registers are not supported.

Parameters:

measurement (qoqo.measurements) -- the measurement to run.

Returns:

QueuedProgramRun

run_measurement_registers(measurement: Any) Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]][source]

Run all circuits of a measurement with the Qiskit backend.

Parameters:

measurement -- The measurement that is run.

Returns:

Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]

run_program(program: QuantumProgram, params_values: List[float] | List[List[float]]) List[Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]] | Dict[str, float]] | None[source]

Run a qoqo quantum program on an IBM backend multiple times.

It can handle QuantumProgram instances containing any kind of measurement. The list of lists of parameters will be used to call program.run(self, params) or program.run_registers(self, params) as many times as the number of sublists. The return type will change accordingly.

If no parameters values are provided, a normal call program.run(self, []) call will be executed.

Parameters:
  • program (QuantumProgram) -- the qoqo quantum program to run.

  • params_values (Union[List[float], List[List[float]]]) -- the parameters values to pass to the quantum program.

Returns:

Optional[
List[
Union[
Tuple[

Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]],

], Dict[str, float],

]

]

]: list of dictionaries (or tuples of dictionaries) containing the

run results.

run_program_queued(program: QuantumProgram, params_values: List[float] | List[List[float]]) List[QueuedProgramRun][source]

Run a qoqo quantum program on a AWS backend multiple times return a list of queued Jobs.

This effectively performs the same operations as run_program but returns queued results.

Parameters:
  • program (QuantumProgram) -- the qoqo quantum program to run.

  • params_values (Union[List[float], List[List[float]]]) -- the parameters values to pass to the quantum program.

Raises:

ValueError -- incorrect length of params_values compared to program's input parameter names.

Returns:

List[QueuedProgramRun]]

class qoqo_qiskit.QueuedCircuitRun(job: Job, memory: bool, sim_type: str, registers_info: Tuple[Dict[str, int], Dict[str, int], Dict[str, int], Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]], res_index: int | None = 0)[source]

Queued Result of the circuit.

static from_json(string: str) QueuedCircuitRun[source]

Convert a JSON string to an instance of QueuedCircuitRun.

Parameters:

string (str) -- JSON string to convert.

Returns:

The converted instance.

Return type:

QueuedCircuitRun

poll_result() Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]] | None[source]

Poll the result.

Returns:

Tuple[Dict[str, List[List[bool]]],

Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]: Result if the run was successful.

Raises:

RuntimeError -- The job failed or was cancelled.

to_json() str[source]

Convert self to a JSON string.

Returns:

self as a JSON string.

Return type:

str

class qoqo_qiskit.QueuedProgramRun(measurement: Any, queued_circuits: List[QueuedCircuitRun])[source]

Queued Result of the measurement.

static from_json(string: str) QueuedProgramRun[source]

Convert a JSON string to an instance of QueuedProgramRun.

Parameters:

string (str) -- JSON string to convert.

Raises:

TypeError -- The measurement type is unknown.

Returns:

The converted instance.

Return type:

QueuedProgramRun

poll_result() Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]] | None[source]

Poll the result.

Returns:

Union[Tuple[Dict[str, List[List[bool]]],

Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]]: Result if all runs were successful.

Raises:

RuntimeError -- The jobs failed or were cancelled.

to_json() str[source]

Convert self to a JSON string.

Returns:

self as a JSON string.

Return type:

str

Raises:

TypeError -- The measurement type is unknown.

class qoqo_qiskit.Registers(bit_register_dict: ~typing.Dict[str, ~typing.List[~typing.List[bool]]] = <factory>, float_register_dict: ~typing.Dict[str, ~typing.List[~typing.List[float]]] = <factory>, complex_register_dict: ~typing.Dict[str, ~typing.List[~typing.List[complex]]] = <factory>)[source]

Registers.

The registers are used to store classical information during the execution of a roqoqo circuit and to provide a unified output interface for the different backends.

Defined by three dictionaries, representing bit, float and complex registers.

bit_register_dict: Dict[str, List[List[bool]]]
complex_register_dict: Dict[str, List[List[complex]]]
float_register_dict: Dict[str, List[List[float]]]
class qoqo_qiskit.RegistersWithLengths(registers: ~qoqo_qiskit.models.Registers = <factory>, bit_regs_lengths: ~typing.Dict[str, int] = <factory>, float_regs_lengths: ~typing.Dict[str, int] = <factory>, complex_regs_lengths: ~typing.Dict[str, int] = <factory>)[source]

Registers, with classical registers lengths.

The registers are used to store classical information during the execution of a roqoqo circuit and to provide a unified output interface for the different backends.

In addition, a dictionary containing the lengths of any register (indexed by its name) is also provided.

Defined by three dictionaries, representing bit, float and complex registers.

bit_regs_lengths: Dict[str, int]
complex_regs_lengths: Dict[str, int]
float_regs_lengths: Dict[str, int]
registers: Registers
to_flat_tuple() Tuple[Dict[str, int], Dict[str, int], Dict[str, int], Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]][source]

Flattens the internal data into a single tuple.

qoqo_qiskit.to_qiskit_circuit(circuit: Circuit, qubit_register_name: str | None = None) Tuple[QuantumCircuit, Dict[str, int]][source]

Applies the qoqo Circuit -> Qiskit QuantumCircuit conversion.

Parameters:
  • circuit (Circuit) -- the qoqo Circuit to port.

  • qubit_register_name (Optional[str]) -- the name of the qubit register.

Returns:

equivalent QuantumCircuit and dict containing info for Qiskit's backend.

Return type:

Tuple[QuantumCircuit, Dict[str, int]]

Raises:

ValueError -- the circuit contains a symbolic PragmaLoop operation.