Skip to main content

A Python-based Quantum Control Instruction Set (QCIS) simulator

Project description

PyQCISim

Introduction

A Python-based Quantum Control Instruction Set (QCIS) simulator developed by Zhihao Wu and Xiang Fu from QUANTA@NUDT.

Actually, PyQCISim is more a QCIS parser than a simulator. PyQCISim implements a QCIS parser which translates QCIS files into an internal representation of quantum operations. These quantum operations are then sent to another simulator to simulate the quantum state evolution. Currently, the open-source density matrix simulator QuantumSim is used as the backend. Other quantum state simulators will also be added in the future.

Installation

Install from pip

pip install pyqcisim

Install from repository

Clone (or download) this repository to your computer, and pip install it using the following commands:

git clone https://gitee.com/hpcl_quanta/pyqcisim
cd pyqcisim
pip install -e .

Note, if your computer also has python2 installed, you might require to replace pip with pip3.

Verify the installation under the root directory of pyqcisim:

pytest -ra

A successful installation should see all tests passed. Note. if your computer also has python2 installed, you might require to replace pytest with pytest-3.

Usage

Direct QCIS simulation in command line

You can use the file pyqcisim/simulate_qcis.py to directly simulate a QCIS file:

python <path-to-pyqcisim/simulate_qcis.py> <qcis-file>

You can use the following command to see its various parameters:

python <path-to-pyqcisim/simulate_qcis.py> --help

Call PyQCISim in Python

First, import the simulator, instantiate PyQCISim, and compile the given QCIS program:

from pyqcisim.simulator import *
pyqcisim = PyQCISim()
prog = """
X qA
X qB
CNOT qA qB
M qA
M qB
"""
pyqcisim.compile(prog)

Second, you can start simulate the program using either the default one_shot mode:

msmt_results = pyqcisim.simulate()
print("msmt_results: ", msmt_results)

or using the final_state mode:

final_state = pyqcisim.simulate(mode="final_state")
print("final_state: ", final_state)

These two mode has some difference:

  • one_shot mode:
    • Only qubit measurement result will be recorded.
    • If there is no measurement in the circuit, then the result will be empty.
    • The entire circuit will be simulated for $n$ times, where $n$ is default to 1000 and can be set via the optional parameter num_shots when calling simulate().
    • Result format
      • (['qA', 'qB'], {'00': 0, '01': 1000, '10': 0, '11': 0})
  • final_state mode:
    • The simulator returns the final state of the entire quantum system, which comprises two parts:
      • The classical state of measured qubits
      • The state vector of qubits that are not measured
    • Example result format after commenting out M qB in the above code:
      • {'classical': {'qA': 1}, 'quantum': (['qB'], array([1.+0.j, 0.+0.j]))}

Problems and Feedback

If you have any suggestions or encounter any problems in using PyQCISim, please feel free to post an issue at https://gitee.com/hpcl_quanta/pyqcisim/issues, or send an email to Xiang Fu (xiangfu at quanta dot org dot cn)

Currently Supported QCIS and the Syntax

Note, PyQCISim supports a super set of QCIS instructions as supported by the current quantumcomputer.ac.cn. The user should pay attention to instructions not supported by quantumcomputer.ac.cn.

In the following, we adopt the following conventions:

  • [qubit], [control_qubit], [target_qubit] are IDENTIFIERs
  • [theta] $\in [-\pi, \pi]$
  • [phi] $\in [-\pi, \pi]$
  • $R_{x/y/z}(\theta)$: rotate the target qubit for $\theta$-radius angle along the $x/y/z$-axis.
  • $R_{\hat{n}}(\theta)$: rotate the target qubit for $\theta$-radius angle along the $\hat{n}$-direction.

Single Qubit Operation Instructions

