qrisp.QuantumCircuit.to_qasm2#
- QuantumCircuit.to_qasm2(formatted: bool = False, filename: str | None = None, encoding: str | None = None) str[source]#
Returns the OpenQASM 2.0 string of this QuantumCircuit.
If the circuit contains gates that cannot be represented in OpenQASM 2.0, it is first transpiled to a universal set of primitive gates before exporting.
- Parameters:
- formattedbool, optional
Return formatted Qasm string. The default is False.
- filenamestr, optional
If provided, the QASM string is also written to this file path. The default is None.
- encodingstr, optional
The file encoding to use when writing to
filename. Defaults to the system’s preferred encoding. Only relevant whenfilenameis given.
- Returns:
- str
The OpenQASM 2.0 string.
Examples
>>> from qrisp import QuantumCircuit >>> qc = QuantumCircuit(2) >>> qc.h(0) >>> qc.cx(0, 1) >>> print(qc.to_qasm2()) OPENQASM 2.0; include "qelib1.inc"; qreg qb_77[1]; qreg qb_78[1]; h qb_77[0]; cx qb_77[0],qb_78[0];