Source code for mpqp.qasm.qasm_to_myqlm

"""The myQLM library allows the user to instantiate a myQLM ``Circuit`` from an
OpenQASM 2.0 code. MyQLM is able to parse most of the standard gates, and allows
us to complete the missing gates by linking them to already defined ones. We
call the function :func:`qasm2_to_myqlm_Circuit` to generate the circuit from
the qasm code."""

from typing import TYPE_CHECKING

from typeguard import typechecked

if TYPE_CHECKING:
    from qat.core.wrappers.circuit import Circuit

from mpqp.qasm.open_qasm_2_and_3 import open_qasm_hard_includes


[docs]@typechecked def qasm2_to_myqlm_Circuit(qasm_str: str) -> "Circuit": """Converting a OpenQASM 2.0 code into a QLM Circuit. Args: qasm_str: A string representing the OpenQASM 2.0 code. Returns: A Circuit equivalent to the QASM code in parameter. """ from qat.interop.openqasm import OqasmParser # type: ignore parser = OqasmParser(gates={"p": "PH", "u": "U"}) # requires myqlm-interop-1.9.3 circuit = parser.compile(open_qasm_hard_includes(qasm_str, set())) return circuit