Instruction Format Description NOTE
X [qubit] $R_x(\pi)$
Y [qubit] $R_y(\pi)$
Z [qubit] $R_z(\pi)$
H [qubit] $\frac{1}{\sqrt{2}}[[1, 1], [1, -1]]$
S [qubit] $e^{\frac{\pi}{4}}R_z(\frac{\pi}{2})$
SD [qubit] $e^{-\frac{\pi}{4}}R_z(-\frac{\pi}{2})$
T [qubit] $e^{\frac{\pi}{8}}R_z(\frac{\pi}{4})$
TD [qubit] $e^{-\frac{\pi}{8}}R_z(-\frac{\pi}{4})$
X2P [qubit] $R_x(\frac{\pi}{2})$
X2M [qubit] $R_x(-\frac{\pi}{2})$
Y2P [qubit] $R_y(\frac{\pi}{2})$
Y2M [qubit] $R_y(-\frac{\pi}{2})$
RX [qubit] [theta] $R_x(\theta)$ $e^{-i\theta X / 2}$
RY [qubit] [theta] $R_y(\theta)$ $e^{-i\theta Y / 2}$
RZ [qubit] [theta] $R_z(\theta)$ $e^{-i\theta Z / 2}$
XY [qubit] [phi] $R_{\hat{n}}(\pi),\quad \hat{n}=[\cos{\phi}, \sin{\phi}, 0]$
XY2P [qubit] [phi] $R_{\hat{n}}(\frac{\pi}{2}),\quad \hat{n}=[\cos{\phi}, \sin{\phi}, 0]$
XY2M [qubit] [phi] $R_{\hat{n}}(-\frac{\pi}{2}),\quad \hat{n}=[\cos{\phi}, \sin{\phi}, 0]$
RXY [qubit] [phi] [theta] $R_{\hat{n}}(\theta),\quad \hat{n}=[\cos{\phi}, \sin{\phi}, 0]$ To be confirmed
XYARB [qubit] [phi] [theta] Same as RYX Deprecated
Z2P [qubit] $R_z(\frac{\pi}{2})$ Deprecated
Z2M [qubit] $R_z(-\frac{\pi}{2})$ Deprecated
Z4P [qubit] $R_z(\frac{\pi}{4})$ Deprecated
Z4M [qubit] $R_z(-\frac{\pi}{4})$ Deprecated

Two Qubit Operation Instructions

Instruction Format Description
CZ [control_qubit] [target_qubit] Control-Z operation
CNOT [control_qubit] [target_qubit] Control-NOT operation
SWP [control_qubit] [target_qubit] SWAP operation
SSWP [control_qubit] [target_qubit] $\sqrt{\text{SWAP}}$ operation
ISWP [control_qubit] [target_qubit] $i$ SWAP operation
SISWP [control_qubit] [target_qubit] $\sqrt{i \text{SWAP}}$ operation

Measurement Instructions

Instruction Format Description NOTE
M [qubit_1] ... [qubit_n] Measure qubits on computational basis
MEASURE [qubit_1] ... [qubit_n] Measure qubits on computational basis Deprecated

Ancillary Instructions

Instruction Format Description NOTE
B Qubit barrier (useless in PyQCISim)

Miscellaneous

  1. All qubit names can be arbitrary identifiers except for reserved key words in QCIS.
  2. Parameters representing angles are all in radian.
  3. Multiple QCIS instructions should be seperated by \n.
  4. Comment line should start with a #.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqcisim-1.3.7.tar.gz (37.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyqcisim-1.3.7-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file pyqcisim-1.3.7.tar.gz.

File metadata

  • Download URL: pyqcisim-1.3.7.tar.gz
  • Upload date:
  • Size: 37.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.19

File hashes

Hashes for pyqcisim-1.3.7.tar.gz
Algorithm Hash digest
SHA256 187748d2805d3116c49eb22228def515521c3a82667cbcfa3c23327d61226a58
MD5 7fc97fddbe0e4222d225836e3860359f
BLAKE2b-256 a2a60436f5456e44b54c56589f9eff4a4cbf76063cd386e231e1c8dfb646c57c

See more details on using hashes here.

File details

Details for the file pyqcisim-1.3.7-py3-none-any.whl.

File metadata

  • Download URL: pyqcisim-1.3.7-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.19

File hashes

Hashes for pyqcisim-1.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d1409eafa9a7ccfcfb999370d418402411621fb8714ad04dbc3e14d36a016d2d
MD5 3c4260dc9db1a84cb38d698a3a501a5c
BLAKE2b-256 d9ac411f440f520e853bd32886d2e966a7ec2281a55b1f5be53a3921717a54af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page