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:
objectResult of exporting a ParityOS
Circuitto OpenQASM 3.
- 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_allbefore calling this function.- Parameters:
parityos_circuit – ParityOS
Circuitto 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.