mindquantum.io.QCIS#
- class mindquantum.io.QCIS#
Convert a circuit to qcis format.
Examples
>>> circ = Circuit() >>> circ.x(0).z(1,0).rx({"a":-2*np.sqrt(2)}, 0).sx(0).barrier() >>> circ.ry(ParameterResolver(data={'theta':-np.pi}, const=np.pi), 1) >>> string= QCIS().to_string(circ) >>> print(string) X Q0 CZ Q0 Q1 RX Q0 -2√2*a X2P Q0 B Q0 B Q1 RY Q1 -π*theta + π >>> circ1 = QCIS().from_string(string) >>> print(circ1) ┏━━━┓ ┏━━━━━━━━━━━━┓ ┏━━━━┓ q0: ──┨╺╋╸┠───■───┨ RX(-2√2*a) ┠─┨ SX ┠─▓──────────────────────── ┗━━━┛ ┃ ┗━━━━━━━━━━━━┛ ┗━━━━┛ ▓ ┏━┻━┓ ▓ ┏━━━━━━━━━━━━━━━━━━┓ q1: ────────┨ Z ┠───────────────────────▓─┨ RY(-π*theta + π) ┠─── ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━┛
- from_file(file_name: str)#
Read a qcis file.
- Parameters:
file_name (str) – The path of file that stored quantum circuit in qcis format.
- Returns:
Circuit, the quantum circuit translated from qcis file.
- from_string(string: str)#
Read a QCIS string.
- Parameters:
string (str) – The QCIS string of Circuit.
- Returns:
Circuit, the quantum circuit translated from QCIS string.
Examples
>>> string = "X Q0 \nCZ Q0 Q1 \nRX Q0 -2√2*a\nX2P Q0 \nB Q0\nB Q1\nRY Q1 -π*theta + π" >>> circ = QCIS().from_string(string) >>> print(circ) ┏━━━┓ ┏━━━━━━━━━━━━┓ ┏━━━━┓ q0: ──┨╺╋╸┠───■───┨ RX(-2√2*a) ┠─┨ SX ┠─▓──────────────────────── ┗━━━┛ ┃ ┗━━━━━━━━━━━━┛ ┗━━━━┛ ▓ ┏━┻━┓ ▓ ┏━━━━━━━━━━━━━━━━━━┓ q1: ────────┨ Z ┠───────────────────────▓─┨ RY(-π*theta + π) ┠─── ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━┛
- to_file(file_name: str, circuit, parametric: bool = True) None#
Convert a quantum circuit to qcis format and save in file.
- Parameters:
file_name (str) – The file name you want to save the qcis file.
circuit (Circuit) – The Circuit you want to convert.
parametric (bool) – Whether to keep the parameters in gates. If it is
False, we will discard all parameters and rotation gates with zero angles. The remaining angles will be restricted to the interval [-pi, pi]. Default:True.
- Raises:
TypeError – if file_name is not a str.
TypeError – if circuit is not a Circuit.
NotImplementedError – if the input circuit containing gates which is not supported by qcis.
- to_string(circuit, parametric: bool = True) str#
Convert the input circuit to qcis.
- Parameters:
circuit (Circuit) – The quantum circuit you want to translated to qcis.
parametric (bool) – Whether to keep the parameters in gates. If it is
False, we will discard all parameters and rotation gates with zero angles. The remaining angles will be restricted to the interval [-pi, pi]. Default:True.
- Returns:
str, The qcis format of the input circuit.
Examples
>>> circ = Circuit() >>> circ.x(0).z(1,0).rx({"a":-2*np.sqrt(2)}, 0).sx(0).barrier() >>> circ.ry(ParameterResolver(data={'theta':-np.pi}, const=np.pi), 1) >>> string= QCIS().to_string(circ) >>> print(string) X Q0 CZ Q0 Q1 RX Q0 -2√2*a X2P Q0 B Q0 B Q1 RY Q1 -π*theta + π
- Raises:
TypeError – if circuit is not a Circuit.
NotImplementedError – if the input circuit containing gates which is not supported by qcis.