mindquantum.io.HiQASM

View Source On Gitee
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
  • file_name (str) – The file name you want to save the HiQASM file.

  • circuit (Circuit) – The Circuit you want to convert.

  • version (str) – The version of HiQASM. Default: '0.1'.

Raises
to_string(circuit, version='0.1')[source]

Convert circuit to HiQASM.

Parameters
  • circuit (Circuit) – The quantum circuit you want to translated to HiQASM.

  • version (str) – The HiQASM version you want to use. Default: '0.1'.

Returns

str, The HiQASM format of input circuit.

Raises