mindquantum.io.OpenQASM
- class mindquantum.io.OpenQASM[source]
Convert a circuit to openqasm format.
Examples
>>> import numpy as np >>> from mindquantum.core import Circuit >>> from mindquantum.io import OpenQASM >>> circuit = Circuit().rx(0.3, 0).z(0, 1).zz(np.pi, [0, 1]) >>> openqasm = OpenQASM() >>> circuit_str = openqasm.to_string(circuit) >>> print(circuit_str) OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; rx(0.3) q[0]; cz q[1],q[0]; rzz(6.283185307179586) q[0],q[1];
- from_file(file_name)[source]
Read a openqasm file.
- Parameters
file_name (str) – The path of file that stored quantum circuit in openqasm format.
- Returns
Circuit, the quantum circuit translated from openqasm file.
- from_string(string)[source]
Read a OpenQASM string.
- Parameters
string (str) – The OpenQASM string of Circuit.
- Returns
Circuit
, the quantum circuit translated from OpenQASM string.
Examples
>>> from mindquantum.io import OpenQASM >>> from mindquantum.core.circuit import Circuit >>> circ = Circuit().x(0, 1).h(1) >>> string = OpenQASM().to_string(circ) >>> OpenQASM().from_string(string) ┏━━━┓ q0: ──┨╺╋╸┠───────── ┗━┳━┛ ┃ ┏━━━┓ q1: ────■───┨ H ┠─── ┗━━━┛
- to_file(file_name, circuit, version='2.0')[source]
Convert a quantum circuit to openqasm format and save in file.
- Parameters
- Raises
- to_string(circuit, version='2.0')[source]
Convert circuit to openqasm.
- Parameters
- Returns
str, The openqasm format of input circuit.
- Raises
TypeError – if circuit is not a Circuit.
TypeError – if version is not a str.
NotImplementedError – if openqasm version not implement.
ValueError – if gate not implement in this version.