Package: pyqcisim
PyQCISimIntroductionA 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 simulatorQuantumSimis used as the backend. Other quantum state simulators will also be added in the future.InstallationInstall from pippip install pyqcisimInstall from repositoryClone (or download) this repository to your computer, and pip install it using the following commands:gitclonehttps://gitee.com/hpcl_quanta/pyqcisimcdpyqcisim
pipinstall-e.Note, if your computer also has python2 installed, you might require to replacepipwithpip3.Verify the installation under the root directory of pyqcisim:pytest-raA successful installation should see all tests passed.
Note. if your computer also has python2 installed, you might require to replacepytestwithpytest-3.UsageDirect QCIS simulation in command lineYou can use the filepyqcisim/simulate_qcis.pyto 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>--helpCall PyQCISim in PythonFirst, import the simulator, instantiatePyQCISim, and compile the given QCIS program:frompyqcisim.simulatorimport*pyqcisim=PyQCISim()prog="""X qAX qBCNOT qA qBM qAM qB"""pyqcisim.compile(prog)Second, you can start simulate the program using either the defaultone_shotmode:msmt_results=pyqcisim.simulate()print("msmt_results: ",msmt_results)or using thefinal_statemode:final_state=pyqcisim.simulate(mode="final_state")print("final_state: ",final_state)These two mode has some difference:one_shotmode: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 parameternum_shotswhen callingsimulate().Result format(['qA', 'qB'], {'00': 0, '01': 1000, '10': 0, '11': 0})final_statemode:The simulator returns the final state of the entire quantum system, which comprises two parts:The classical state of measured qubitsThe state vector of qubits that are not measuredExample result format after commenting outM qBin the above code:{'classical': {'qA': 1}, 'quantum': (['qB'], array([1.+0.j, 0.+0.j]))}Problems and FeedbackIf you have any suggestions or encounter any problems in using PyQCISim, please feel free to post an issue athttps://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 SyntaxNote, 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 InstructionsInstruction FormatDescriptionNOTEX [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 confirmedXYARB [qubit] [phi] [theta]Same asRYXDeprecatedZ2P [qubit]$R_z(\frac{\pi}{2})$DeprecatedZ2M [qubit]$R_z(-\frac{\pi}{2})$DeprecatedZ4P [qubit]$R_z(\frac{\pi}{4})$DeprecatedZ4M [qubit]$R_z(-\frac{\pi}{4})$DeprecatedTwo Qubit Operation InstructionsInstruction FormatDescriptionCZ [control_qubit] [target_qubit]Control-Z operationCNOT [control_qubit] [target_qubit]Control-NOT operationSWP [control_qubit] [target_qubit]SWAP operationSSWP [control_qubit] [target_qubit]$\sqrt{\text{SWAP}}$ operationISWP [control_qubit] [target_qubit]$i$ SWAP operationSISWP [control_qubit] [target_qubit]$\sqrt{i \text{SWAP}}$ operationMeasurement InstructionsInstruction FormatDescriptionNOTEM [qubit_1] ... [qubit_n]Measure qubits on computational basisMEASURE [qubit_1] ... [qubit_n]Measure qubits on computational basisDeprecatedAncillary InstructionsInstruction FormatDescriptionNOTEBQubit barrier (useless in PyQCISim)MiscellaneousAll qubit names can be arbitrary identifiers except for reserved key words in QCIS.Parameters representing angles are all in radian.Multiple QCIS instructions should be seperated by\n.Comment line should start with a#.