Package: qsy
qsyA quantum computer state vector/stabilizer circuit simulator and assembly
language.Table of ContentsInstallationqsyExampleqsyASMUsageExampleSyntaxOperationsAdjoint OperationList of OperationsRegistersMeasurementEfficient simulation of stabilizer circuitsLicenseInstallation$ pip install qsyThis will install the Python library qsy and command-line tool qsyasm.qsyqsy is a Python library for simulating quantum circuits.ExampleThe following code creates an entangled state and prints its state vector in
Dirac notation.fromqsyimportQuantumRegister,gatesqr=QuantumRegister(2)qr.apply_gate(gates.H,0)qr.apply_gate(gates.CX,0,1)print(qr.to_dirac())The output will be:+0.70711|00> +0.70711|11>qsyASMqsyASM is a quantum assembly language acting as front-end for qsy. It allows
you to quickly write and debug quantum programs. It also allows for efficient
simulation of stabilizer circuits using thechpback-end.Usageusage: qsyasm [-h] [-V] [-v] [-t] [-b B] [-s SHOTS] [--ignore-print-warning]
              [--skip-zero-amplitudes]
              filename

qsyasm assembly runner

positional arguments:
  filename              qsyasm file to execute

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -v, --verbose         verbose output
  -t, --time            time program execution
  -b B, --backend B     simulator back-end to use: chp or statevector
                        (default: statevector)
  -s SHOTS, --shots SHOTS
                        amount of shots to run
  --ignore-print-warning
                        ignore register too large to print warning
  --skip-zero-amplitudes
                        don't print states with an amplitude of 0ExampleThe following qsyASM program creates an entangled state and measures to a
classical register:qreg[2]qcreg[2]chq[0]cxq[0],q[1]measq,cRunning it:$ qsyasm examples/qsyasm/bell.qs
q[2]: +1|11>
      +0 | 00
      +0 | 01
      +0 | 10
      +1 | 11
c[2]: 11Or running it a number of times:$ qsyasm examples/qsyasm/bell.qs --shots=1024
q[2]: +1|00>
      +1 | 00
      +0 | 01
      +0 | 10
      +0 | 11
c[2]: {'11': 550, '00': 474}More examples such as the quantum phase estimation algorithm can be found in theexamples/qsyasmfolder.SyntaxThe structure of a qsyASM program consists of a list of instructions. An
instruction is defined as an operation followed by its arguments.OperationsThe instructioncxq[0],q[1]applies a CNOT operation with control qubitq[0]and target qubitq[1].
Some operations take an angle (in radians) as argument. The parameterized operationrz(pi/2)q[0]rotatesq[0]π/2 radians around the Z axis. Expressions are allowed in
parameterized operations. Expression operators supported are+,-,*,/and**(power). The variablepiis available for convenience.Adjoint OperationTo apply the adjoint of a gate, theadjkeyword is available. For example, to
apply the adjoint of S (S dagger):adjsq[0]List of OperationsGateqsyASM operationPauli Ii targetPauli Xx targetPauli Yy targetPauli Zz targetHadamardh targetSs targetTt targetRxrx(angle) targetRyry(angle) targetRzrz(angle) targetCNOTcx control, targetCZcz control, targetCRxcrx(angle) control, targetCRycry(angle) control, targetCRzcrz(angle) control, targetToffoliccx controlA, controlB, targetRegistersDefining a quantum register is done with theqregoperation. The instructionqreg[5]qdefines a 5 qubit quantum register namedq. Likewise, a classical register (useful for measuring) can be defined ascreg[5]cQubits in a quantum register are initiated to |0⟩, and bits in a classical register to 0.MeasurementMeasurement can be done on individual qubits, or a complete quantum state. The programqreg[5]qcreg[1]chq[0]measq[0],c[0]measuresq[0]toc[0], collapsing the state and storing the result inc[0]. The measurement result can be ignored by only passing one argument tomeas:measq[0]To measure a complete quantum state you can pass the whole quantum and classical register:qreg[3]qcreg[3]c; 3 qubit GHZ statehq[0]cxq[0],q[1]cxq[0],q[2]measq,ccollapsing the quantum registerqand storing the measurement result inc. This only works when the quantum register and classical register are equal in size.Efficient simulation of stabilizer circuitsCircuits consisting only of CNOT, H, S, X, Y, Z and CZ gates can be efficiently
simulated with the CHP back-end. Using any other operations with the CHP
back-end will result in an error.For example, we can simulate a partially entangled 750 qubit state:$ qsyasm examples/qsyasm/750_qubits.qs --backend=chp
c[750]: 000000000000000000000000000000000000000000000000001111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000This back-end is an implementation of the CHP simulator described by
Scott Aaronson and Daniel Gottesman in their paper "Improved Simulation of Stabilizer Circuits"
(arXiv:quant-ph/0406196).LicenseThis project is licensed under the MIT License. See theLICENSEfile
for the full license.