mindquantum.io.QCIS

View Source On Gitee
class mindquantum.io.QCIS[source]

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)[source]

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)[source]

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, circuit)[source]

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.

Raises
to_string(circuit)[source]

Convert the input circuit to qcis.

Parameters

circuit (Circuit) – The quantum circuit you want to translated to qcis.

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