openqasm_exporter

Tools to export ParityOS circuits to OpenQASM 3.

class parityos.exporters.openqasm_exporter.Qasm3ExportResult(circuit: str, qubit_map: dict[Qubit, str], cbit_map: dict[Cbit, str])

Bases: object

Result of exporting a ParityOS Circuit to OpenQASM 3.

circuit: str

Circuit represented as OpenQASM 3 string

qubit_map: dict[Qubit, str]

Mapping from parityos qubits to their name in the OpenQASM string.

cbit_map: dict[Cbit, str]

Mapping from parityos cbits to their name in the OpenQASM string.

parityos.exporters.openqasm_exporter.export_parityos_to_qasm3(parityos_circuit: CircuitLike[QubitT]) Qasm3ExportResult

Export a ParityOS circuit to OpenQASM 3.

Note

If final measurements are desired, they should be added to the circuit by calling measure_all before calling this function.

Parameters:

parityos_circuit – ParityOS Circuit to export.

Returns:

The exported OpenQASM string together with the qubit and classical-bit mappings.

parityos.exporters.openqasm_exporter.qubit_to_openqasm(qubit: Qubit) str

Convert the ParityOS qubit id into a valid OpenQASM qubit identifier.

Commas are mapped to underscores and invalid characters that are not in [a-zA-Z_0-9] are removed.

Examples

>>> assert qubit_to_openqasm(get_q("F@ncy:")) == "q_Fncy"
>>> assert qubit_to_openqasm(get_q(0, 0)) == "q_0_0"
Parameters:

qubit – ParityOS qubit to convert.

Returns:

OpenQASM-compatible qubit identifier.

parityos.exporters.openqasm_exporter.get_parameters(operator: OperatorLike[QubitT]) str

Get parameters in OpenQASM format from operator.

There are two cases where the operator is parameterized. Either it is a rotation operator, or it is a controlled operator where the target operator is a rotation operator. If it is neither, an empty string is returned.

Parameters:

operator – Operator to get parameters from.

Returns:

Parameter string in OpenQASM format, or an empty string if the operator is not parameterized.