mindquantum.io.HiQASM
- class mindquantum.io.HiQASM[source]
Convert a circuit to HiQASM format.
Examples
>>> import numpy as np >>> from mindquantum.io.qasm import HiQASM >>> from mindquantum.core import Circuit >>> circuit = Circuit().rx(0.3, 0).z(0, 1).rzz(np.pi, [0, 1]) >>> HiQASM = HiQASM() >>> circuit_str = HiQASM.to_string(circuit) >>> print(circuit_str[68: 80]) CZ q[1],q[0] >>> circuit_2 = HiQASM.from_string(circuit_str) >>> circuit_2 q0: ──RX(3/10)────Z────ZZ(π)── │ │ q1: ──────────────●────ZZ(π)──
- from_file(file_name)[source]
Read a HiQASM file.
- Parameters
file_name (str) – The path of file that stored quantum circuit in HiQASM format.
- Returns
Circuit, the quantum circuit translated from HiQASM file.
- from_string(string)[source]
Read a HiQASM string.
- Parameters
string (str) – The HiQASM string of a Circuit.
- Returns
Circuit, The quantum circuit translated from HiQASM string.
- to_file(file_name, circuit, version='0.1')[source]
Convert a quantum circuit to HiQASM format and save in file.
- Parameters
- Raises
- to_string(circuit, version='0.1')[source]
Convert circuit to HiQASM.
- Parameters
- Returns
str, The HiQASM format of input circuit.
- Raises
TypeError – if circuit is not a Circuit.
TypeError – if version is not a str.
NotImplementedError – if HiQASM version not implement.
ValueError – if gate not implement in this version.