├── LICENSE ├── README.md ├── examples ├── qckt │ ├── Getting-started-tutorial-noise-sim.ipynb │ ├── Getting-started-tutorial.ipynb │ ├── Miscellaneous Algorithms │ │ ├── QFT-constructor.ipynb │ │ ├── add-qckt.ipynb │ │ └── bell-state-nativegates.ipynb │ └── Well-Known Algorithms │ │ ├── bern-vazi-qckt.ipynb │ │ ├── deutsch-jozsa-qckt.ipynb │ │ ├── grover1-qckt.ipynb │ │ ├── grover2-qckt.ipynb │ │ ├── libgrover.py │ │ ├── libqpe.py │ │ ├── period-finding-qckt.ipynb │ │ ├── quantum-error-correction.ipynb │ │ ├── simons-algorithm.ipynb │ │ ├── sudoku.ipynb │ │ ├── teleportation-qckt.py │ │ ├── testgrover.py │ │ └── testqpe.py └── qsim │ ├── add.py │ ├── bern-vazi.py │ ├── depolarizing-dm.py │ ├── deutsch-jozsa.py │ ├── double-slit.py │ ├── fourier.py │ ├── grover-noisey.py │ ├── grover.py │ ├── period-finding.py │ ├── simple-search.py │ ├── teleportation-manyworlds.py │ └── teleportation.py ├── pip-local-install.sh ├── qucircuit ├── DEVELOPER_NOTES.txt ├── LICENSE ├── README.md ├── RELEASE-splash.md ├── TODO.md ├── qckt │ ├── Canvas.py │ ├── Gates.py │ ├── Job.py │ ├── QCkt.py │ ├── Registers.py │ ├── __init__.py │ ├── backend │ │ ├── BackendAPI.py │ │ ├── QSystems.py │ │ ├── __init__.py │ │ └── svcReg.py │ ├── gatesutils │ │ ├── GatesUtils.py │ │ └── __init__.py │ ├── noisemodel │ │ ├── __init__.py │ │ ├── noiseChannels.py │ │ └── noiseUtils.py │ └── qException.py ├── setup.cfg └── setup.py ├── qusimulator ├── LICENSE ├── README.md ├── RELEASE-splash.md ├── qsim │ ├── DMQsim.py │ ├── Qsim.py │ ├── __init__.py │ ├── noisemodel │ │ ├── __init__.py │ │ ├── noiseChannels.py │ │ └── noiseUtils.py │ ├── qSimException.py │ ├── qcli.py │ ├── qgates.py │ └── qgatesUtils.py ├── setup.cfg └── setup.py └── tests ├── qckt ├── CTRL-tests-dm.py ├── CTRL-tests.py ├── QFT-test-dm.py ├── QFT-test.py ├── RUN_ALL_TESTS ├── SHOWDIFF ├── allgates_drawifcbit_test.py ├── arg_validations.py ├── backend-test-dm.py ├── backend-test.py ├── circuits-test-dm.py ├── circuits-test.py ├── custom-append-realign.py ├── customgate-test-dm.py ├── customgate-test.py ├── direct-qengine-dm.py ├── direct-qengine.py ├── drawlist-test.py ├── expected │ ├── CTRL-tests-dm.py.log.1 │ ├── CTRL-tests-dm.py.log.2 │ ├── CTRL-tests.py.log │ ├── QFT-test-dm.py.log.1 │ ├── QFT-test-dm.py.log.2 │ ├── QFT-test.py.log │ ├── allgates_drawifcbit_test.py.log │ ├── arg_validations.py.log │ ├── backend-test-dm.py.log.1 │ ├── backend-test-dm.py.log.2 │ ├── backend-test.py.log │ ├── circuits-test-dm.py.log │ ├── circuits-test.py.log │ ├── custom-append-realign.py.log │ ├── customgate-test-dm.py.log │ ├── customgate-test.py.log │ ├── direct-qengine-dm.py.log │ ├── direct-qengine.py.log │ ├── drawlist-test.py.log │ ├── gates-test-dm.py.log.1 │ ├── gates-test-dm.py.log.2 │ ├── gates-test.py.log │ ├── noise-measurement-test.py.log │ ├── noise-model-test.py.log │ ├── noise-op-vs-seq.py.log │ ├── noise-qengdeb-test.py.log │ ├── noise-quant.py.log │ ├── noise-test-qckt-dmdeb.py.log │ ├── noise-test-qckt-dmeng.py.log │ ├── opmatrix-tests-dm.py.log │ ├── opmatrix-tests.py.log │ ├── realign-test-dm.py.log │ ├── realign-test.py.log │ ├── registry-access-dm.py.log │ ├── registry-access.py.log │ ├── rgates-test-dm.py.log.1 │ ├── rgates-test-dm.py.log.2 │ ├── rgates-test.py.log │ ├── runstats-dm.py.log │ └── runstats.py.log ├── gates-test-dm.py ├── gates-test.py ├── noise-measurement-test.py ├── noise-model-test.py ├── noise-op-vs-seq.py ├── noise-qengdeb-test.py ├── noise-quant.py ├── noise-test-qckt-dmdeb.py ├── noise-test-qckt-dmeng.py ├── opmatrix-tests-dm.py ├── opmatrix-tests.py ├── realign-test-dm.py ├── realign-test.py ├── registry-access-dm.py ├── registry-access.py ├── rgates-test-dm.py ├── rgates-test.py ├── runstats-dm.py └── runstats.py └── qsim ├── RUN_ALL_TESTS ├── SHOWDIFF ├── combine-gates-dm.py ├── combine-gates.py ├── expected ├── combine-gates-dm.py.log ├── combine-gates.py.log ├── fourier-dm.py.log ├── fourier.py.log ├── gates-test-dm.py.log.1 ├── gates-test-dm.py.log.2 ├── gates-test.py.log ├── helloworld-dm.py.log.1 ├── helloworld-dm.py.log.2 ├── helloworld-traceON-dm.py.log.1 ├── helloworld-traceON-dm.py.log.2 ├── helloworld-traceON.py.log.1 ├── helloworld-traceON.py.log.2 ├── helloworld.py.log.1 ├── helloworld.py.log.2 ├── ifcbit-dm.py.log ├── ifcbit.py.log ├── initialize-state-dm.py.log.1 ├── initialize-state-dm.py.log.2 ├── initialize-state.py.log ├── noise-model-test.py.log ├── noise-op-vs-seq.py.log ├── noise-test-dm.py.log ├── probestates-qzeros-test-dm.py.log.1 ├── probestates-qzeros-test-dm.py.log.2 ├── probestates-qzeros-test.py.log.1 ├── probestates-qzeros-test.py.log.2 ├── qsim-dmqsim-dropinreplacement.py.log ├── qsimcli-test.py.log ├── runstats-dm.py.log ├── runstats.py.log ├── stretch-op-dm.py.log ├── stretch-op.py.log ├── user-def-gates-dm.py.log ├── user-def-gates.py.log └── visualize.py.log ├── fourier-dm.py ├── fourier.py ├── gates-test-dm.py ├── gates-test.py ├── helloworld-dm.py ├── helloworld-traceON-dm.py ├── helloworld-traceON.py ├── helloworld.py ├── ifcbit-dm.py ├── ifcbit.py ├── initialize-state-dm.py ├── initialize-state.py ├── noise-model-test.py ├── noise-op-vs-seq.py ├── noise-test-dm.py ├── probestates-qzeros-test-dm.py ├── probestates-qzeros-test.py ├── qsim-dmqsim-dropinreplacement.py ├── qsimcli-test.py ├── runstats-dm.py ├── runstats.py ├── stretch-op-dm.py ├── stretch-op.py ├── user-def-gates-dm.py ├── user-def-gates.py └── visualize.py /README.md: -------------------------------------------------------------------------------- 1 | # A quantun computing development environment in Python 2 | Comprises of two parts - `qusimulator` (package `qsim`) the quantum simulator, and `qucircuit` (packages `qckt`, `qckt.gatesutils`, and `qckt.backend`) the library to implement quantum computing programs using quantum circuits paradigm. `qucircuit` uses `qusimulator` as a backed engine to run quantum circuits. 3 | 4 | ## INSTALLATION 5 | `qusimulator` and `qucircuit` are on PyPi now. So, you can simply install them using `pip`. 6 | 7 | pip install qusimulator 8 | pip install qucircuit 9 | 10 | Since `qucircuit` has `qusimulator` as a dependency, so installing qucircuit will also install `qusimulator`. 11 | 12 | ## FEATURES 13 | All common gates available as pre-defined. Allows user-defined gates. Allows adding control qubits to any gates. A number of utility functions to manipulate gates - combine sequentially applied or parallelly applied gates, check for unitarity, inverse. 14 | 15 | Full featured support for quantum noise simulation. Leverages a new density-matrix based simulation engine. 16 | 17 | Easy to follow documentation with tutorial introduction - see `qusimumator/README.md` and `qucircuit/README.md`. A bunch of examples under `examples/qsim` and `examples/qckt`. Code for regression tests also serves as examples to quickly learn `qsim` and `qckt` packages (see folder `tests/`). 18 | 19 | Getting started tutorials - `examples/qckt/Getting-started-tutorial.ipynb`, `examples/qckt/Getting-started-tutorial-noise-sim.ipynb` 20 | 21 | Growing list of known quantum algorithm implementations included as examples. 22 | 23 | ## CLI tool 24 | An interactive commandline interface (`qsimcli`) to quickly check out sequence of quantum operations. 25 | -------------------------------------------------------------------------------- /examples/qckt/Miscellaneous Algorithms/bell-state-nativegates.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Implementing bell-state using native gates (per Rigetti native gates)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import qckt\n", 17 | "import qckt.backend as bknd\n", 18 | "import math\n", 19 | "pi = math.pi" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "## Bell-state using high level gates" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "# First the high-level gates\n", 36 | "\n", 37 | "ck = qckt.QCkt(2,2)\n", 38 | "ck.H(0)\n", 39 | "ck.CX(0,1)\n", 40 | "\n", 41 | "job = qckt.Job(ck, qtrace=True, verbose=True)\n", 42 | "bk = bknd.Qdeb()\n", 43 | "bk.runjob(job)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Bell-state using native gates on Rigetti\n", 51 | "Based on AWS blog https://aws.amazon.com/blogs/quantum-computing/noise-in-quantum-computing/" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "ck = qckt.QCkt(2,2)\n", 61 | "\n", 62 | "ck.Rz(pi/2,0)\n", 63 | "ck.Rx(pi/2,0)\n", 64 | "\n", 65 | "ck.Rz(-pi/2,1)\n", 66 | "ck.Rx(pi/2,1)\n", 67 | "\n", 68 | "ck.CZ(1,0)\n", 69 | "\n", 70 | "ck.Rx(-pi/2,1)\n", 71 | "# ck.Rz(-pi/2,0) # not required? the blog mentioned above included these two\n", 72 | "# ck.Rz(-pi/2,1) # not required? the blog mentioned above included these two\n", 73 | "\n", 74 | "job = qckt.Job(ck, qtrace=True, verbose=True)\n", 75 | "bk = bknd.Qdeb()\n", 76 | "bk.runjob(job)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "## GHZ using native gates on Rigetti\n", 84 | "Based on Rigetti article https://pyquil-docs.rigetti.com/en/stable/compiler.html" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "\n", 94 | "ck = qckt.QCkt(3,3)\n", 95 | "\n", 96 | "ck.Rz(pi/2,0)\n", 97 | "ck.Rx(pi/2,0)\n", 98 | "ck.Rz(-pi/2,1)\n", 99 | "ck.Rx(pi/2,1)\n", 100 | "\n", 101 | "ck.CZ(1,0)\n", 102 | "\n", 103 | "ck.Rz(-pi/2,2)\n", 104 | "ck.Rx(pi/2,2)\n", 105 | "ck.Rx(-pi/2,1)\n", 106 | "\n", 107 | "ck.CZ(2,1)\n", 108 | "\n", 109 | "ck.Rz(-pi/2,0)\n", 110 | "ck.Rz(-pi/2,1)\n", 111 | "ck.Rx(-pi/2,2)\n", 112 | "ck.Rz(pi/2,2)\n", 113 | "\n", 114 | "job = qckt.Job(ck, qtrace=True, verbose=True)\n", 115 | "bk = bknd.Qdeb()\n", 116 | "bk.runjob(job)" 117 | ] 118 | } 119 | ], 120 | "metadata": { 121 | "kernelspec": { 122 | "display_name": "pytorch-py39", 123 | "language": "python", 124 | "name": "python3" 125 | }, 126 | "language_info": { 127 | "codemirror_mode": { 128 | "name": "ipython", 129 | "version": 3 130 | }, 131 | "file_extension": ".py", 132 | "mimetype": "text/x-python", 133 | "name": "python", 134 | "nbconvert_exporter": "python", 135 | "pygments_lexer": "ipython3", 136 | "version": "3.9.13" 137 | } 138 | }, 139 | "nbformat": 4, 140 | "nbformat_minor": 2 141 | } 142 | -------------------------------------------------------------------------------- /examples/qckt/Well-Known Algorithms/libgrover.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import numpy as np 5 | import random as rnd 6 | from qckt import QCktException 7 | 8 | ################################################################################# 9 | # Details @ https://en.wikipedia.org/wiki/Grover%27s_algorithm 10 | ################################################################################# 11 | 12 | ''' 13 | This library 14 | ''' 15 | 16 | class Grover: 17 | def __init__(self, orcale_ckt, inpreg, outreg, nmarked=1, probestates=None): 18 | if len(outreg) != 1: 19 | errmsg = "Out register must have only 1 qubit" 20 | raise QCktException(errmsg) 21 | 22 | # first lookup the nqubits, nclbits in the circuit, and the input register size 23 | fullnqbits,fullncbits = orcale_ckt.get_size() 24 | inreg_len = len(inpreg) 25 | 26 | #### 1. Initialization circuit 27 | init_ckt = qckt.QCkt(fullnqbits,name="Initialize") 28 | init_ckt.H(inpreg) 29 | init_ckt.X(outreg) 30 | init_ckt.H(outreg) 31 | # init_ckt.draw() 32 | 33 | #### 2. Diffuser (amplifier) circuit 34 | amp_ckt = qckt.QCkt(fullnqbits, name="Diffuser") 35 | amp_ckt.H(inpreg) 36 | amp_ckt.X(inpreg) 37 | amp_ckt.CX(*(inpreg+outreg)) 38 | amp_ckt.X(inpreg) 39 | amp_ckt.H(inpreg) 40 | # amp_ckt.draw() 41 | 42 | ### 43 | # Now assemble the component circuits into the overall full circuit 44 | ### 45 | fullckt = qckt.QCkt(fullnqbits,fullncbits,name="Full Grover's Circuit") 46 | #### 1. First add the init_ckt 47 | fullckt = fullckt.append(init_ckt) 48 | if probestates is not None: 49 | fullckt.Probe("after initialization",probestates=probestates) 50 | #### 2. now add the required number of oracle_ckt + amp_ckt pairs 51 | numitrs = int((np.pi/4.0) * ((2.0**(inreg_len))/nmarked)**0.5) # optimal # iter, less or more dont work 52 | # print("number of Invert-Diffuser iterations = ",numitrs) 53 | for itr in range(numitrs): 54 | fullckt = fullckt.append(orcale_ckt) 55 | fullckt = fullckt.append(amp_ckt) 56 | if probestates is not None: 57 | fullckt.Probe("after iteration "+str(itr+1), probestates=probestates) 58 | # fullckt.draw() 59 | self.groverckt = fullckt 60 | 61 | def getckt(self): 62 | return self.groverckt 63 | 64 | if __name__ == "__main__": 65 | pass -------------------------------------------------------------------------------- /examples/qckt/Well-Known Algorithms/libqpe.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | import qckt 5 | import qckt.gatesutils as gutils 6 | 7 | class QPE: 8 | def __init__(self, target_uop, uop_qubits, measurement_qubits): 9 | self.qpe_circuit = None 10 | 11 | # create a user defined gate for controlled-uop 12 | ctrl_func_op = gutils.CTL(target_uop) 13 | qckt.define_gate("CUOP", ctrl_func_op) 14 | 15 | # also create inverse quantum Fourier transform gate 16 | nqft = len(measurement_qubits) 17 | qftckt_qubits = [i for i in reversed(range(nqft))] 18 | ckt = qckt.QCkt(nqft) 19 | ckt.QFT(*(qftckt_qubits)) 20 | mat = ckt.to_opMatrix() 21 | QFTinvOp = gutils.opmat_dagger(mat) 22 | qckt.define_gate("QFTinv", QFTinvOp) 23 | 24 | # start the QPE circuit 25 | nqubits = len(measurement_qubits + uop_qubits) 26 | qc = qckt.QCkt(nqubits) 27 | 28 | # put all measuremnt qubits in full superposition 29 | qc.H(measurement_qubits) 30 | 31 | # Apply the controlled unitary operators in sequence 32 | len_measq = len(measurement_qubits) 33 | uop_exponent = 1 34 | for ctrl_qubit in range(len_measq): 35 | for r in range(uop_exponent): 36 | qc.CUOP(*([measurement_qubits[len_measq-ctrl_qubit-1]] + uop_qubits)) 37 | uop_exponent *= 2 38 | 39 | # complete the circuit with inverse-QFT on measurement_qubits 40 | qc.QFTinv(*measurement_qubits) 41 | 42 | self.qpe_circuit = qc 43 | 44 | def getckt(self): 45 | return self.qpe_circuit 46 | 47 | -------------------------------------------------------------------------------- /examples/qckt/Well-Known Algorithms/quantum-error-correction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# QEC\n", 8 | "With correction the error rate comes down to 2% from 10%" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 9, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import qckt\n", 18 | "import qckt.backend as bknd\n", 19 | "import qckt.noisemodel as ns" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 10, 25 | "metadata": {}, 26 | "outputs": [ 27 | { 28 | "name": "stdout", 29 | "output_type": "stream", 30 | "text": [ 31 | "Error rate without QEC: 10.60%\n", 32 | "Error rate with QEC : 2.60%\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "# Without QEC\n", 38 | "ck = qckt.QCkt(1,1)\n", 39 | "ck.X(0)\n", 40 | "ck.Border()\n", 41 | "ck.NOISE(ns.bit_flip(0.1),[0])\n", 42 | "ck.Border()\n", 43 | "ck.M([0])\n", 44 | "# ck.draw()\n", 45 | "\n", 46 | "job = qckt.Job(ck, qtrace=True, shots=1000)\n", 47 | "bk = bknd.DMQeng()\n", 48 | "bk.runjob(job=job)\n", 49 | "vcounts = job.get_counts()\n", 50 | "print(f'Error rate without QEC: {100*float(vcounts[0])/(vcounts[0]+vcounts[1]):5.2f}%')\n", 51 | "\n", 52 | "\n", 53 | "# With QEC\n", 54 | "ck = qckt.QCkt(3,1)\n", 55 | "ck.X(0)\n", 56 | "ck.CX(0,1)\n", 57 | "ck.CX(0,2)\n", 58 | "ck.Border()\n", 59 | "ck.NOISE(ns.bit_flip(0.1),[0,1,2])\n", 60 | "ck.Border()\n", 61 | "ck.CX(0,1)\n", 62 | "ck.CX(0,2)\n", 63 | "ck.CCX(1,2,0)\n", 64 | "ck.M([0])\n", 65 | "# ck.draw()\n", 66 | "\n", 67 | "job = qckt.Job(ck, qtrace=True, shots=1000)\n", 68 | "bk = bknd.DMQeng()\n", 69 | "bk.runjob(job=job)\n", 70 | "vcounts = job.get_counts()\n", 71 | "print(f'Error rate with QEC : {100*float(vcounts[0])/(vcounts[0]+vcounts[1]):5.2f}%')" 72 | ] 73 | } 74 | ], 75 | "metadata": { 76 | "kernelspec": { 77 | "display_name": "pytorch-py39", 78 | "language": "python", 79 | "name": "python3" 80 | }, 81 | "language_info": { 82 | "codemirror_mode": { 83 | "name": "ipython", 84 | "version": 3 85 | }, 86 | "file_extension": ".py", 87 | "mimetype": "text/x-python", 88 | "name": "python", 89 | "nbconvert_exporter": "python", 90 | "pygments_lexer": "ipython3", 91 | "version": "3.9.13" 92 | } 93 | }, 94 | "nbformat": 4, 95 | "nbformat_minor": 2 96 | } 97 | -------------------------------------------------------------------------------- /examples/qckt/Well-Known Algorithms/teleportation-qckt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Standard teleportation protocol 4 | 5 | import qckt 6 | from qckt.backend import * 7 | 8 | ckt = qckt.QCkt(3,3) 9 | ckt.RND(2) 10 | ckt.Border() 11 | ckt.Probe() 12 | ckt.H(0) 13 | ckt.CX(0,1) 14 | ckt.Border() 15 | ckt.CX(2,1) 16 | ckt.H(2) 17 | ckt.M([1]) 18 | ckt.M([2]) 19 | ckt.X(0).ifcbit(1,1) 20 | ckt.Z(0).ifcbit(2,1) 21 | ckt.Probe() 22 | 23 | ckt.draw() 24 | 25 | job = qckt.Job(ckt,qtrace=False, verbose=False) 26 | bk = Qdeb() 27 | bk.runjob(job) 28 | print('READ OUT RUNSTATS') 29 | job.print_runstats() 30 | -------------------------------------------------------------------------------- /examples/qckt/Well-Known Algorithms/testgrover.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | from qckt.backend import * 5 | import libgrover as grv 6 | import random as rnd 7 | import sys 8 | 9 | ### get the command line arguments 10 | if len(sys.argv) != 2: 11 | print(f"Usage: {sys.argv[0]} in_register_size") 12 | quit() 13 | ninreg = int(sys.argv[1]) 14 | nwkreg = 2 15 | noutreg = 1 16 | 17 | ### input, output, and (dummy) work registers 18 | inreg = [i for i in reversed(range(ninreg))] 19 | wkreg = [i+ninreg for i in reversed(range(nwkreg))] 20 | outreg = [i+ninreg+nwkreg for i in reversed(range(noutreg))] 21 | nqbits = ninreg + +nwkreg + noutreg 22 | 23 | ### 'needle' in the haytack = key 24 | marked = int(rnd.random() * (2**ninreg-1)) 25 | print(("Marked to search = {0:0"+str(ninreg)+"b}, ({0:d})").format(marked)) 26 | 27 | ### Build the Oracle circuit 28 | uf_ckt = qckt.QCkt(nqbits,nqbits,name="Oracle") 29 | x_list = [] 30 | for i in range(ninreg): 31 | if (marked & (0b1< 0: 34 | uf_ckt.X(x_list) 35 | uf_ckt.CX(*inreg, *outreg) 36 | if len(x_list) > 0: 37 | uf_ckt.X(x_list) 38 | # uf_ckt.draw() 39 | 40 | ### create a single gate representation of the Oracle circuit, and replace the Oracle circuit using that one gate 41 | uf_op = uf_ckt.to_opMatrix() 42 | qckt.define_gate("Oracle", uf_op) 43 | uf_ckt = qckt.QCkt(nqbits,nqbits,name="Oracle Circuit") 44 | uf_ckt.Oracle(*outreg, *wkreg, *inreg) 45 | # uf_ckt.draw() 46 | 47 | grv_ckt = grv.Grover(uf_ckt,inreg,outreg).getckt() 48 | grv_ckt.M(inreg) 49 | grv_ckt.draw() 50 | 51 | correct_res = 0 52 | job = qckt.Job(grv_ckt, shots=100) 53 | bk = Qeng() 54 | bk.runjob(job) 55 | job.plot_counts(verbose=False) -------------------------------------------------------------------------------- /examples/qckt/Well-Known Algorithms/testqpe.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | import qckt 5 | from qckt.backend import * 6 | import libqpe as qpe 7 | 8 | #### 9 | # qubits registers 10 | # | target | measurement qubits | 11 | # | MSB | ... ... ... 2 1 0 | 12 | #### 13 | n_counting_qubits = 4 14 | measurement_qubits = [i for i in reversed(range(n_counting_qubits))] 15 | target_qubit = [n_counting_qubits] 16 | nqubits = n_counting_qubits + 1 17 | 18 | #### 19 | # the target unitary operator (we do a 1 qubit function here), converted to an operator matrix 20 | #### 21 | theta = 6.0/8.0 22 | ckt = qckt.QCkt(1) 23 | ckt.P(2*np.pi*theta,0) 24 | uop = ckt.to_opMatrix() 25 | 26 | #### 27 | # construct the QPE circuit 28 | # create the initial part of the circuit, 29 | # * with measurement qubits register, and 30 | # * target uop register, setup with an eigenvector 31 | # add the full QPE circuit built using libqpe QPE class 32 | # finally, the measurement of measuremnt_qubits 33 | # 34 | # libqpe QPE class takes as inputs: 35 | # * the unitary operator, 36 | # * a register on which the operator operates, initialized to an eigenvector of the operator, and 37 | # * a register for measuring the result 38 | #### 39 | # start the circuit 40 | mycircuit = qckt.QCkt(nqubits=nqubits,nclbits=nqubits) 41 | # set target register to operator's eigenvector 42 | mycircuit.X(target_qubit) 43 | # get the rest of the QPE circuit built using libqpe 44 | qpeckt = qpe.QPE(uop, target_qubit, measurement_qubits).getckt() 45 | # append to the initial circuit 46 | mycircuit = mycircuit.append(qpeckt) 47 | # and add the measuremnt 48 | mycircuit.M(measurement_qubits) 49 | mycircuit.draw() 50 | 51 | #### 52 | ## run multiple shots display the bargraph of results 53 | ## pick the one with max freq as the result 54 | #### 55 | job = qckt.Job(mycircuit, shots=100) 56 | bk = Qeng() 57 | bk.runjob(job) 58 | creg = job.get_creg() 59 | counts = job.get_counts() 60 | 61 | # use the measured values to compute estimated phase 62 | resvalue = max(range(len(counts)), key=lambda x : counts[x]) 63 | print(f"Most frequent readout = {resvalue}, frequency = {counts[resvalue]}/{len(creg)}") 64 | print(str(resvalue)+"/2**"+str(n_counting_qubits)," = ",float(resvalue)/(2**n_counting_qubits)) 65 | -------------------------------------------------------------------------------- /examples/qsim/add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | print(""" 4 | PROBLEM STATEMENT: 5 | Adds 2 2-bit numbers, result is 3-bits, and scratch register is 2-bits holdch holds carry overs for bits 1 and 2, 6 | there is no carry over value expected for bit 0, hence no qubit for that 7 | 8 | Total of 9 qubits, hence simulator took just over 1 second elapsed time on my laptop. 9 | The circuit blueprint used is -- 10 | 11 | ci+1 ----------o---o----- --.-- 12 | ci ------.---|---.----- --|-- 13 | | | | | 14 | bi ----.-|---.---|----- --|-- 15 | ai --.-|-|---.---|----- --|-- 16 | | | | | | 17 | si+1 --|-|-|-------|----- --o-- 18 | si --o-o-o-----x-.-x--- ----- 19 | 20 | Need to copy the final carry-out bit into the highest order result bit, as shown. 21 | 22 | """) 23 | 24 | 25 | import qsim 26 | 27 | q = qsim.QSimulator(9,qtrace=False) 28 | 29 | s = [0, 1, 2] # sum bits - Result of addition 30 | c = [3, 4] # carry bits, scratch pad register - Junk bits 31 | b = [5, 6] # input number B 32 | a = [7, 8] # input number A 33 | 34 | H4 = qsim.qcombine_par("H4",[qsim.H(),qsim.H(),qsim.H(),qsim.H()]) 35 | q.qgate(H4,[a[0],a[1],b[0],b[1]]) 36 | 37 | # run the addition 38 | for i in range(2): 39 | print("Processing bit", i) 40 | q.qgate(qsim.C(),[a[i],s[i]]) 41 | q.qgate(qsim.C(),[b[i],s[i]]) 42 | if i != 0: 43 | q.qgate(qsim.C(),[c[i-1],s[i]]) 44 | q.qgate(qsim.T(),[a[i],b[i],c[i]]) 45 | if i != 0: 46 | q.qgate(qsim.X(),[s[i]]) 47 | q.qgate(qsim.T(),[s[i],c[i-1],c[i]]) 48 | q.qgate(qsim.X(),[s[i]]) 49 | q.qgate(qsim.C(),[c[1],s[2]]) 50 | 51 | # Clean up the junk bits 52 | print("Cleaning up junk bits") 53 | for i in reversed(range(2)): 54 | if i != 0: 55 | q.qgate(qsim.X(),[s[i]]) 56 | q.qgate(qsim.T(),[s[i],c[i-1],c[i]]) 57 | q.qgate(qsim.X(),[s[i]]) 58 | q.qgate(qsim.T(),[a[i],b[i],c[i]]) 59 | 60 | q.qreport("Result") 61 | -------------------------------------------------------------------------------- /examples/qsim/bern-vazi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | 5 | print(""" 6 | ------------------------------------------------------------------------------------------------------- 7 | Problem Statement: 8 | 9 | Given a function f(x) on n qubits |x>, that has an n-bit secret code, a, 10 | with f(x) = a.x = (a0x0+a1x1+...) modulo 2. 11 | 12 | Find the secret code, a. 13 | ------------------------------------------------------------------------------------------------------- 14 | """) 15 | 16 | ########################################################################### 17 | ## This is the function with the secret code 18 | ########################################################################### 19 | def get_fx(qc): 20 | input_sz = qc.qsize() - 1 21 | secret_code = 0b11101 22 | code_fmt = "{:0"+"{:d}".format(input_sz)+"b}" 23 | print("Pssst... the secret code is ",code_fmt.format(secret_code)) 24 | fx_oplist = [] 25 | for i in range(input_sz): 26 | if secret_code & (0x1< to |-> 51 | self.qc.qgate(qsim.X(),[self.inputsz]) 52 | self.qc.qgate(qsim.H(),[self.inputsz]) 53 | print("Step 0: Prepared |b> as |->") 54 | 55 | ########################################################################### 56 | ## Step 1: Apply H on all qbits of |x> 57 | for i in range(self.inputsz): 58 | self.qc.qgate(qsim.H(),[i]) 59 | print("Step 1: Applied H to all |x> qbits") 60 | 61 | ########################################################################### 62 | ## Step 2: Now apply the secret function f() 63 | qbit_list = list(range(self.inputsz+1)) 64 | qbit_list.reverse() 65 | self.qc.qgate(fx,qbit_list) 66 | print("Step 2: Applied FX to |b>|x>") 67 | 68 | ########################################################################### 69 | ## Step 3: Again apply H on all qbits of |x> 70 | for i in range(self.inputsz): 71 | self.qc.qgate(qsim.H(),[i]) 72 | print("Step 3: Again Applied H to all |x> qbits") 73 | 74 | ########################################################################### 75 | ## Step 4: Measure all qbits of |x> 76 | v = self.qc.qmeasure(list(range(self.inputsz))) # this will give [LSB, ..., MSB] 77 | res = 0 78 | for i in range(self.inputsz): 79 | res += (v[i] << i) 80 | print("Step 4: Measured all qbits of |x>") 81 | 82 | print("Result = "+code_fmt.format(res)) 83 | 84 | if __name__ == "__main__": 85 | qc = qsim.QSimulator(7) 86 | bv = bernvazi(qc) 87 | bv.run() 88 | -------------------------------------------------------------------------------- /examples/qsim/depolarizing-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | import qsim.noisemodel as nmdl 5 | import numpy as np 6 | 7 | print('Adding noise channel to all gates') 8 | print() 9 | 10 | # with probabilty = 0.75, the bell-state gets completely depolarized (TODO source of this info?) 11 | # i.e., becomes 1/4*I 12 | noise_allgates = nmdl.qNoiseChannelSequence( 13 | nmdl.depolarizing(probability=0.75), 14 | ) 15 | noise_model = { 16 | 'noise_chan_allgates': noise_allgates, 17 | } 18 | q = qsim.DMQSimulator(2, noise_profile=noise_model, qtrace=True, verbose=False) 19 | 20 | q.qgate(qsim.H(),[0]) 21 | _,state,_ = q.qsnapshot() 22 | print('Full state dump:') 23 | print(state) 24 | print(f'State trace {np.trace(state):.4f}') 25 | print() 26 | 27 | q.qgate(qsim.C(),[0,1]) 28 | _,state,_ = q.qsnapshot() 29 | print('Full state dump:') 30 | print(state) 31 | print(f'State trace {np.trace(state):.4f}') 32 | print() 33 | 34 | I = ['Identity',np.matrix([[1.0,0.0],[0.0,1.0]],dtype=complex)] 35 | q.qgate(I,[0]) 36 | _,state,_ = q.qsnapshot() 37 | print('Full state dump:') 38 | print(state) 39 | print(f'State trace {np.trace(state):.4f}') 40 | print() 41 | -------------------------------------------------------------------------------- /examples/qsim/deutsch-jozsa.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import random as rnd 4 | import numpy as np 5 | import qsim 6 | 7 | print(""" 8 | ------------------------------------------------------------------------------------------------------- 9 | Problem Statement: 10 | Given a function whose output is CONSTANT (fixed output in the result 11 | register) or BALANCED (result register is equally 0 and 1 across all 12 | possible input values. Problem is to find which fx it is. 13 | 14 | This program randomly selects one of the two fx's and the algorithm 15 | determines which one it is. 16 | ------------------------------------------------------------------------------------------------------- 17 | """) 18 | 19 | nqbits = 8 20 | 21 | def fx(q): 22 | toss = int(rnd.random()*2.0) 23 | if toss == 0: 24 | print("fx is CONSTANT.") 25 | elif toss == 1: 26 | print("fx is BALANCED.") 27 | q.qgate(qsim.C(),[1,0]) 28 | 29 | try: 30 | q = qsim.QSimulator(nqbits) 31 | q.qgate(qsim.X(),[0]) 32 | q.qgate(qsim.H(),[0]) 33 | 34 | for i in range(nqbits-1): 35 | q.qgate(qsim.H(),[i+1]) 36 | 37 | fx(q) 38 | # q.qmeasure([0]) # measure it if you like, does not change anything 39 | 40 | for i in range(nqbits-1): 41 | q.qgate(qsim.H(),[i+1]) 42 | 43 | v = q.qmeasure(list(range(nqbits-1,0,-1)),qtrace=False) 44 | if 1 in v: 45 | print("Found fx is BALANCED") 46 | else: 47 | print("Found fx is CONSTANT") 48 | 49 | except qsim.QSimError as ex: 50 | print(ex.args) 51 | -------------------------------------------------------------------------------- /examples/qsim/fourier.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | print(""" 4 | ------------------------------------------------------------------------------------------------------- 5 | Problem Statement: 6 | Setup an initial prepared state and compute the fourier transform on it. 7 | ------------------------------------------------------------------------------------------------------- 8 | """) 9 | 10 | import qsim 11 | import numpy as np 12 | 13 | nqbits = 8 14 | 15 | try: 16 | # setup an initial state to try out QFT 17 | initstate = [None]*(2**nqbits) 18 | p = 0 19 | stsz = 2**nqbits 20 | for i in range(stsz): 21 | if (i % (stsz/8)) == 0: 22 | initstate[i] = 1 23 | else: 24 | initstate[i] = 0 25 | p += np.absolute(initstate[i])**2 26 | initstate = np.transpose(np.matrix(initstate,dtype=complex))/np.sqrt(p) 27 | 28 | # Start the Quantum Computer Simulator 29 | q = qsim.QSimulator(nqbits,initstate=initstate, qtrace=True) 30 | 31 | # Perform QFT 32 | qftgate = qsim.QFT(nqbits) 33 | q.qgate(qftgate, list(reversed(range(nqbits)))) 34 | 35 | except qsim.QSimError as ex: 36 | print(ex.args) 37 | -------------------------------------------------------------------------------- /examples/qsim/grover-noisey.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | import qsim 5 | import qsim.noisemodel as nmdl 6 | 7 | 8 | def intro(): 9 | print("""Grover's Algorithm. 10 | 11 | Problem Statement: 12 | Well known search algorithm by Lov Grover. 13 | 14 | +----+ +------+ +----+ +------+ +----+ 15 | n-1 |0> --| |-----| |-----| |----| |----| |--- ... --(/) 16 | n-2 |0> --| |-----| |-----| |----| |----| |--- ... --(/) 17 | n-3 |0> --| Hn |-----| Uf |-----| Hn |----| UinvM|----| Hn |--- ... --(/) 18 | ... ... ... ... ... 19 | 2 |0> --| |-----| |-----| |----| |----| |--- ... --(/) 20 | 1 |0> --| |-----| |-----| |----| |----| |--- ... --(/) 21 | +----+ | | +----+ | | +----+ 22 | 0 |-> -------------| |---------------| |------------- 23 | +------+ +------+ 24 | 25 | \-Init-/ \------------------Iterate-------------------/ \-Measure-/ 26 | """) 27 | 28 | ################################################################################# 29 | # Details @ https://en.wikipedia.org/wiki/Grover%27s_algorithm 30 | 31 | # Functions to build Grover's algo gates- Phase-flip and Invert-around-mean 32 | def Uf(q): 33 | n = q.qsize() 34 | key = 0b11011010 & (2**(n-1) - 1) 35 | fmt = "{:0"+str(n-1)+"b}" 36 | print("Uf(): Setup to search key =",fmt.format(key)) 37 | return __u(q,key,"Uf") 38 | 39 | def UinvM(q): 40 | ''' 41 | Used for inverse around Mean 42 | ''' 43 | key = 0 44 | return __u(q,key,"UinvM") 45 | 46 | def __u(q,key,name): 47 | n = q.qsize() 48 | # 'needle' in the haytack = key 49 | op_list = [] 50 | for i in range(n-1,0,-1): 51 | if (key & (0b1<<(i-1))) == 0: 52 | op_list.append(qsim.X()) 53 | else: 54 | op_list.append(["I",np.matrix(np.eye(2),dtype=complex)]) 55 | op_list.append(["I",np.matrix(np.eye(2),dtype=complex)]) 56 | uprep = qsim.qcombine_par("U-Prep",op_list) 57 | 58 | uflip = qsim.X() 59 | for i in range(n-1,0,-1): 60 | uflip = qsim.CTL(uflip) 61 | 62 | return qsim.qcombine_seq(name,[uprep,uflip,uprep]) 63 | 64 | ################################################################################# 65 | 66 | def main(n): 67 | intro() 68 | 69 | # bit flip probality of around 0.002 is about the max that this circuit can tolerate 70 | noise_ops = nmdl.bit_flip(probability=0.0025) 71 | noise_all_gates = nmdl.qNoiseChannelSequence(noise_ops) 72 | noise_model = { 73 | 'noise_chan_allgates': noise_all_gates 74 | } 75 | 76 | q = qsim.DMQSimulator(n) 77 | 78 | print("Building Uf operator ...") 79 | Ufgate = Uf(q) 80 | print("Buiding UinvM operator ...") 81 | UinvMgate = UinvM(q) 82 | 83 | print("Take from the following, best of 5 results...") 84 | for m in range(5): # Look for best of 5 85 | q = qsim.DMQSimulator(n, noise_profile=noise_model, qtrace=False) 86 | # Hn on x-register 87 | q.qgate(qsim.Hn(n-1), list(range(n-1,0,-1))) 88 | # prepare b as |-> 89 | q.qgate(qsim.X(),[0]) 90 | q.qgate(qsim.H(),[0]) 91 | 92 | numitrs = int(q.pi * (2.0**((n-1.0)/2.0))/4.0) # optimal # iter, less or more dont work 93 | for itr in range(numitrs): 94 | q.qgate(Ufgate,list(reversed(range(n)))) 95 | q.qgate(qsim.Hn(n-1), list(range(n-1,0,-1))) 96 | q.qgate(UinvMgate,list(reversed(range(n)))) 97 | q.qgate(qsim.Hn(n-1), list(range(n-1,0,-1))) 98 | res = q.qmeasure(list(range(n-1,0,-1))) 99 | print("Result",m,"=",res) 100 | 101 | if __name__ == "__main__": 102 | main(8) 103 | -------------------------------------------------------------------------------- /examples/qsim/grover.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | import qsim 5 | 6 | 7 | def intro(): 8 | print("""Grover's Algorithm. 9 | 10 | Problem Statement: 11 | Well known search algorithm by Lov Grover. 12 | 13 | +----+ +------+ +----+ +------+ +----+ 14 | n-1 |0> --| |-----| |-----| |----| |----| |--- ... --(/) 15 | n-2 |0> --| |-----| |-----| |----| |----| |--- ... --(/) 16 | n-3 |0> --| Hn |-----| Uf |-----| Hn |----| UinvM|----| Hn |--- ... --(/) 17 | ... ... ... ... ... 18 | 2 |0> --| |-----| |-----| |----| |----| |--- ... --(/) 19 | 1 |0> --| |-----| |-----| |----| |----| |--- ... --(/) 20 | +----+ | | +----+ | | +----+ 21 | 0 |-> -------------| |---------------| |------------- 22 | +------+ +------+ 23 | 24 | \-Init-/ \------------------Iterate-------------------/ \-Measure-/ 25 | """) 26 | 27 | ################################################################################# 28 | # Details @ https://en.wikipedia.org/wiki/Grover%27s_algorithm 29 | 30 | # Functions to build Grover's algo gates- Phase-flip and Invert-around-mean 31 | def Uf(q): 32 | n = q.qsize() 33 | key = 0b11011010 & (2**(n-1) - 1) 34 | fmt = "{:0"+str(n-1)+"b}" 35 | print("Uf(): Setup to search key =",fmt.format(key)) 36 | return __u(q,key,"Uf") 37 | 38 | def UinvM(q): 39 | ''' 40 | Used for inverse around Mean 41 | ''' 42 | key = 0 43 | return __u(q,key,"UinvM") 44 | 45 | def __u(q,key,name): 46 | n = q.qsize() 47 | # 'needle' in the haytack = key 48 | op_list = [] 49 | for i in range(n-1,0,-1): 50 | if (key & (0b1<<(i-1))) == 0: 51 | op_list.append(qsim.X()) 52 | else: 53 | op_list.append(["I",np.matrix(np.eye(2),dtype=complex)]) 54 | op_list.append(["I",np.matrix(np.eye(2),dtype=complex)]) 55 | uprep = qsim.qcombine_par("U-Prep",op_list) 56 | 57 | uflip = qsim.X() 58 | for i in range(n-1,0,-1): 59 | uflip = qsim.CTL(uflip) 60 | 61 | return qsim.qcombine_seq(name,[uprep,uflip,uprep]) 62 | 63 | ################################################################################# 64 | 65 | def main(n): 66 | intro() 67 | 68 | q = qsim.QSimulator(n) 69 | 70 | print("Building Uf operator ...") 71 | Ufgate = Uf(q) 72 | print("Buiding UinvM operator ...") 73 | UinvMgate = UinvM(q) 74 | 75 | print("Take from the following, best of 5 results...") 76 | for m in range(5): # Look for best of 5 77 | q = qsim.QSimulator(n) 78 | # Hn on x-register 79 | q.qgate(qsim.Hn(n-1), list(range(n-1,0,-1))) 80 | # prepare b as |-> 81 | q.qgate(qsim.X(),[0]) 82 | q.qgate(qsim.H(),[0]) 83 | 84 | numitrs = int(q.pi * (2.0**((n-1.0)/2.0))/4.0) # optimal # iter, less or more dont work 85 | for itr in range(numitrs): 86 | q.qgate(Ufgate,list(reversed(range(n)))) 87 | q.qgate(qsim.Hn(n-1), list(range(n-1,0,-1))) 88 | q.qgate(UinvMgate,list(reversed(range(n)))) 89 | q.qgate(qsim.Hn(n-1), list(range(n-1,0,-1))) 90 | res = q.qmeasure(list(range(n-1,0,-1))) 91 | print("Result",m,"=",res) 92 | 93 | if __name__ == "__main__": 94 | main(8) 95 | -------------------------------------------------------------------------------- /examples/qsim/period-finding.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | import math 5 | 6 | # Initialize the Quantum Computer 7 | nqbits = 8 # per the definition of f(x) below, must be >= 4 8 | q = qsim.QSimulator(nqbits) 9 | 10 | M = 2**(nqbits-2) 11 | 12 | # setup the periodic function 13 | op1 = q.qstretch(qsim.C(),[2,0]) 14 | op2 = q.qstretch(qsim.C(),[3,1]) 15 | f = qsim.qcombine_seq("F(x)",[op1,op2]) 16 | print("Psst ... f(x) defined as having period of 4\n") 17 | 18 | # Now loop to repeatedly find values of multiples of M/r by 19 | # running the QC repeatedly and reading the outputs 20 | idx = 0 21 | vals = [0,0] 22 | while idx < 2: 23 | # Get a fresh QC machine 24 | q = qsim.QSimulator(nqbits) 25 | 26 | # QFT(x) - F(x) - QFT(x) - Measure 27 | q.qgate(qsim.QFT(nqbits-2),list(range(nqbits-1,1,-1))) 28 | q.qgate(f,list(reversed(range(nqbits)))) 29 | # measure this if you like - q.qmeasure([1,0]) 30 | q.qgate(qsim.QFT(nqbits-2),list(range(nqbits-1,1,-1))) 31 | mbyrarr = q.qmeasure(list(range(nqbits-1,1,-1))) 32 | 33 | # convert to integer the measured values of the x register 34 | mbyr = 0 35 | for i in range(nqbits-2): 36 | sign = nqbits-2-1-i 37 | if mbyrarr[i] == 1: 38 | mbyr += 2**sign 39 | 40 | # Look for two distinc non-zero values 41 | print("a multiple of M/r = ",mbyr) 42 | if mbyr != 0: 43 | vals[idx] = mbyr 44 | if (vals[0] != vals[1]): 45 | idx += 1 46 | 47 | # find the GCD of the two values read to get M/r, and compute r, as M is known 48 | mbyr = int(math.gcd(int(vals[0]), int(vals[1]))) 49 | print("GCD of values of M/r = {:d}\n".format(mbyr)) 50 | print("But, M =", M) 51 | r = int(M / mbyr) 52 | print("Therefore, the period, r = ",r) 53 | -------------------------------------------------------------------------------- /examples/qsim/simple-search.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import random as rnd 4 | import numpy as np 5 | import qsim 6 | 7 | 8 | def fx(q): 9 | toss = int(rnd.random()*4.0) 10 | print("Selected fx is {:02b}".format(toss)) 11 | if toss == 0: 12 | q.qgate(qsim.X(),[2]) 13 | q.qgate(qsim.X(),[1]) 14 | q.qgate(qsim.T(),[2,1,0]) 15 | q.qgate(qsim.X(),[1]) 16 | q.qgate(qsim.X(),[2]) 17 | elif toss == 1: 18 | q.qgate(qsim.X(),[2]) 19 | q.qgate(qsim.T(),[2,1,0]) 20 | q.qgate(qsim.X(),[2]) 21 | elif toss == 2: 22 | q.qgate(qsim.X(),[1]) 23 | q.qgate(qsim.T(),[2,1,0]) 24 | q.qgate(qsim.X(),[1]) 25 | elif toss == 3: 26 | q.qgate(qsim.T(),[2,1,0]) 27 | 28 | def U(): 29 | return ["U",np.matrix([ 30 | [-0.5,0.5,0.5,0.5], 31 | [0.5,-0.5,0.5,0.5], 32 | [0.5,0.5,-0.5,0.5], 33 | [0.5,0.5,0.5,-0.5]],dtype=complex)] 34 | 35 | print("-------------------------------------------------------------------------------------------------------") 36 | print("Problem Statement:") 37 | print(" Given a function which outputs 1 either on inputs of 00 (fx=00), 01 (fx=01), 10 (fx=10) or 11 (fx=11)") 38 | print(" Problem is to find which fx it is.") 39 | print() 40 | print("This program randomly selects one of the four fx's and the algorithm determines which one it is.") 41 | print("-------------------------------------------------------------------------------------------------------") 42 | print() 43 | 44 | q = qsim.QSimulator(3) 45 | q.qgate(qsim.X(),[0]) 46 | q.qgate(qsim.H(),[0]) 47 | q.qgate(qsim.H(),[2]) 48 | q.qgate(qsim.H(),[1]) 49 | fx(q) 50 | # q.qmeasure([0]) 51 | q.qgate(U(),[2,1]) 52 | v = q.qmeasure([2,1]) 53 | print("Found fx = {:d}{:d}".format(v[0],v[1])) 54 | -------------------------------------------------------------------------------- /examples/qsim/teleportation-manyworlds.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | import numpy as np 5 | import random as rnd 6 | 7 | ''' 8 | This example shows an implementation of the teleportation protocol 9 | with qubits 5 and 4 representing the state of the worlds. 10 | Qubit 5 represents 'what I observed qubit 1 to be' and qubit 4 11 | represents 'what I observed qubit 2 to be'. 12 | So, Qubits 5 and 4 identify the 4 possible branches in the many-worlds. 13 | ''' 14 | 15 | ''' 16 | This implementation follows slightly different version of the algorithm 17 | than the other telepotation example in this folder. 18 | ''' 19 | 20 | NQUBITS=6 21 | # Note: qubit 3 is not used, it is just a 'space' between the 22 | # qubits involved in the algorithm and the bits identifying 23 | # the worlds. 24 | 25 | # Prepare a qubit in some random state 26 | theta = rnd.random() * 2 * np.pi 27 | c = np.cos(theta) 28 | s = np.sin(theta) 29 | # prepare the initial state with the above qubit as qbit-2 30 | tbit = np.transpose(np.matrix([[c,s]],dtype=complex)) 31 | initstate = np.transpose(np.matrix([[1,0]],dtype=complex)) 32 | for i in range(NQUBITS-1): 33 | if i == 2: 34 | initstate = np.kron(initstate,tbit) 35 | else: 36 | initstate = np.kron(initstate,np.transpose(np.matrix([[1,0]],dtype=complex))) 37 | 38 | # now get started ... 39 | q = qsim.QSimulator(NQUBITS,initstate=initstate) 40 | q.qreport(header="Initial State") 41 | 42 | # first put qbits 0 and 1 in bell state 43 | q.qgate(qsim.H(),[0]) 44 | q.qgate(qsim.C(),[0,1]) 45 | q.qreport(header="0 and 1 in bell state") 46 | # qbit 1 is kept 'here' and qbit 0 is sent 'far away'; and we have 47 | # the input qbit to be teleported, qbit 2, also 'here'. 48 | 49 | # at 'here' we CNOT qbit 2 (control qubit) and qbit 1 50 | q.qgate(qsim.C(), [2,1]) 51 | # at 'here' perform H on qubit 2 (the qubit to be teleported) 52 | q.qgate(qsim.H(),[2]) 53 | q.qreport(header="C(2,1), H(2)") 54 | 55 | # Now "measure" qubits 1 and 2 56 | # OK, we do this measurement as if we are combination of qubits 5 and 4. 57 | # So, qubit 5 measures (gets entangled with) qubits 1 and represents 58 | # the state 'what I observed 1 as' and then qubit 4 entangles with 59 | # qubit 2 and represents the state 'what I observed 2 as'. 60 | # The worlds splits into 4 branches as following -- 61 | # == 62 | # / 63 | # == m(2) 64 | # / \ 65 | # / == 66 | # === m(1) 67 | # \ == 68 | # \ / 69 | # == m(2) 70 | # \ 71 | # == 72 | q.qgate(qsim.C(), [1,5]) 73 | q.qgate(qsim.C(), [2,4]) 74 | q.qreport(header="q5 measured q1, and q4 measured q2") 75 | 76 | # OK, now we pick any one branch of the 4 branched worlds we 77 | # concurrently live in. We do that by a trick in the simulator - 78 | # we perform a measurement on the observer qubits 5 and 4. 79 | q.qmeasure([5,4]) 80 | q.qreport(header="Picking one branch of the many-worlds") 81 | 82 | # Now we continue with the algorith. We measure the qubits 2 1nd 1 83 | # and pass that classical information to 'far away' location where 84 | # qubit 0 resides. And based on that classical information we 85 | # conditionally apply X and Z gates to complete the teleportation. 86 | mvals = q.qmeasure([2,1]) 87 | mq2 = mvals[0] 88 | mq1 = mvals[1] 89 | if mq1 == 1: 90 | q.qgate(qsim.X(), [0]) 91 | if mq2 == 1: 92 | q.qgate(qsim.Z(), [0]) 93 | 94 | q.qreport(header="Final state") 95 | 96 | -------------------------------------------------------------------------------- /examples/qsim/teleportation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | import numpy as np 5 | 6 | q = qsim.QSimulator(3) 7 | 8 | # put the qubit 2 in some randoom state 9 | # this is the qubit that is to be teleported by Alice to Bob 10 | print("\nThe qubit 2 is put in some random state, it will be teleported into qubit 0.") 11 | q.qgate(qsim.RND(),[2], qtrace=True) 12 | 13 | # get qubits 0 and 1 in the triplet state, |00> + |11> 14 | # Alice and Bob have one of each of these entangled qubits 15 | q.qgate(qsim.H(),[0]) 16 | q.qgate(qsim.C(),[0,1]) 17 | 18 | print( ''' 19 | cbit2 ============m=======.== 20 | | | 21 | cbit1 ========m===|===.===|== 22 | | | | | 23 | qubit2 -.-[H]-(/)--|---|---|-- 24 | | | | | 25 | qubit1 -o---------(/)--|---|-- 26 | | | 27 | qubit0 ---------------[X]-[Z]-- qubit 2 teleported into qubit 0 28 | 29 | ''') 30 | 31 | print("Starting the teleportation protocol...") 32 | q.qgate(qsim.C(),[2,1]) 33 | q.qgate(qsim.H(),[2]) 34 | q.qmeasure([1]) 35 | q.qmeasure([2]) 36 | 37 | q.qgate(qsim.X(),[0], ifcbit=(1,1)) 38 | q.qgate(qsim.Z(),[0], ifcbit=(2,1)) 39 | 40 | q.qreport() 41 | print("qubit 2 teleported into qubit 0.") 42 | -------------------------------------------------------------------------------- /pip-local-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | select=${1:-all} 4 | 5 | if [ $select == "all" ] || [ $select == "qusimulator" ]; then 6 | pushd qusimulator 7 | pip install -e . 8 | rm -r build 9 | # rm -r qusimulator.egg-info 10 | rm -r __pycache__ 11 | popd 12 | echo '-----------------------------------------------------' 13 | fi 14 | 15 | if [ $select == "all" ] || [ $select == "qucircuit" ]; then 16 | pushd qucircuit 17 | pip install -e . 18 | rm -r build 19 | # rm -r qucircuit.egg-info 20 | rm -r __pycache__ 21 | popd 22 | echo '-----------------------------------------------------' 23 | fi 24 | -------------------------------------------------------------------------------- /qucircuit/RELEASE-splash.md: -------------------------------------------------------------------------------- 1 | # Qucircuit – A quantum computing circuits simulator 2 | ## Release 2.2 3 | 4 | `$ pip install qucircuit` 5 | 6 | Now full support for quantum noise simulation. 7 | Includes state-vector and density-matrix based simulator backends. 8 | 'Getting started' tutorial Jupyter notebooks, and documentation resources - 9 | * [Getting started tutorial Jupyter notebook](https://github.com/atulvarshneya/quantum-computing/tree/master/examples/qckt/Getting-started-tutorial.ipynb) 10 | * [Getting started with noise simulation tutorial Jupyter notebook](https://github.com/atulvarshneya/quantum-computing/tree/master/examples/qckt/Getting-started-tutorial-noise-sim.ipynb) 11 | * [Example implementations of various quantum algorithms](https://github.com/atulvarshneya/quantum-computing/tree/master/examples/qckt) 12 | * [Developer documentation](https://github.com/atulvarshneya/quantum-computing/blob/master/qucircuit/README.md) 13 | -------------------------------------------------------------------------------- /qucircuit/TODO.md: -------------------------------------------------------------------------------- 1 | Backends: 2 | * submit job 3 | * async/sync wait for job to complete 4 | -------------------------------------------------------------------------------- /qucircuit/qckt/Job.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | class Job: 4 | 'just a packet of all job attributes. Is a qckt concept, so is ' 5 | def __init__(self, circuit, qtrace=False, verbose=False, shots=1): 6 | 'Job is a qckt concept to encapsulate the work packet that is to be submitted to the quantum computer to execute' 7 | self.circuit = circuit 8 | self.nqubits, self.nclbits = circuit.get_size() 9 | self.assembledCkt = circuit.assemble() 10 | self.qtrace = qtrace 11 | self.verbose = verbose 12 | self.shots = shots 13 | # result will be populated after the job is run 14 | self.result = None 15 | self.runstats = None 16 | 17 | def get_svec(self): 18 | return self.result.state_vector 19 | 20 | def get_creg(self): 21 | return self.result.cregister 22 | 23 | def get_counts(self): 24 | counts = [0]*(2**self.nclbits) 25 | for r in self.result.cregister: 26 | counts[r.intvalue] += 1 27 | return counts 28 | 29 | def plot_counts(self,verbose=False): 30 | counts = self.get_counts() 31 | lc = len(counts) 32 | nbits = 0 33 | while 2**nbits < lc: nbits += 1 34 | if 'ipykernel' in sys.modules: 35 | lbl = [] 36 | vals = [] 37 | for i,c in enumerate(counts): 38 | if verbose or c > 0: 39 | binlbl = ('[{0:0'+str(nbits)+'b}]').format(i) 40 | lbl.append(str(i)+" "+binlbl) 41 | vals.append(c) 42 | import matplotlib.pyplot as plt 43 | plt.xticks(rotation='vertical') 44 | fig = plt.bar(lbl,vals) 45 | for i in range(len(vals)): 46 | plt.annotate(str(vals[i]), xy=(lbl[i],vals[i]), ha='center', va='bottom') 47 | plt.show() 48 | else: 49 | maxc = max(counts) 50 | cwid = len(str(maxc)) 51 | scale = 1 if maxc < 50 else 50.0/maxc 52 | for i,c in enumerate(counts): 53 | if verbose or c > 0: 54 | print(('{0:4d} [{0:0'+str(nbits)+'b}] {1:'+str(cwid)+'d} |').format(i,c),end="") 55 | for j in range(int(c * scale)): 56 | print("*",end="") 57 | print() 58 | return counts 59 | 60 | def get_runstats(self): 61 | return self.runstats 62 | 63 | def print_runstats(self): 64 | qsteps = self.runstats['QSteps'] 65 | op_counts = self.runstats['OpCounts'] 66 | op_times = self.runstats['OpTimes'] 67 | tot_time = 0.0 68 | for k,v in op_times.items(): 69 | tot_time = tot_time + v 70 | print(f'Total Ops : {qsteps:4d} operations') 71 | # print(f'Total Time : {tot_time:9.4f} sec') 72 | print(f'Per Operation:') 73 | for op in op_counts.keys(): 74 | # print(f' {op:8s} {op_times[op]:9.4f} sec {op_counts[op]:4d} times {op_times[op]/op_counts[op]:4.4f} avg') 75 | print(f' {op:8s} {op_counts[op]:4d} times') 76 | 77 | -------------------------------------------------------------------------------- /qucircuit/qckt/Registers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | from qckt.qException import QCktException 4 | 5 | class Register(list): 6 | def __init__(self,sz): 7 | super().__init__([None]*sz) 8 | self.placed = False 9 | def __getitem__(self,idx): 10 | if self.placed is False: 11 | raise QCktException("Attempt to access register qbit ids without placement") 12 | return super().__getitem__(idx) 13 | def placeMSB(self,loc): 14 | for q in range(len(self)): 15 | self[q] = loc - q 16 | self.placed = True 17 | return self 18 | class QRegister(Register): 19 | pass 20 | class CRegister(Register): 21 | pass 22 | 23 | def placement(*regs): 24 | qbitplaced = QRegister(0).placeMSB(0) # trick to mark the register 'placed' 25 | cbitplaced = CRegister(0).placeMSB(0) # trick to mark the register 'placed' 26 | qbitsz = 0 27 | cbitsz = 0 28 | for r in reversed(regs): 29 | if type(r) is QRegister: 30 | if r.placed: raise QCktException("Attempt to place already placed QRegister") 31 | qbitsz = qbitsz + len(r) if qbitsz is not None else len(r) 32 | r.placeMSB(qbitsz - 1) 33 | temp = QRegister(0).placeMSB(0) # trick to mark the register 'placed' 34 | for i in r: temp.append(i) 35 | temp.extend(qbitplaced) 36 | qbitplaced = temp 37 | elif type(r) is CRegister: 38 | if r.placed: raise QCktException("Attempt to place already placed CRegister") 39 | cbitsz = cbitsz + len(r) if cbitsz is not None else len(r) 40 | r.placeMSB(cbitsz - 1) 41 | temp = CRegister(0).placeMSB(0) # trick to mark the register 'placed' 42 | for i in r: temp.append(i) 43 | temp.extend(cbitplaced) 44 | cbitplaced = temp 45 | else: 46 | raise QCktException("placement not supported for type:"+type(r).__name__) 47 | return qbitsz,cbitsz,qbitplaced,cbitplaced 48 | -------------------------------------------------------------------------------- /qucircuit/qckt/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from qckt.QCkt import QCkt 3 | from qckt.Gates import define_gate, get_gates_list 4 | from qckt.Job import Job 5 | from qckt.qException import QCktException 6 | 7 | __version__ = '2.2' 8 | __author__ = 'Atul Varshneya' 9 | __author_email__ = 'atul.varshneya@gmail.com' 10 | __email__ = __author_email__ 11 | __url__ = 'https://github.com/atulvarshneya/quantum-computing' 12 | -------------------------------------------------------------------------------- /qucircuit/qckt/backend/BackendAPI.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | 5 | # ABSTRACT class for backend services 6 | class BackendSvc: 7 | 'the service implments the methods to connect with the quantum computing service, i.e., the required protocol, etc. - config registry will provide the specifics e.g., IP address' 8 | def __init__(self,connectionToken=None): 9 | 'connectionToken contains the credentials required to access the service; the type of this object is specific to the service' 10 | self.connnectionToken = connectionToken 11 | pass 12 | def listInstances(self): 13 | 'provides a list of tuples (name, description) of all instances (quamtum computer) available at this service' 14 | pass 15 | def getInstance(self, name): 16 | 'returns an object representation of the named instance(quantum computer)' 17 | pass 18 | 19 | class Cregister: 20 | 21 | def __init__(self): 22 | self.value = None 23 | self.intvalue = None 24 | 25 | def __str__(self): 26 | creg_str = "" 27 | for i in (range(len(self.value))): # creg[0] is MSB 28 | creg_str = creg_str + "{0:01b}".format(self.value[i]) 29 | # creg_str = creg_str + "\n" 30 | return creg_str 31 | 32 | def setvalue_vec(self,cbitsvec): 33 | intval = 0 34 | for i in range(len(cbitsvec)): 35 | intval = 2 * intval 36 | intval += cbitsvec[i] 37 | self.intvalue = intval 38 | self.value = cbitsvec 39 | 40 | 41 | class StateVector: 42 | 43 | def __init__(self): 44 | self.value = None 45 | self.verbosity = False 46 | 47 | def __str__(self): 48 | svec_str = "" 49 | dispvalue = self.value 50 | if len(dispvalue.shape) > 1: 51 | svec_str = "Density matrix DIAGONAL\n" 52 | dispvalue = np.diagonal(self.value) 53 | 54 | ### wonky way to find number of qubits 55 | nq = 0 56 | n = len(dispvalue) - 1 57 | while n > 0: 58 | nq = nq + 1 59 | n = n >> 1 60 | 61 | statefmt = "{0:"+"0{0:d}b".format(nq)+"}" 62 | s = 0 63 | for i in dispvalue: 64 | if self.verbosity or np.absolute(i) > 10**(-6): 65 | svec_str = svec_str + statefmt.format(s) + " " + "{:.8f}".format(i) + "\n" 66 | s += 1 67 | return svec_str 68 | 69 | def verbose(self,v): 70 | if v is True: 71 | self.verbosity = True 72 | else: 73 | self.verbosity = False 74 | return self 75 | 76 | class Result: 77 | def __init__(self,cregvals,svecvals=None): 78 | self.cregister = cregvals 79 | self.state_vector = svecvals 80 | 81 | -------------------------------------------------------------------------------- /qucircuit/qckt/backend/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from qckt.backend.svcReg import Registry 3 | from qckt.backend.QSystems import qsimSvc, Qeng, Qdeb, DMQeng, DMQdeb 4 | from qckt.backend.BackendAPI import Cregister, StateVector, Result 5 | 6 | -------------------------------------------------------------------------------- /qucircuit/qckt/backend/svcReg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import qckt.backend.QSystems as qsys 4 | from qckt.qException import QCktException 5 | 6 | 7 | class Registry: 8 | 'this is an API for accessing the registry of Quantum Computing Services (e.g., IBM quantum computing, Ionq quantum computing, local qsim simulator, local debugging simulator)' 9 | services = {"QSystems": (qsys.qsimSvc, "qsim simulator from Quantum Systems")} 10 | 11 | def __init__(self): 12 | pass 13 | def listSvc(self): 14 | 'returns a list of tuples (name, description) of all services available (i.e. registered in the configuration)' 15 | return [(k,Registry.services[k][1]) for k in Registry.services.keys()] 16 | def getSvc(self, svcName): 17 | if svcName in Registry.services.keys(): 18 | return Registry.services[svcName][0]() 19 | else: 20 | raise QCktException("No such registered service: "+str(svcName)) 21 | 22 | -------------------------------------------------------------------------------- /qucircuit/qckt/gatesutils/GatesUtils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import numpy as np 4 | import copy 5 | from qckt.qException import QCktException 6 | 7 | #################################################################################################### 8 | ## Utility functions ############################################################################### 9 | #################################################################################################### 10 | 11 | def _qbit_realign_full_list(nqbits, qbit_list): 12 | reord_list = copy.deepcopy(qbit_list) 13 | for i in reversed(range(nqbits)): # reversed to maintain significance order of the other qbits; poetic correctness :-) 14 | if i not in reord_list: 15 | reord_list.append(i) 16 | return reord_list 17 | 18 | def _shuffled_count(nqbits, bitorder): 19 | shuffled = [] 20 | for i in range(2**nqbits): 21 | shfval = 0 22 | for b in range(nqbits): 23 | dstbit = bitorder[nqbits-b-1] ## (nqbits-1) - b becasue bitorder is array like [MSB, ...,LSB] 24 | shfval += (((i >> b) & 0x1) << dstbit) 25 | shuffled.append(shfval) 26 | return shuffled 27 | 28 | def _rmat_invrmat(nqbits, qbit_reorder): ## why this name? rmat is matrix that reorders the state vector, invrmat is inverse of rmat 29 | # this is per counting with the given bit ordering 30 | shfl_svec_idxs = _shuffled_count(nqbits, qbit_reorder) 31 | ## create the rmat and invrmat 32 | imat = np.matrix(np.eye(2**nqbits)) 33 | rmat = np.matrix(np.eye(2**nqbits)) 34 | invrmat = np.matrix(np.eye(2**nqbits)) 35 | for i in range(2**nqbits): 36 | s = shfl_svec_idxs[i] 37 | rmat[i] = imat[s] 38 | invrmat[s] = imat[i] 39 | return (rmat, invrmat) 40 | 41 | def _aligned_op(nqbits, oper, qbit_list): 42 | qbit_reorder = _qbit_realign_full_list(nqbits, qbit_list) 43 | (rmat,invrmat) = _rmat_invrmat(nqbits, qbit_reorder) 44 | a_op = invrmat * oper * rmat 45 | return a_op 46 | 47 | 48 | def stretched_opmatrix(nqbits,oper,qbit_list): 49 | c_op = np.kron(oper,np.eye(2**(nqbits-len(qbit_list)))) 50 | a_op = _aligned_op(nqbits,c_op,qbit_list) 51 | return a_op 52 | 53 | def combine_opmatrices_par(op_list): 54 | res = None 55 | first = True 56 | for op in op_list: 57 | mat = op 58 | if first: 59 | res = op 60 | first = False 61 | else: 62 | res = np.kron(res,op) 63 | return res 64 | 65 | def combine_opmatrices_seq(op_list): 66 | d = (op_list[0]).shape[0] 67 | res = np.matrix(np.eye(d),dtype=complex) 68 | for op in op_list: 69 | r = op.shape[0] 70 | c = op.shape[1] 71 | if r != c: 72 | errmsg = "Operation is not a square matrix." 73 | raise QCktException(errmsg) 74 | if r != d: 75 | errmsg = "Operation matrices not the same size." 76 | raise QCktException(errmsg) 77 | res = op*res # remember order of multiplication is opposite of the visual order 78 | return res 79 | 80 | def isunitary(mat): 81 | floaterr = 10**(-8) 82 | if type(mat) is not np.matrix: 83 | return False 84 | (r,c) = mat.shape 85 | if r != c: 86 | return False 87 | invmat = np.conjugate(np.transpose(mat)) 88 | pmat = np.asarray(mat * invmat) 89 | for i in range(r): 90 | for j in range(c): 91 | if i != j: 92 | if np.absolute(pmat[i][j]) > floaterr: 93 | return False 94 | else: 95 | if np.absolute(pmat[i][j]-1.0) > floaterr: 96 | return False 97 | return True 98 | 99 | def opmat_dagger(opMat): 100 | mat = opMat[:] 101 | invmat = np.conjugate(np.transpose(mat)) 102 | return invmat 103 | 104 | ## Utility function to add control bit 105 | def CTL(opMatrix): 106 | (r,c) = opMatrix.shape 107 | oparr = np.array(opMatrix) 108 | coparr = np.eye(r*2,dtype=complex) 109 | for i in range(r,r*2): 110 | for j in range(r,r*2): 111 | coparr[i][j] = oparr[i-r][j-r] 112 | return np.matrix(coparr,dtype=complex) 113 | 114 | -------------------------------------------------------------------------------- /qucircuit/qckt/gatesutils/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from qckt.gatesutils.GatesUtils import stretched_opmatrix, combine_opmatrices_par, combine_opmatrices_seq, isunitary, opmat_dagger, CTL 3 | 4 | -------------------------------------------------------------------------------- /qucircuit/qckt/noisemodel/__init__.py: -------------------------------------------------------------------------------- 1 | from .noiseUtils import NoiseChannel, \ 2 | NoiseChannelSequence, \ 3 | NoiseChannelApplierSequense, \ 4 | NoiseProfile, \ 5 | consolidate_gate_noise 6 | 7 | from .noiseChannels import bit_flip, \ 8 | phase_flip, \ 9 | depolarizing, \ 10 | amplitude_damping, \ 11 | phase_damping, \ 12 | pauli_channel, \ 13 | generalized_amplitude_damping, \ 14 | dummy_2qubit_chan, \ 15 | two_qubit_dephasing, \ 16 | two_qubit_depolarizing, \ 17 | noise_channel_list, \ 18 | noise_channel_lookup 19 | -------------------------------------------------------------------------------- /qucircuit/qckt/qException.py: -------------------------------------------------------------------------------- 1 | 2 | class QCktException(Exception): 3 | def __init__(self,msg): 4 | self.args = msg 5 | self.msg = msg 6 | 7 | def __str__(self): 8 | return self.msg 9 | -------------------------------------------------------------------------------- /qucircuit/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description_file=README.md 3 | license_files=LICENSE 4 | -------------------------------------------------------------------------------- /qucircuit/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | with open('RELEASE-splash.md', 'r') as file: 4 | long_description = file.read() 5 | 6 | setup( 7 | name='qucircuit', 8 | version='2.2', 9 | license='GPL', 10 | author='Atul Varshneya', 11 | author_email='atul.varshneya@gmail.com', 12 | description='Quantum computer programming with circuits paradigm', 13 | long_description=long_description, 14 | long_description_content_type='text/markdown', 15 | packages=find_packages('.'), 16 | # package_dir={'': '.'}, 17 | keywords='qsystems quantum computing', 18 | url='https://github.com/atulvarshneya/quantum-computing', 19 | python_requires='>3.9', 20 | install_requires=[ 21 | 'numpy', 22 | 'matplotlib', 23 | 'qusimulator>=2.2' 24 | ] 25 | ) 26 | -------------------------------------------------------------------------------- /qusimulator/RELEASE-splash.md: -------------------------------------------------------------------------------- 1 | # Qusimulator – A quantum computing simulator 2 | ## Release 2.2 3 | 4 | `$ pip install qusimulator` 5 | 6 | Now full support for quantum noise simulation. 7 | Includes state-vector and density-matrix based simulators. 8 | Documentation and example code resources - 9 | * [Example implementations of various quantum algorithms](https://github.com/atulvarshneya/quantum-computing/tree/master/examples/qsim/) 10 | * [Developer documentation](https://github.com/atulvarshneya/quantum-computing/blob/master/qusimulator/README.md) 11 | -------------------------------------------------------------------------------- /qusimulator/qsim/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from qsim.qSimException import QSimError 3 | from qsim.Qsim import QSimulator 4 | from qsim.DMQsim import DMQSimulator 5 | from qsim.qgates import X, Y, Z, H, Rphi, Rk, SQSWAP, SWAP, CSWAP, QFT, Hn, RND, CTL, C, T, BELL_BASIS, HDM_BASIS 6 | from qsim.qgatesUtils import qcombine_seq, qcombine_par 7 | 8 | __version__ = '2.2' 9 | __author__ = 'Atul Varshneya' 10 | __author_email__ = 'atul.varshneya@gmail.com' 11 | __email__ = __author_email__ 12 | __url__ = 'https://github.com/atulvarshneya/quantum-computing' 13 | -------------------------------------------------------------------------------- /qusimulator/qsim/noisemodel/__init__.py: -------------------------------------------------------------------------------- 1 | from .noiseUtils import qNoiseChannel, \ 2 | qNoiseChannelSequence, \ 3 | qNoiseChannelApplierSequense, \ 4 | consolidate_gate_noise 5 | 6 | from .noiseChannels import bit_flip, \ 7 | phase_flip, \ 8 | depolarizing, \ 9 | amplitude_damping, \ 10 | phase_damping, \ 11 | pauli_channel, \ 12 | generalized_amplitude_damping, \ 13 | two_qubit_dephasing, \ 14 | two_qubit_depolarizing, \ 15 | noise_channel_list, \ 16 | noise_channel_lookup 17 | -------------------------------------------------------------------------------- /qusimulator/qsim/qSimException.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class QSimError(BaseException): 4 | def __init__(self,arg): 5 | self.args = arg 6 | self.msg = arg 7 | def __str__(self): 8 | return self.msg 9 | -------------------------------------------------------------------------------- /qusimulator/qsim/qgates.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | from qsim.qSimException import * 4 | import random as rnd 5 | import qsim.qgatesUtils as qgu 6 | 7 | ## QC Gates 8 | def X(): 9 | """ 10 | Pauli_X gate. 11 | """ 12 | return ["X", np.matrix([[0,1],[1,0]],dtype=complex)] 13 | 14 | def Y(): 15 | """ 16 | Pauli_Y gate. 17 | """ 18 | return ["Y", np.matrix([[0,complex(0,-1)],[complex(0,1),0]],dtype=complex)] 19 | 20 | def Z(): 21 | """ 22 | Pauli_Z gate. 23 | """ 24 | return ["Z", np.matrix([[1,0],[0,-1]],dtype=complex)] 25 | 26 | def H(): 27 | """ 28 | Hadamard gate. 29 | """ 30 | sqr2 = np.sqrt(2) 31 | return ["HADAMARD", np.matrix([[1/sqr2,1/sqr2],[1/sqr2,-1/sqr2]],dtype=complex)] 32 | 33 | def Rphi(phi): 34 | """ 35 | Phase rotation gate. Takes the Phi as an argument. 36 | """ 37 | cphi = np.cos(phi) 38 | sphi = np.sin(phi) 39 | return ["ROTphi({:0.4f})".format(phi), np.matrix([[1,0],[0,complex(cphi,sphi)]],dtype=complex)] 40 | 41 | def Rk(k): 42 | """ 43 | Phase rotation gate. Takes the k as an argument to divide 2*pi by 2**k. 44 | """ 45 | ck = np.cos(2*np.pi/(2**k)) 46 | sk = np.sin(2*np.pi/(2**k)) 47 | return ["ROTk({:d})".format(k), np.matrix([ 48 | [1,0], 49 | [0,complex(ck,sk)]],dtype=complex)] 50 | 51 | def SQSWAP(): 52 | """ 53 | Square-root of Swap gate. 54 | """ 55 | return ["SQSWAP", np.matrix([[1,0,0,0],[0,0.5+0.5j,0.5-0.5j,0],[0,0.5-0.5j,0.5+0.5j,0],[0,0,0,1]],dtype=complex)] 56 | 57 | def SWAP(): 58 | """ 59 | Swap gate. 60 | """ 61 | return ["SWAP", np.matrix([[1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]],dtype=complex)] 62 | 63 | def CSWAP(): 64 | """ 65 | CSWAP gate 66 | """ 67 | return CTL(SWAP()) 68 | 69 | def QFT(nqbits): 70 | N = 2**nqbits # number of rows and cols 71 | theta = 2.0 * np.pi / N 72 | opmat = [None]*N 73 | for i in range(N): 74 | # print "row",i,"--------------------" 75 | row = [] 76 | for j in range(N): 77 | pow = i * j 78 | pow = pow % N 79 | # print "w^",pow 80 | row.append(np.e**(1.j*theta*pow)) 81 | opmat[i] = row 82 | # print opmat 83 | opmat = np.matrix(opmat,dtype=complex) / np.sqrt(N) 84 | oper = ["QFT({:d})".format(nqbits),opmat] 85 | return oper 86 | 87 | def Hn(n): 88 | """ 89 | H^n gate - very commonly used 90 | """ 91 | op_list = [] 92 | for i in range(n): 93 | op_list.append(H()) 94 | return qgu.qcombine_par("H**{:d}".format(n),op_list) 95 | 96 | def RND(): 97 | """ 98 | Random apmplitude gate. 99 | """ 100 | phi = rnd.random() * np.pi * 2 101 | camp = np.cos(phi) 102 | samp = np.sin(phi) 103 | phi = rnd.random() * np.pi * 2 104 | re1 = camp*np.cos(phi) 105 | im1 = camp*np.sin(phi) 106 | re2 = samp*np.cos(phi) 107 | im2 = samp*np.sin(phi) 108 | return ["RND", np.matrix([[complex(-re1,-im1),complex(re2,im2)],[complex(re2,im2),complex(re1,im1)]],dtype=complex)] 109 | 110 | def CTL(op,name=None): 111 | """ 112 | Add Control to any gate 113 | """ 114 | opname = op[0] 115 | opmat = op[1] 116 | (r,c) = opmat.shape 117 | oparr = np.array(opmat) 118 | coparr = np.eye(r*2,dtype=complex) 119 | for i in range(r,r*2): 120 | for j in range(r,r*2): 121 | coparr[i][j] = oparr[i-r][j-r] 122 | if name is None: 123 | name = "C"+opname 124 | return [name, np.matrix(coparr,dtype=complex)] 125 | 126 | def C(): 127 | """ 128 | CNOT gate 129 | """ 130 | return CTL(X(),name="CNOT") 131 | 132 | def T(): 133 | """ 134 | TOFFOLI gate. 135 | """ 136 | return CTL(CTL(X()),name="TOFFOLI") 137 | 138 | # Basis Matrices 139 | def BELL_BASIS(): 140 | return ["BELL_BASIS",np.matrix([[1,0,0,1],[1,0,0,-1],[0,1,1,0],[0,1,-1,0]], dtype=complex)/np.sqrt(2)] 141 | 142 | def HDM_BASIS(): 143 | sq2 = np.sqrt(2) 144 | return ["HDM_BASIS",np.matrix([[1,1],[1,-1]], dtype=complex)/np.sqrt(2)] 145 | 146 | -------------------------------------------------------------------------------- /qusimulator/qsim/qgatesUtils.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import qsim 4 | 5 | ## qcombine_seq(name,op_list): 6 | ## 7 | ## Just multiply the operation matrices 8 | def qcombine_seq(name,op_list): 9 | d = ((op_list[0])[1]).shape[0] 10 | res = np.matrix(np.eye(d),dtype=complex) 11 | for opdef in op_list: 12 | op = opdef[1] 13 | r = op.shape[0] 14 | c = op.shape[1] 15 | if r != c: 16 | errmsg = "Operation is not a square matrix." 17 | raise qsim.QSimError(errmsg) 18 | if r != d: 19 | errmsg = "Operation matrices not the same size." 20 | raise qsim.QSimError(errmsg) 21 | res = op*res # remember order of multiplication is opposite of the visual order 22 | return [name,res] 23 | 24 | 25 | ## qcombine_par(name,op_list): 26 | ## 27 | ## Qubits |x> and |y>, each is acted upon by 2x2 operators U1 and U2, respectively. 28 | ## This is equivalent to the combined state of x and y, i.e., |xy> acted upon 29 | ## by a single 4x4 operator U = np.kron(U1, U2) (see Umesh Vazirani course 30 | ## on edx.org - Week 3: Quantum Circuits and Teleportation 31 | ## Lecture 5: Quantum Gates Video: Two Qubit Gates and Tensor Products 32 | ## https://www.youtube.com/watch?v=ISJYwzN-W20 ) 33 | ## 34 | ## +-------+ 35 | ## | | 36 | ## | +---+ | 37 | ## | | | | 38 | ## |x> -------+-|U1 |-+-------- U1|x> +-----+ 39 | ## | |2x2| | | | 40 | ## | +---+ | | | 41 | ## | | |xy> --------+ U +------- U|xy> 42 | ## | | | | 43 | ## | +---+ | | 4x4 | 44 | ## | | | | +-----+ 45 | ## |y> -------+-|U1 |-+-------- U2|y> 46 | ## | |2x2| | 47 | ## | +---+ | 48 | ## | | 49 | ## +-------+ 50 | 51 | def qcombine_par(name,op_list): 52 | res = None 53 | first = True 54 | for op in op_list: 55 | mat = op[1] 56 | if first: 57 | res = mat 58 | first = False 59 | else: 60 | res = np.kron(res,mat) 61 | return [name,res] 62 | -------------------------------------------------------------------------------- /qusimulator/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description_file=README.md 3 | license_files=LICENSE 4 | -------------------------------------------------------------------------------- /qusimulator/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | with open('RELEASE-splash.md', 'r') as file: 4 | long_description = file.read() 5 | 6 | setup( 7 | name='qusimulator', 8 | version='2.2', 9 | license='GPL', 10 | author='Atul Varshneya', 11 | author_email='atul.varshneya@gmail.com', 12 | description='Quantum computer simulator', 13 | long_description=long_description, 14 | long_description_content_type='text/markdown', 15 | packages=find_packages('.'), 16 | # package_dir={'': '.'}, 17 | keywords='qsystems quantum computing', 18 | url='https://github.com/atulvarshneya/quantum-computing', 19 | python_requires='>3.9', 20 | install_requires=[ 21 | 'numpy' 22 | ], 23 | entry_points = { 24 | 'console_scripts': ['qsimcli=qsim.qcli:main'], 25 | } 26 | ) 27 | -------------------------------------------------------------------------------- /tests/qckt/CTRL-tests-dm.py: -------------------------------------------------------------------------------- 1 | import qckt 2 | from qckt.backend import * 3 | import numpy as np 4 | 5 | 6 | # CX 7 | print("CX ---------------------------------------") 8 | ck = qckt.QCkt(8) 9 | ck.CX(2,1,0) 10 | ck.X([4,5,6]) 11 | ck.CX(6,5,4,3) 12 | ck.list() 13 | ck.draw() 14 | job = qckt.Job(ck, qtrace=True) 15 | DMQdeb().runjob(job) 16 | 17 | # CY 18 | print("CY ---------------------------------------") 19 | ck = qckt.QCkt(8) 20 | ck.CY(2,1,0) 21 | ck.X([4,5,6]) 22 | ck.CY(6,5,4,3) 23 | ck.list() 24 | ck.draw() 25 | job = qckt.Job(ck, qtrace=True) 26 | DMQdeb().runjob(job) 27 | 28 | # CZ 29 | print("CZ ---------------------------------------") 30 | ck = qckt.QCkt(8) 31 | ck.CZ(2,1,0) 32 | ck.X([3,4,5,6]) 33 | ck.CZ(6,5,4,3) 34 | ck.list() 35 | ck.draw() 36 | job = qckt.Job(ck, qtrace=True) 37 | DMQdeb().runjob(job) 38 | 39 | # CP 40 | print("CP ---------------------------------------") 41 | ck = qckt.QCkt(8) 42 | ck.CP(np.pi/4,2,1,0) 43 | ck.X([4,5,6,3]) 44 | ck.CP(np.pi/4,6,5,4,3) 45 | ck.list() 46 | ck.draw() 47 | job = qckt.Job(ck, qtrace=True) 48 | DMQdeb().runjob(job) 49 | 50 | 51 | # CROTx 52 | print("CROTk ------------------------------------") 53 | ck = qckt.QCkt(8) 54 | ck.CROTk(3,2,1,0) 55 | ck.X([4,5,6,3]) 56 | ck.CROTk(3,6,5,4,3) 57 | ck.list() 58 | ck.draw() 59 | job = qckt.Job(ck, qtrace=True) 60 | DMQdeb().runjob(job) 61 | -------------------------------------------------------------------------------- /tests/qckt/CTRL-tests.py: -------------------------------------------------------------------------------- 1 | import qckt 2 | from qckt.backend import * 3 | import numpy as np 4 | 5 | 6 | # CX 7 | print("CX ---------------------------------------") 8 | ck = qckt.QCkt(8) 9 | ck.CX(2,1,0) 10 | ck.X([4,5,6]) 11 | ck.CX(6,5,4,3) 12 | ck.list() 13 | ck.draw() 14 | job = qckt.Job(ck, qtrace=True) 15 | Qdeb().runjob(job) 16 | 17 | # CY 18 | print("CY ---------------------------------------") 19 | ck = qckt.QCkt(8) 20 | ck.CY(2,1,0) 21 | ck.X([4,5,6]) 22 | ck.CY(6,5,4,3) 23 | ck.list() 24 | ck.draw() 25 | job = qckt.Job(ck, qtrace=True) 26 | Qdeb().runjob(job) 27 | 28 | # CZ 29 | print("CZ ---------------------------------------") 30 | ck = qckt.QCkt(8) 31 | ck.CZ(2,1,0) 32 | ck.X([3,4,5,6]) 33 | ck.CZ(6,5,4,3) 34 | ck.list() 35 | ck.draw() 36 | job = qckt.Job(ck, qtrace=True) 37 | Qdeb().runjob(job) 38 | 39 | # CP 40 | print("CP ---------------------------------------") 41 | ck = qckt.QCkt(8) 42 | ck.CP(np.pi/4,2,1,0) 43 | ck.X([4,5,6,3]) 44 | ck.CP(np.pi/4,6,5,4,3) 45 | ck.list() 46 | ck.draw() 47 | job = qckt.Job(ck, qtrace=True) 48 | Qdeb().runjob(job) 49 | 50 | 51 | # CROTx 52 | print("CROTk ------------------------------------") 53 | ck = qckt.QCkt(8) 54 | ck.CROTk(3,2,1,0) 55 | ck.X([4,5,6,3]) 56 | ck.CROTk(3,6,5,4,3) 57 | ck.list() 58 | ck.draw() 59 | job = qckt.Job(ck, qtrace=True) 60 | Qdeb().runjob(job) 61 | -------------------------------------------------------------------------------- /tests/qckt/QFT-test-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | import qckt 5 | from qckt.backend import * 6 | 7 | nqbits = 8 # per the definition of f(x) below, must be >= 4 8 | M = 2**(nqbits-2) 9 | cktf = qckt.QCkt(nqbits) 10 | cktf.CX(2,0) 11 | cktf.CX(3,1) 12 | print("Psst ... f(x) defined as having period of 4\n") 13 | 14 | ckt = qckt.QCkt(nqbits) 15 | ckt.X(0) 16 | ckt.QFT(*(range(nqbits-1,1,-1))) 17 | ckt = ckt.append(cktf) 18 | ckt.QFT(*(range(nqbits-1,1,-1))) 19 | ckt.draw() 20 | 21 | job = qckt.Job(ckt,qtrace=False) 22 | bk = DMQdeb() 23 | bk.runjob(job) 24 | 25 | svec = job.get_svec() 26 | print("READ OUT STATE VECTOR: ") 27 | print(svec) 28 | 29 | print("READ OUT CREGISTER: ",end="") 30 | creg = job.get_creg()[0] 31 | print(creg) 32 | -------------------------------------------------------------------------------- /tests/qckt/QFT-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | import qckt 5 | from qckt.backend import * 6 | 7 | nqbits = 8 # per the definition of f(x) below, must be >= 4 8 | M = 2**(nqbits-2) 9 | cktf = qckt.QCkt(nqbits) 10 | cktf.CX(2,0) 11 | cktf.CX(3,1) 12 | print("Psst ... f(x) defined as having period of 4\n") 13 | 14 | ckt = qckt.QCkt(nqbits) 15 | ckt.X(0) 16 | ckt.QFT(*(range(nqbits-1,1,-1))) 17 | ckt = ckt.append(cktf) 18 | ckt.QFT(*(range(nqbits-1,1,-1))) 19 | ckt.draw() 20 | 21 | job = qckt.Job(ckt,qtrace=False) 22 | bk = Qdeb() 23 | bk.runjob(job) 24 | 25 | svec = job.get_svec() 26 | print("READ OUT STATE VECTOR: ") 27 | print(svec) 28 | 29 | print("READ OUT CREGISTER: ",end="") 30 | creg = job.get_creg()[0] 31 | print(creg) 32 | -------------------------------------------------------------------------------- /tests/qckt/RUN_ALL_TESTS: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BRIEF=0 3 | QUIET=0 4 | while [[ $# -gt 0 ]] 5 | do 6 | key="$1" 7 | 8 | case $key in 9 | -b|--brief) 10 | BRIEF=1 11 | ;; 12 | -q|--quiet) 13 | QUIET=1 14 | ;; 15 | *) 16 | echo "Usage: $0 [-b|--brief] [-q|--quiet]" 17 | exit 1 18 | ;; 19 | esac 20 | shift # past argument or value 21 | done 22 | 23 | list=`ls *.py` 24 | 25 | if [ ! -d runlogs ]; then 26 | mkdir runlogs 27 | fi 28 | overall_ret=0 29 | for f in $list; do 30 | logfile=runlogs/${f}.log 31 | python3 $f > ${logfile} 32 | explist="" 33 | explist=$(ls expected/${f}.log*) 34 | succ=1 35 | if [[ $explist != "" ]]; then 36 | for e in $explist; do 37 | cmp -s $logfile $e 38 | if [ $? = 0 ]; then 39 | succ=0 40 | fi 41 | done 42 | fi 43 | if [ $succ = 0 ]; then 44 | if [[ $BRIEF = 0 && $QUIET = 0 ]]; then 45 | echo "SUCCESS - $f" 46 | fi 47 | else 48 | if [[ $QUIET = 0 ]]; then 49 | echo ">>>>>>> FAILED - $f" 50 | fi 51 | overall_ret=1 52 | fi 53 | done 54 | if [[ $BRIEF = 1 && $QUIET = 0 ]]; then 55 | if [[ $overall_ret = 0 ]]; then 56 | echo "SUCCESS" 57 | fi 58 | fi 59 | exit $overall_ret 60 | -------------------------------------------------------------------------------- /tests/qckt/SHOWDIFF: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | diff -y runlogs/${1}.log expected/${1}.log | less 4 | -------------------------------------------------------------------------------- /tests/qckt/allgates_drawifcbit_test.py: -------------------------------------------------------------------------------- 1 | 2 | import qckt 3 | from qckt import QCktException 4 | import numpy as np 5 | 6 | print('X') 7 | ck = qckt.QCkt(5,5) 8 | ck.X(1).ifcbit(2,1) 9 | ck.X([2,3]).ifcbit(2,1) 10 | ck.draw() 11 | 12 | print('Y') 13 | ck = qckt.QCkt(5,5) 14 | ck.Y(1).ifcbit(2,1) 15 | ck.Y([1,3]).ifcbit(2,1) 16 | ck.draw() 17 | 18 | print('Z') 19 | ck = qckt.QCkt(5,5) 20 | ck.Z(1).ifcbit(2,1) 21 | ck.Z([1,3]).ifcbit(2,1) 22 | ck.draw() 23 | 24 | print('H') 25 | ck = qckt.QCkt(5,5) 26 | ck.H(0).ifcbit(2,1) 27 | ck.H([1,3]).ifcbit(2,1) 28 | ck.draw() 29 | 30 | print('CX') 31 | ck = qckt.QCkt(5,5) 32 | ck.CX(1,3).ifcbit(2,1) 33 | ck.draw() 34 | 35 | print('CY') 36 | ck = qckt.QCkt(5,5) 37 | ck.CY(0,2).ifcbit(3,1) 38 | ck.draw() 39 | 40 | print('CZ') 41 | ck = qckt.QCkt(5,5) 42 | ck.CZ(0,2).ifcbit(3,1) 43 | ck.draw() 44 | 45 | print('CCX') 46 | ck = qckt.QCkt(5,5) 47 | ck.CCX(0,3,2).ifcbit(3,1) 48 | ck.draw() 49 | 50 | print('SWAP') 51 | ck = qckt.QCkt(5,5) 52 | ck.SWAP(1,3).ifcbit(3,1) 53 | ck.draw() 54 | 55 | print('M') 56 | ck = qckt.QCkt(5,5) 57 | try: 58 | ck.M([1,2]).ifcbit(3,1) 59 | except QCktException as ex: 60 | print(ex) 61 | ck.draw() 62 | 63 | print('Border') 64 | ck = qckt.QCkt(5,5) 65 | try: 66 | ck.Border().ifcbit(2,1) 67 | except QCktException as ex: 68 | print(ex) 69 | ck.draw() 70 | 71 | print('Probe') 72 | ck = qckt.QCkt(5,5) 73 | try: 74 | ck.Probe().ifcbit(2,1) 75 | except QCktException as ex: 76 | print(ex) 77 | ck.draw() 78 | 79 | print('QFT') 80 | ck = qckt.QCkt(5,5) 81 | ck.QFT([1,3,2]).ifcbit(2,1) 82 | ck.draw() 83 | 84 | print('RND') 85 | ck = qckt.QCkt(5,5) 86 | ck.RND(2).ifcbit(3,1) 87 | ck.draw() 88 | 89 | print('P') 90 | ck = qckt.QCkt(5,5) 91 | ck.P(0.1, 2).ifcbit(3,0) 92 | ck.draw() 93 | 94 | print('CP') 95 | ck = qckt.QCkt(5,5) 96 | ck.CP(0.1,1,3).ifcbit(3,0) 97 | ck.draw() 98 | 99 | print('UROTk') 100 | ck = qckt.QCkt(5,5) 101 | ck.UROTk(3,2).ifcbit(3,1) 102 | ck.draw() 103 | 104 | print('CROTk') 105 | ck = qckt.QCkt(5,5) 106 | ck.CROTk(3,1,3).ifcbit(3,0) 107 | ck.draw() 108 | 109 | print('Rx') 110 | ck = qckt.QCkt(5,5) 111 | ck.Rx(0.1, 3).ifcbit(3,0) 112 | ck.draw() 113 | 114 | print('CRx') 115 | ck = qckt.QCkt(5,5) 116 | ck.CRx(0.1, 3,4).ifcbit(2,1) 117 | ck.draw() 118 | 119 | print('Ry') 120 | ck = qckt.QCkt(5,5) 121 | ck.Ry(0.1,0).ifcbit(2,1) 122 | ck.draw() 123 | 124 | print('CRy') 125 | ck = qckt.QCkt(5,5) 126 | ck.CRy(0.3, 3,2).ifcbit(4,0) 127 | ck.draw() 128 | 129 | print('Rz') 130 | ck = qckt.QCkt(5,5) 131 | ck.Rz(1.1, 2).ifcbit(3,0) 132 | ck.draw() 133 | 134 | print('CRz') 135 | ck = qckt.QCkt(5,5) 136 | ck.CRz(1.5, 2,3,4).ifcbit(2,0) 137 | ck.draw() 138 | 139 | print('CUSTOM') 140 | opmat = np.matrix([ 141 | [1,0,0,0], 142 | [0,1,0,0], 143 | [0,0,0,1], 144 | [0,0,1,0]],dtype=complex) 145 | qckt.define_gate("CUST",opmat) 146 | print(qckt.get_gates_list()) 147 | 148 | ck = qckt.QCkt(5,5) 149 | ck.CUST(0,2).ifcbit(3,1) 150 | ck.draw() 151 | -------------------------------------------------------------------------------- /tests/qckt/arg_validations.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt as q 4 | from qckt import QCktException 5 | import numpy as np 6 | 7 | ck = q.QCkt(4,4) 8 | 9 | try: 10 | ck.X(8) 11 | except QCktException as e: 12 | print(e.msg) 13 | try: 14 | ck.X(0) 15 | ck.X([0,1,2,6]) 16 | except QCktException as e: 17 | print(e) 18 | 19 | try: 20 | ck.Y(8) 21 | except QCktException as e: 22 | print(e.msg) 23 | try: 24 | ck.Y(0) 25 | ck.Y([0,1,2,6]) 26 | except QCktException as e: 27 | print(e) 28 | 29 | try: 30 | ck.Z(8) 31 | except QCktException as e: 32 | print(e.msg) 33 | try: 34 | ck.Z(0) 35 | ck.Z([0,1,2,6]) 36 | except QCktException as e: 37 | print(e) 38 | 39 | try: 40 | ck.H(8) 41 | except QCktException as e: 42 | print(e.msg) 43 | try: 44 | ck.H(0) 45 | ck.H([0,1,6]) 46 | except QCktException as e: 47 | print(e) 48 | 49 | try: 50 | ck.RND(8) 51 | except QCktException as e: 52 | print(e.msg) 53 | try: 54 | ck.RND(0) 55 | ck.RND([0,1,6]) 56 | except QCktException as e: 57 | print(e) 58 | 59 | try: 60 | ck.P(3.14/2,8) 61 | except QCktException as e: 62 | print(e.msg) 63 | try: 64 | ck.P(3.14/2,0) 65 | ck.P(3.14/2,[0,1,6]) 66 | except QCktException as e: 67 | print(e) 68 | 69 | try: 70 | ck.UROTk(12,8) 71 | except QCktException as e: 72 | print(e.msg) 73 | try: 74 | ck.UROTk(10,0) 75 | ck.UROTk(8,[0,1,6]) 76 | except QCktException as e: 77 | print(e) 78 | 79 | try: 80 | ck.CX(0,1) 81 | ck.CX(1) 82 | except QCktException as e: 83 | print(e) 84 | try: 85 | ck.CX([0,1,2,3]) 86 | except QCktException as e: 87 | print(e) 88 | 89 | try: 90 | ck.CY(0,1) 91 | ck.CY(1) 92 | except QCktException as e: 93 | print(e) 94 | try: 95 | ck.CY([0,1,2,3]) 96 | except QCktException as e: 97 | print(e) 98 | 99 | try: 100 | ck.CZ(0,1) 101 | ck.CZ(1) 102 | except QCktException as e: 103 | print(e) 104 | try: 105 | ck.CZ([0,1,2,3]) 106 | except QCktException as e: 107 | print(e) 108 | 109 | try: 110 | ck.CCX(0,1,2) 111 | ck.CCX(1,1,3) 112 | except QCktException as e: 113 | print(e) 114 | try: 115 | ck.CCX(1,2,8) 116 | except QCktException as e: 117 | print(e) 118 | try: 119 | ck.CCX([0,1],2,3) 120 | except QCktException as e: 121 | print(e) 122 | 123 | try: 124 | ck.CP(3.14/2,0,1) 125 | ck.CP(3.14/2, 0,1,2,3) 126 | ck.CP(3.14/2,1) 127 | except QCktException as e: 128 | print(e) 129 | try: 130 | ck.CP(3.14/2, 0,1,2,3) 131 | ck.CP(3.14/2, [0,1,2,3]) 132 | except QCktException as e: 133 | print(e) 134 | 135 | try: 136 | ck.CROTk(2, 0,1) 137 | ck.CROTk(2, 0,1,2,3) 138 | ck.CROTk(2, 1) 139 | except QCktException as e: 140 | print(e) 141 | try: 142 | ck.CROTk(2, 0,1,2,3) 143 | ck.CROTk(2, 0,1,2,8) 144 | except QCktException as e: 145 | print(e) 146 | 147 | try: 148 | ck.QFT([0,1,2,3]) 149 | ck.QFT([0,1],[2,3]) 150 | except QCktException as e: 151 | print(e) 152 | 153 | try: 154 | ck.SWAP(0,1) 155 | ck.SWAP(0,8) 156 | except QCktException as e: 157 | print(e) 158 | try: 159 | ck.SWAP([0,1],[2,3]) 160 | except QCktException as e: 161 | print(e) 162 | 163 | try: 164 | ck.M([0,1]) 165 | ck.M([0,8]) 166 | except QCktException as e: 167 | print(e) 168 | try: 169 | ck.M([0,1],[2,5]) 170 | except QCktException as e: 171 | print(e) 172 | try: 173 | ck.M([0,2],[2,1,2]) 174 | except QCktException as e: 175 | print(e) 176 | 177 | opmat = np.matrix([ 178 | [1,0,0,0], 179 | [0,1,0,0], 180 | [0,0,0,1], 181 | [0,0,1,0]],dtype=complex) 182 | q.define_gate("CNOT",opmat) 183 | ck = q.QCkt(4,4) 184 | try: 185 | ck.CNOT(0,1) 186 | ck.CNOT(0,1,2) 187 | except QCktException as e: 188 | print(e) 189 | 190 | try: 191 | opmat = np.matrix([ 192 | [1,0,0,0], 193 | [0,0,0,1], 194 | [0,0,1,0]],dtype=complex) 195 | q.define_gate('CTRLX',opmat) 196 | except QCktException as e: 197 | print(e) 198 | -------------------------------------------------------------------------------- /tests/qckt/backend-test-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | from qckt.backend import * 5 | 6 | #test 02 7 | nq = 6 8 | qc = qckt.QCkt(nq,nq) 9 | qc.H(0) 10 | qc.CX(0,1) 11 | qc.QFT(0,1,2,3) 12 | qc.X(4) 13 | qc.Y(5) 14 | qc.M([4,5]) 15 | qc.draw() 16 | 17 | job = qckt.Job(qc,qtrace=False) 18 | bk = DMQdeb() 19 | bk.runjob(job) 20 | 21 | svec = job.get_svec() 22 | print("READ OUT STATE VECTOR: ") 23 | print(svec) 24 | print("READ OUT STATE VECTOR (verbose): ") 25 | svec.verbose(True) 26 | print(svec) 27 | 28 | # print cregister in proper MSB to LSB order 29 | print("READ OUT CREGISTER: ",end="") 30 | creg = job.get_creg()[0] 31 | print(creg) 32 | 33 | #### multiple qbits inputs for single qubit gates draw and list 34 | print() 35 | print("================================================================") 36 | print("multiple inputs X, Y, Z, H, P, UROTk gates draw and list test===") 37 | print("================================================================") 38 | 39 | ck = qckt.QCkt(8) 40 | ck.X([0,1,2,3]) 41 | ck.Y([1,2,3,4]) 42 | ck.Z([2,3,4,5]) 43 | ck.H([3,4,5,6]) 44 | ck.P(3.14/2,[4,5,6,7]) 45 | ck.UROTk(2,[2,3,4,5,6,7]) 46 | ck.list() 47 | ck.draw() 48 | 49 | job = qckt.Job(ck,qtrace=True) 50 | bk = DMQdeb() 51 | bk.runjob(job) 52 | 53 | svec = job.get_svec() 54 | print("READ OUT STATE VECTOR: ") 55 | print(svec) 56 | print("READ OUT STATE VECTOR (verbose): ") 57 | svec.verbose(True) 58 | print(svec) 59 | 60 | -------------------------------------------------------------------------------- /tests/qckt/backend-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | from qckt.backend import * 5 | 6 | #test 02 7 | nq = 6 8 | qc = qckt.QCkt(nq,nq) 9 | qc.H(0) 10 | qc.CX(0,1) 11 | qc.QFT(0,1,2,3) 12 | qc.X(4) 13 | qc.Y(5) 14 | qc.M([4,5]) 15 | qc.draw() 16 | 17 | job = qckt.Job(qc,qtrace=False) 18 | bk = Qdeb() 19 | bk.runjob(job) 20 | 21 | svec = job.get_svec() 22 | print("READ OUT STATE VECTOR: ") 23 | print(svec) 24 | print("READ OUT STATE VECTOR (verbose): ") 25 | svec.verbose(True) 26 | print(svec) 27 | 28 | # print cregister in proper MSB to LSB order 29 | print("READ OUT CREGISTER: ",end="") 30 | creg = job.get_creg()[0] 31 | print(creg) 32 | 33 | #### multiple qbits inputs for single qubit gates draw and list 34 | print() 35 | print("================================================================") 36 | print("multiple inputs X, Y, Z, H, P, UROTk gates draw and list test===") 37 | print("================================================================") 38 | 39 | ck = qckt.QCkt(8) 40 | ck.X([0,1,2,3]) 41 | ck.Y([1,2,3,4]) 42 | ck.Z([2,3,4,5]) 43 | ck.H([3,4,5,6]) 44 | ck.P(3.14/2,[4,5,6,7]) 45 | ck.UROTk(2,[2,3,4,5,6,7]) 46 | ck.list() 47 | ck.draw() 48 | 49 | job = qckt.Job(ck,qtrace=True) 50 | bk = Qdeb() 51 | bk.runjob(job) 52 | 53 | svec = job.get_svec() 54 | print("READ OUT STATE VECTOR: ") 55 | print(svec) 56 | print("READ OUT STATE VECTOR (verbose): ") 57 | svec.verbose(True) 58 | print(svec) 59 | 60 | -------------------------------------------------------------------------------- /tests/qckt/circuits-test-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt as qk 4 | from qckt.backend import * 5 | 6 | ckt1 = qk.QCkt(4,4) 7 | 8 | ckt1.X(0) 9 | ckt1.CX(0,1) 10 | ckt1.H(1) 11 | ckt1.X(2) 12 | ckt1.CCX(2,0,1) 13 | ckt1.Border() 14 | 15 | ckt2 = qk.QCkt(6,6) 16 | ckt2.Y(4) 17 | ckt2.Z(5) 18 | ckt2.Border() 19 | 20 | ckt1 = ckt1.realign(6,6,[0,1,2,3]) 21 | 22 | ckt3 = ckt1.append(ckt2) 23 | ckt3.CCX(4,5,3) 24 | ckt3.M([3,4,5],[3,4,5]) 25 | 26 | ckt3.draw() 27 | 28 | job = qk.Job(ckt3, qtrace=False) 29 | bk = DMQdeb() 30 | bk.runjob(job) 31 | print("READ OUT STATE VECTOR: ") 32 | print(job.get_svec()) 33 | res = job.get_creg()[0] 34 | print("READ OUT CREGISTER: ", end="") 35 | print(res) 36 | -------------------------------------------------------------------------------- /tests/qckt/circuits-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt as qk 4 | from qckt.backend import * 5 | 6 | ckt1 = qk.QCkt(4,4) 7 | 8 | ckt1.X(0) 9 | ckt1.CX(0,1) 10 | ckt1.H(1) 11 | ckt1.X(2) 12 | ckt1.CCX(2,0,1) 13 | ckt1.Border() 14 | 15 | ckt2 = qk.QCkt(6,6) 16 | ckt2.Y(4) 17 | ckt2.Z(5) 18 | ckt2.Border() 19 | 20 | ckt1 = ckt1.realign(6,6,[0,1,2,3]) 21 | 22 | ckt3 = ckt1.append(ckt2) 23 | ckt3.CCX(4,5,3) 24 | ckt3.M([3,4,5],[3,4,5]) 25 | 26 | ckt3.draw() 27 | 28 | job = qk.Job(ckt3, qtrace=False) 29 | bk = Qdeb() 30 | bk.runjob(job) 31 | print("READ OUT STATE VECTOR: ") 32 | print(job.get_svec()) 33 | res = job.get_creg()[0] 34 | print("READ OUT CREGISTER: ", end="") 35 | print(res) 36 | -------------------------------------------------------------------------------- /tests/qckt/custom-append-realign.py: -------------------------------------------------------------------------------- 1 | import qckt 2 | import qckt.backend as bknd 3 | import qckt.noisemodel as ns 4 | import numpy as np 5 | 6 | # test 01 - custom gate 7 | print('test 01 - custom gate') 8 | # create user defined gates 9 | qckt.define_gate('myX', np.matrix([[0.0,1.0],[1.0,0.0]],dtype=complex)) 10 | qckt.define_gate('myCX', np.matrix([[1.0,0.0,0.0,0.0],[0.0,1.0,0.0,0.0],[0.0,0.0,0.0,1.0],[0.0,0.0,1.0,0.0]],dtype=complex)) 11 | ck = qckt.QCkt(3,3) 12 | ck.H(0) 13 | ck.myCX(0,2) 14 | ck.myX(0) 15 | ck.myX(1) 16 | ck.myX(2) 17 | ck.draw() 18 | job = qckt.Job(ck,qtrace=True, verbose=True) 19 | bk = bknd.DMQdeb() 20 | bk.runjob(job) 21 | 22 | # test 02 - realign should preserve the custom gate definitions 23 | print('test 02 - realign should preserve the custom gate definitions') 24 | ck2 = ck.realign(newnq=3,newnc=3,inpqubits=[1,2,0]) 25 | ck2.myX(0) 26 | ck2.draw() 27 | job = qckt.Job(ck2,qtrace=True, verbose=True) 28 | bk = bknd.DMQdeb() 29 | bk.runjob(job) 30 | 31 | # test 03 - append should preserve custom gate definitions 32 | print('test 03 - append should preserve custom gate definitions') 33 | qckt.define_gate('my2CX', np.matrix([[1.0,0.0,0.0,0.0],[0.0,1.0,0.0,0.0],[0.0,0.0,0.0,1.0],[0.0,0.0,1.0,0.0]],dtype=complex)) 34 | qckt.define_gate('my2X', np.matrix([[0.0,1.0],[1.0,0.0]],dtype=complex)) 35 | ck3 = qckt.QCkt(3,3) 36 | ck3.H(0) 37 | ck3.my2CX(0,1) 38 | 39 | ck4 = qckt.QCkt(3,3) 40 | ck4.my2X(2) 41 | 42 | ck5 = ck3.append(ck4) 43 | ck5.my2CX(0,1) 44 | ck5.draw() 45 | job = qckt.Job(ck5,qtrace=True, verbose=True) 46 | bk = bknd.DMQdeb() 47 | bk.runjob(job) 48 | -------------------------------------------------------------------------------- /tests/qckt/customgate-test-dm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import qckt 3 | from qckt import QCktException 4 | from qckt.backend import * 5 | 6 | opmat = np.matrix([ 7 | [1,0,0,0], 8 | [0,1,0,0], 9 | [0,0,0,1], 10 | [0,0,1,0]],dtype=complex) 11 | qckt.define_gate("CNOT",opmat) 12 | 13 | ck = qckt.QCkt(4) 14 | ck.H(0) 15 | ck.CNOT(0,2) 16 | ck.draw() 17 | inpqubits = [3,1,2,0] 18 | ck = ck.realign(4,4,inpqubits) 19 | print("realigned with:",inpqubits) 20 | ck.draw() 21 | 22 | ## by appending circuits, the custom gates definitions are available to the new circuit 23 | ckt = qckt.QCkt(6) 24 | ckt = ckt.append(ck) 25 | ckt = ckt.append(ck) 26 | ckt.CNOT(1,3) 27 | ckt.draw() 28 | job = qckt.Job(ckt,qtrace=True) 29 | DMQdeb().runjob(job) 30 | 31 | print("==Unitary test=======================") 32 | opmatx = np.matrix([ 33 | [2,0,0,0], 34 | [0,2,0,0], 35 | [0,0,0,1], 36 | [0,0,1,0]],dtype=complex) 37 | try: 38 | qckt.define_gate("CuCXx",opmatx) 39 | except QCktException as e: 40 | print(e) 41 | 42 | qckt.define_gate("CuCX",opmat) 43 | ckt = qckt.QCkt(6) 44 | ckt.CuCX(1,3) 45 | ckt.draw() 46 | job = qckt.Job(ckt,qtrace=True) 47 | DMQdeb().runjob(job) 48 | -------------------------------------------------------------------------------- /tests/qckt/customgate-test.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import qckt 3 | from qckt import QCktException 4 | from qckt.backend import * 5 | 6 | opmat = np.matrix([ 7 | [1,0,0,0], 8 | [0,1,0,0], 9 | [0,0,0,1], 10 | [0,0,1,0]],dtype=complex) 11 | qckt.define_gate("CNOT",opmat) 12 | 13 | ck = qckt.QCkt(4) 14 | ck.H(0) 15 | ck.CNOT(0,2) 16 | ck.draw() 17 | inpqubits = [3,1,2,0] 18 | ck = ck.realign(4,4,inpqubits) 19 | print("realigned with:",inpqubits) 20 | ck.draw() 21 | 22 | ## by appending circuits, the custom gates definitions are available to the new circuit 23 | ckt = qckt.QCkt(6) 24 | ckt = ckt.append(ck) 25 | ckt = ckt.append(ck) 26 | ckt.CNOT(1,3) 27 | ckt.draw() 28 | job = qckt.Job(ckt,qtrace=True) 29 | Qdeb().runjob(job) 30 | 31 | print("==Unitary test=======================") 32 | opmatx = np.matrix([ 33 | [2,0,0,0], 34 | [0,2,0,0], 35 | [0,0,0,1], 36 | [0,0,1,0]],dtype=complex) 37 | try: 38 | qckt.define_gate("CuCXx",opmatx) 39 | except QCktException as e: 40 | print(e) 41 | 42 | qckt.define_gate("CuCX",opmat) 43 | ckt = qckt.QCkt(6) 44 | ckt.CuCX(1,3) 45 | ckt.draw() 46 | job = qckt.Job(ckt,qtrace=True) 47 | Qdeb().runjob(job) 48 | -------------------------------------------------------------------------------- /tests/qckt/direct-qengine-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | from qckt.backend import * 5 | 6 | ck = qckt.QCkt(4,4) 7 | ck.H(0) 8 | ck.CX(0,1) 9 | ck.Border() 10 | ck.X([2,3]) 11 | ck.Border() 12 | # ck.M([1,0],[1,0]) 13 | ck.Probe("point 1") 14 | ck.draw() 15 | 16 | job = qckt.Job(ck,qtrace=False,shots=5) 17 | bk = DMQdeb().runjob(job) 18 | # bk = DMQeng().runjob(job) 19 | print(job.get_svec()) 20 | print(job.get_creg()[0]) 21 | -------------------------------------------------------------------------------- /tests/qckt/direct-qengine.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | from qckt.backend import * 5 | 6 | ck = qckt.QCkt(4,4) 7 | ck.H(0) 8 | ck.CX(0,1) 9 | ck.Border() 10 | ck.X([2,3]) 11 | ck.Border() 12 | # ck.M([1,0],[1,0]) 13 | ck.Probe("point 1") 14 | ck.draw() 15 | 16 | job = qckt.Job(ck,qtrace=False,shots=5) 17 | bk = Qdeb().runjob(job) 18 | # bk = Qeng().runjob(job) 19 | print(job.get_svec()) 20 | print(job.get_creg()[0]) 21 | -------------------------------------------------------------------------------- /tests/qckt/drawlist-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import qckt.noisemodel as ns 5 | 6 | # test 01 7 | print("================================================") 8 | print("Composing circuits from subcircuits ============") 9 | print("================================================") 10 | print() 11 | print("subcircuit--------------------------------------") 12 | qckt1 = qckt.QCkt(2,name="ckt01") 13 | qckt1.H(0) 14 | qckt1.CX(0,1) 15 | qckt1.Border() 16 | qckt1.draw() 17 | qckt1.list() 18 | 19 | print("subcircuit with QFT ----------------------------") 20 | qckt2 = qckt.QCkt(4,name="ckt02") 21 | qckt2.QFT(2,0,3) 22 | qckt2.X(2) 23 | qckt2.Y(0) 24 | qckt2.Z(3) 25 | qckt2.Border() 26 | qckt2.draw() 27 | qckt2.list() 28 | 29 | print("fragment of the final circuit-------------------") 30 | qckt3 = qckt.QCkt(4,4,name="ckt03") 31 | qckt3.M([2,3]) 32 | qckt3.Border() 33 | qckt3.draw() 34 | qckt3.list() 35 | 36 | print("realigned subcircuit----------------------------") 37 | qckt1 = qckt1.realign(4,4,[3,2]) 38 | qckt1.draw() 39 | qckt1.list() 40 | 41 | print("realigned subcircuit----------------------------") 42 | qckt2 = qckt2.realign(4,4,[1,3,0,2]) 43 | qckt2.draw() 44 | qckt2.list() 45 | 46 | print("Overall circuit---------------------------------") 47 | qckt5 = (qckt1.append(qckt2)).append(qckt3) 48 | qckt5.draw() 49 | qckt5.list() 50 | 51 | #### RND, P, CP, SWAP and UROTk gates draw and list 52 | print() 53 | print("================================================") 54 | print("RND, P, UROTk gates draw and list test===========") 55 | print("================================================") 56 | 57 | ck = qckt.QCkt(4) 58 | ck.RND(0) 59 | ck.P(3.14/4,1) 60 | ck.CP(3.14/8,0,3) 61 | ck.UROTk(3,2) 62 | ck.CROTk(3,2,0) 63 | ck.SWAP(1,3) 64 | ck.CCX(0,2,3) 65 | ck.CCX(2,3,0) 66 | ck.draw() 67 | ck.list() 68 | ck = ck.realign(6,6,[3,0,2,1]) 69 | ck.draw() 70 | ck.list() 71 | 72 | #### multiple qbits inputs for single qubit gates draw and list 73 | print() 74 | print("================================================================") 75 | print("multiple inputs X, Y, Z, H, P, UROTk gates draw and list test===") 76 | print("================================================================") 77 | 78 | ck = qckt.QCkt(8) 79 | ck.X([0,1,2,3]) 80 | ck.Y([1,2,3,4]) 81 | ck.Z([2,3,4,5]) 82 | ck.H([3,4,5,6]) 83 | ck.P(3.14/2,[4,5,6,7]) 84 | ck.UROTk(2,[2,3,4,5,6,7]) 85 | ck.list() 86 | ck.draw() 87 | 88 | 89 | #### sniff test for drawing and listing noise elements 90 | print() 91 | print("================================================================") 92 | print("sniff test for drawing and listing noise elements===============") 93 | print("================================================================") 94 | 95 | ck = qckt.QCkt(2,2,name='Test circuit for draw, list') 96 | ck.H(0) 97 | ck.CX(0,1).ifcbit(1,1) 98 | ck.P(3.14,[0,1]) 99 | ck.UROTk(2,0) 100 | ck.NOISE(ns.bit_flip(0.5),[0,1]) 101 | ck.M([1,0],[1,0]) 102 | ck.Probe() 103 | 104 | ck.set_noise_profile(noise_profile=ns.NoiseProfile( 105 | noise_chan_init=ns.bit_flip(probability=0.1), 106 | noise_chan_allgates=ns.depolarizing(probability=0.2), 107 | noise_chan_qubits=ns.NoiseChannelApplierSequense(noise_chan=ns.amplitude_damping(gamma=0.3),qubit_list=[1]), 108 | noise_chan_allsteps=ns.NoiseChannelApplierSequense(noise_chan=ns.phase_damping(gamma=0.4),qubit_list=[1]), 109 | ) 110 | ) 111 | ck.list(show_noise=True) 112 | print() 113 | ck.draw(show_noise=True) 114 | print() 115 | ck.list(show_noise=False) 116 | print() 117 | ck.draw(show_noise=False) 118 | print() 119 | -------------------------------------------------------------------------------- /tests/qckt/expected/QFT-test-dm.py.log.1: -------------------------------------------------------------------------------- 1 | Psst ... f(x) defined as having period of 4 2 | 3 | q000 -[X]---------[X]------------- 4 | | 5 | q001 --------------|--[X]--------- 6 | | | 7 | q002 -----[QFT L]-[.]--|--[QFT L]- 8 | | | | | | 9 | q003 -----[QFT ]-----[.]-[QFT ]- 10 | | | | | 11 | q004 -----[QFT ]---------[QFT ]- 12 | | | | | 13 | q005 -----[QFT ]---------[QFT ]- 14 | | | | | 15 | q006 -----[QFT ]---------[QFT ]- 16 | | | | | 17 | q007 -----[QFT M]---------[QFT M]- 18 | 19 | creg ============================= 20 | 21 | READ OUT STATE VECTOR: 22 | Density matrix DIAGONAL 23 | 00000000 0.06250000+0.00000000j 24 | 00000001 0.06250000+0.00000000j 25 | 00000010 0.06250000+0.00000000j 26 | 00000011 0.06250000+0.00000000j 27 | 01000000 0.06250000+0.00000000j 28 | 01000001 0.06250000+0.00000000j 29 | 01000010 0.06250000-0.00000000j 30 | 01000011 0.06250000+0.00000000j 31 | 10000000 0.06250000+0.00000000j 32 | 10000001 0.06250000+0.00000000j 33 | 10000010 0.06250000+0.00000000j 34 | 10000011 0.06250000+0.00000000j 35 | 11000000 0.06250000-0.00000000j 36 | 11000001 0.06250000+0.00000000j 37 | 11000010 0.06250000+0.00000000j 38 | 11000011 0.06250000+0.00000000j 39 | 40 | READ OUT CREGISTER: 41 | -------------------------------------------------------------------------------- /tests/qckt/expected/QFT-test-dm.py.log.2: -------------------------------------------------------------------------------- 1 | Psst ... f(x) defined as having period of 4 2 | 3 | q000 -[X]---------[X]------------- 4 | | 5 | q001 --------------|--[X]--------- 6 | | | 7 | q002 -----[QFT L]-[.]--|--[QFT L]- 8 | | | | | | 9 | q003 -----[QFT ]-----[.]-[QFT ]- 10 | | | | | 11 | q004 -----[QFT ]---------[QFT ]- 12 | | | | | 13 | q005 -----[QFT ]---------[QFT ]- 14 | | | | | 15 | q006 -----[QFT ]---------[QFT ]- 16 | | | | | 17 | q007 -----[QFT M]---------[QFT M]- 18 | 19 | creg ============================= 20 | 21 | READ OUT STATE VECTOR: 22 | Density matrix DIAGONAL 23 | 00000000 0.06250000+0.00000000j 24 | 00000001 0.06250000+0.00000000j 25 | 00000010 0.06250000+0.00000000j 26 | 00000011 0.06250000+0.00000000j 27 | 01000000 0.06250000+0.00000000j 28 | 01000001 0.06250000+0.00000000j 29 | 01000010 0.06250000+0.00000000j 30 | 01000011 0.06250000+0.00000000j 31 | 10000000 0.06250000+0.00000000j 32 | 10000001 0.06250000+0.00000000j 33 | 10000010 0.06250000+0.00000000j 34 | 10000011 0.06250000+0.00000000j 35 | 11000000 0.06250000+0.00000000j 36 | 11000001 0.06250000+0.00000000j 37 | 11000010 0.06250000+0.00000000j 38 | 11000011 0.06250000+0.00000000j 39 | 40 | READ OUT CREGISTER: 41 | -------------------------------------------------------------------------------- /tests/qckt/expected/QFT-test.py.log: -------------------------------------------------------------------------------- 1 | Psst ... f(x) defined as having period of 4 2 | 3 | q000 -[X]---------[X]------------- 4 | | 5 | q001 --------------|--[X]--------- 6 | | | 7 | q002 -----[QFT L]-[.]--|--[QFT L]- 8 | | | | | | 9 | q003 -----[QFT ]-----[.]-[QFT ]- 10 | | | | | 11 | q004 -----[QFT ]---------[QFT ]- 12 | | | | | 13 | q005 -----[QFT ]---------[QFT ]- 14 | | | | | 15 | q006 -----[QFT ]---------[QFT ]- 16 | | | | | 17 | q007 -----[QFT M]---------[QFT M]- 18 | 19 | creg ============================= 20 | 21 | READ OUT STATE VECTOR: 22 | 00000000 0.25000000+0.00000000j 23 | 00000001 0.25000000+0.00000000j 24 | 00000010 0.25000000+0.00000000j 25 | 00000011 0.25000000+0.00000000j 26 | 01000000 0.00000000+0.25000000j 27 | 01000001 0.25000000+0.00000000j 28 | 01000010 -0.00000000-0.25000000j 29 | 01000011 -0.25000000+0.00000000j 30 | 10000000 -0.25000000+0.00000000j 31 | 10000001 0.25000000+0.00000000j 32 | 10000010 -0.25000000+0.00000000j 33 | 10000011 0.25000000+0.00000000j 34 | 11000000 -0.00000000-0.25000000j 35 | 11000001 0.25000000+0.00000000j 36 | 11000010 0.00000000+0.25000000j 37 | 11000011 -0.25000000+0.00000000j 38 | 39 | READ OUT CREGISTER: 40 | -------------------------------------------------------------------------------- /tests/qckt/expected/arg_validations.py.log: -------------------------------------------------------------------------------- 1 | Error: qubit arguments incorrect. X[8] 2 | Error: qubit arguments incorrect. X[0, 1, 2, 6] 3 | Error: qubit arguments incorrect. Y[8] 4 | Error: qubit arguments incorrect. Y[0, 1, 2, 6] 5 | Error: qubit arguments incorrect. Z[8] 6 | Error: qubit arguments incorrect. Z[0, 1, 2, 6] 7 | Error: qubit arguments incorrect. H[8] 8 | Error: qubit arguments incorrect. H[0, 1, 6] 9 | Error: qubit arguments incorrect. RND[8] 10 | Error: qubit arguments incorrect. RND[0, 1, 6] 11 | Error: qubit arguments incorrect. P[8] 12 | Error: qubit arguments incorrect. P[0, 1, 6] 13 | Error: qubit arguments incorrect. UROTk[8] 14 | Error: qubit arguments incorrect. UROTk[0, 1, 6] 15 | Error: qubit arguments incorrect. CX[1] 16 | Error: qubit arguments incorrect. CX[[0, 1, 2, 3]] 17 | Error: qubit arguments incorrect. CY[1] 18 | Error: qubit arguments incorrect. CY[[0, 1, 2, 3]] 19 | Error: qubit arguments incorrect. CZ[1] 20 | Error: qubit arguments incorrect. CZ[[0, 1, 2, 3]] 21 | Error: qubit arguments incorrect. CCX[1, 1, 3] 22 | Error: qubit arguments incorrect. CCX[1, 2, 8] 23 | Error: qubit arguments incorrect. CCX[[0, 1], 2, 3] 24 | Error: qubit arguments incorrect. CP[1] 25 | Error: qubit arguments incorrect. CP[[0, 1, 2, 3]] 26 | Error: qubit arguments incorrect. CROTk[1] 27 | Error: qubit arguments incorrect. CROTk[0, 1, 2, 8] 28 | Error: qubit arguments incorrect. QFT[[0, 1], [2, 3]] 29 | Error: qubit arguments incorrect. SWAP[0, 8] 30 | Error: qubit arguments incorrect. SWAP[[0, 1], [2, 3]] 31 | Error: qubit arguments incorrect. M[0, 8] 32 | Error: qubit arguments incorrect. M[0, 1] 33 | Error: qubit arguments incorrect. M[0, 2] 34 | Error: qubit arguments incorrect. CNOT[0, 1, 2] 35 | Custom gate, CTRLX, operator matrix is not unitary. 36 | -------------------------------------------------------------------------------- /tests/qckt/expected/circuits-test-dm.py.log: -------------------------------------------------------------------------------- 1 | q000 ----------------------#----------#--------- 2 | # # 3 | q001 -------------[X]-[.]--#----------#--------- 4 | | # # 5 | q002 -----[X]-[H]-----[X]--#----------#--------- 6 | | | # # 7 | q003 -[X]-[.]---------[.]--#----------#-[X]-[M]- 8 | # # | | 9 | q004 ----------------------#-[Y]------#-[.]-[M]- 10 | # # | | 11 | q005 ----------------------#-----[Z]--#-[.]-[M]- 12 | # # | 13 | creg ======================#==========#======v== 14 | # # 15 | READ OUT STATE VECTOR: 16 | Density matrix DIAGONAL 17 | 011010 0.50000000+0.00000000j 18 | 011110 0.50000000+0.00000000j 19 | 20 | READ OUT CREGISTER: 011000 21 | -------------------------------------------------------------------------------- /tests/qckt/expected/circuits-test.py.log: -------------------------------------------------------------------------------- 1 | q000 ----------------------#----------#--------- 2 | # # 3 | q001 -------------[X]-[.]--#----------#--------- 4 | | # # 5 | q002 -----[X]-[H]-----[X]--#----------#--------- 6 | | | # # 7 | q003 -[X]-[.]---------[.]--#----------#-[X]-[M]- 8 | # # | | 9 | q004 ----------------------#-[Y]------#-[.]-[M]- 10 | # # | | 11 | q005 ----------------------#-----[Z]--#-[.]-[M]- 12 | # # | 13 | creg ======================#==========#======v== 14 | # # 15 | READ OUT STATE VECTOR: 16 | 011010 0.00000000-0.70710678j 17 | 011110 0.00000000+0.70710678j 18 | 19 | READ OUT CREGISTER: 011000 20 | -------------------------------------------------------------------------------- /tests/qckt/expected/customgate-test-dm.py.log: -------------------------------------------------------------------------------- 1 | q000 -[H]-[CNOT M]- 2 | | | 3 | q001 -----|------|- 4 | | | 5 | q002 -----[CNOT L]- 6 | 7 | q003 -------------- 8 | 9 | creg ============== 10 | 11 | realigned with: [3, 1, 2, 0] 12 | q000 -[H]-[CNOT M]- 13 | | | 14 | q001 -----[CNOT L]- 15 | 16 | q002 -------------- 17 | 18 | q003 -------------- 19 | 20 | creg ============== 21 | 22 | q000 -[H]-[CNOT M]-[H]-[CNOT M]---------- 23 | | | | | 24 | q001 -----[CNOT L]-----[CNOT L]-[CNOT M]- 25 | | | 26 | q002 ---------------------------|------|- 27 | | | 28 | q003 ---------------------------[CNOT L]- 29 | 30 | q004 ------------------------------------ 31 | 32 | q005 ------------------------------------ 33 | 34 | creg ==================================== 35 | 36 | Initial State 37 | 000000 ... | 1.0000+0.0000j 38 | Mixed State Purity: 1.0000 39 | CREGISTER: 0000 40 | 41 | H Qubit[0] 42 | 000000 ... | 0.5000+0.0000j 43 | 000001 ... | 0.5000+0.0000j 44 | Mixed State Purity: 1.0000 45 | CREGISTER: 0000 46 | 47 | CNOT Qubit[0, 1] 48 | 000000 ... | 0.5000+0.0000j 49 | 000011 ... | 0.5000+0.0000j 50 | Mixed State Purity: 1.0000 51 | CREGISTER: 0000 52 | 53 | H Qubit[0] 54 | 000000 ... | 0.2500+0.0000j 55 | 000001 ... | 0.2500+0.0000j 56 | 000010 ... | 0.2500+0.0000j 57 | 000011 ... | 0.2500+0.0000j 58 | Mixed State Purity: 1.0000 59 | CREGISTER: 0000 60 | 61 | CNOT Qubit[0, 1] 62 | 000000 ... | 0.2500+0.0000j 63 | 000001 ... | 0.2500+0.0000j 64 | 000010 ... | 0.2500+0.0000j 65 | 000011 ... | 0.2500+0.0000j 66 | Mixed State Purity: 1.0000 67 | CREGISTER: 0000 68 | 69 | CNOT Qubit[1, 3] 70 | 000000 ... | 0.2500+0.0000j 71 | 000001 ... | 0.2500+0.0000j 72 | 001010 ... | 0.2500+0.0000j 73 | 001011 ... | 0.2500+0.0000j 74 | Mixed State Purity: 1.0000 75 | CREGISTER: 0000 76 | 77 | ==Unitary test======================= 78 | Custom gate, CuCXx, operator matrix is not unitary. 79 | q000 ---------- 80 | 81 | q001 -[CuCX M]- 82 | | | 83 | q002 -|------|- 84 | | | 85 | q003 -[CuCX L]- 86 | 87 | q004 ---------- 88 | 89 | q005 ---------- 90 | 91 | creg ========== 92 | 93 | Initial State 94 | 000000 ... | 1.0000+0.0000j 95 | Mixed State Purity: 1.0000 96 | CREGISTER: 97 | 98 | CuCX Qubit[1, 3] 99 | 000000 ... | 1.0000+0.0000j 100 | Mixed State Purity: 1.0000 101 | CREGISTER: 102 | 103 | -------------------------------------------------------------------------------- /tests/qckt/expected/customgate-test.py.log: -------------------------------------------------------------------------------- 1 | q000 -[H]-[CNOT M]- 2 | | | 3 | q001 -----|------|- 4 | | | 5 | q002 -----[CNOT L]- 6 | 7 | q003 -------------- 8 | 9 | creg ============== 10 | 11 | realigned with: [3, 1, 2, 0] 12 | q000 -[H]-[CNOT M]- 13 | | | 14 | q001 -----[CNOT L]- 15 | 16 | q002 -------------- 17 | 18 | q003 -------------- 19 | 20 | creg ============== 21 | 22 | q000 -[H]-[CNOT M]-[H]-[CNOT M]---------- 23 | | | | | 24 | q001 -----[CNOT L]-----[CNOT L]-[CNOT M]- 25 | | | 26 | q002 ---------------------------|------|- 27 | | | 28 | q003 ---------------------------[CNOT L]- 29 | 30 | q004 ------------------------------------ 31 | 32 | q005 ------------------------------------ 33 | 34 | creg ==================================== 35 | 36 | 37 | Initial State 38 | 000000 1.00000000+0.00000000j 39 | CREGISTER: 0000 40 | 41 | H Qubit[0] 42 | 000000 0.70710678+0.00000000j 43 | 000001 0.70710678+0.00000000j 44 | CREGISTER: 0000 45 | 46 | CNOT Qubit[0, 1] 47 | 000000 0.70710678+0.00000000j 48 | 000011 0.70710678+0.00000000j 49 | CREGISTER: 0000 50 | 51 | H Qubit[0] 52 | 000000 0.50000000+0.00000000j 53 | 000001 0.50000000+0.00000000j 54 | 000010 0.50000000+0.00000000j 55 | 000011 -0.50000000+0.00000000j 56 | CREGISTER: 0000 57 | 58 | CNOT Qubit[0, 1] 59 | 000000 0.50000000+0.00000000j 60 | 000001 -0.50000000+0.00000000j 61 | 000010 0.50000000+0.00000000j 62 | 000011 0.50000000+0.00000000j 63 | CREGISTER: 0000 64 | 65 | CNOT Qubit[1, 3] 66 | 000000 0.50000000+0.00000000j 67 | 000001 -0.50000000+0.00000000j 68 | 001010 0.50000000+0.00000000j 69 | 001011 0.50000000+0.00000000j 70 | CREGISTER: 0000 71 | ==Unitary test======================= 72 | Custom gate, CuCXx, operator matrix is not unitary. 73 | q000 ---------- 74 | 75 | q001 -[CuCX M]- 76 | | | 77 | q002 -|------|- 78 | | | 79 | q003 -[CuCX L]- 80 | 81 | q004 ---------- 82 | 83 | q005 ---------- 84 | 85 | creg ========== 86 | 87 | 88 | Initial State 89 | 000000 1.00000000+0.00000000j 90 | CREGISTER: 91 | 92 | CuCX Qubit[1, 3] 93 | 000000 1.00000000+0.00000000j 94 | CREGISTER: 95 | -------------------------------------------------------------------------------- /tests/qckt/expected/direct-qengine-dm.py.log: -------------------------------------------------------------------------------- 1 | q000 -[H]-[.]--#------#--v- 2 | | # # v 3 | q001 -----[X]--#------#--v- 4 | # # v 5 | q002 ----------#-[X]--#--v- 6 | # # v 7 | q003 ----------#-[X]--#--v- 8 | # # v 9 | creg ==========#======#==v= 10 | # # v 11 | WARNING: debugger simulator, multi-shot not supported. Falling back to shots=1. 12 | 13 | PROBE: point 1 14 | 1100 ... | 0.50000000+0.00000000j 15 | 1111 ... | 0.50000000+0.00000000j 16 | CREGISTER: 0000 17 | Density matrix DIAGONAL 18 | 1100 0.50000000+0.00000000j 19 | 1111 0.50000000+0.00000000j 20 | 21 | 0000 22 | -------------------------------------------------------------------------------- /tests/qckt/expected/direct-qengine.py.log: -------------------------------------------------------------------------------- 1 | q000 -[H]-[.]--#------#--v- 2 | | # # v 3 | q001 -----[X]--#------#--v- 4 | # # v 5 | q002 ----------#-[X]--#--v- 6 | # # v 7 | q003 ----------#-[X]--#--v- 8 | # # v 9 | creg ==========#======#==v= 10 | # # v 11 | WARNING: debugger simulator, multi-shot not supported. Falling back to shots=1. 12 | 13 | PROBE: point 1 14 | 1100 0.70710678+0.00000000j 15 | 1111 0.70710678+0.00000000j 16 | CREGISTER: 0000 17 | 1100 0.70710678+0.00000000j 18 | 1111 0.70710678+0.00000000j 19 | 20 | 0000 21 | -------------------------------------------------------------------------------- /tests/qckt/expected/noise-measurement-test.py.log: -------------------------------------------------------------------------------- 1 | bit_flip 2 | q000 -[H]-[H:BF(0.10)]-[.]-[CX:BF(0.10)]-------------------[M]- 3 | | | 4 | q001 ------------------[X]-[CX:BF(0.10)]-[.]-[CX:BF(0.10)]-[M]- 5 | | | 6 | q002 ------------------------------------[X]-[CX:BF(0.10)]-[M]- 7 | | 8 | creg =======================================================v== 9 | 10 | Measurements within margin of error? True 11 | -------------------------------------------------------------------------------- /tests/qckt/expected/noise-qengdeb-test.py.log: -------------------------------------------------------------------------------- 1 | added noise profile, but using Qdeb 2 | q000 -[INIT:PF(0.20)]-[X]-[X:Dep(0.10)]-[NS:BF(0.10)]-[.]---------------[CX:Dep(0.10)]--------------------------------[M]- 3 | | | 4 | q001 -[INIT:PF(0.20)]-------------------[NS:BF(0.10)]-[X]-[CX:BF(0.30)]-[CX:Dep(0.10)]--------------------------------[M]- 5 | | 6 | q002 -[INIT:PF(0.20)]-------------------[NS:BF(0.10)]----------------------------------[X]-[X:Dep(0.10)]-[X:PF(0.10)]-[M]- 7 | | 8 | creg ==================================================================================================================v== 9 | 10 | 11 | Initial State 12 | 000 1.00000000+0.00000000j 13 | CREGISTER: 000 14 | 15 | X Qubit[0] 16 | 001 1.00000000+0.00000000j 17 | CREGISTER: 000 18 | 19 | CX Qubit[0, 1] 20 | 011 1.00000000+0.00000000j 21 | CREGISTER: 000 22 | 23 | X Qubit[2] 24 | 111 1.00000000+0.00000000j 25 | CREGISTER: 000 26 | 27 | MEASURED Qubit[2, 1, 0] = [1, 1, 1] with probability = 1.0 28 | 111 1.00000000+0.00000000j 29 | CREGISTER: 111 30 | READ OUT STATE VECTOR: 31 | 111 1.00000000+0.00000000j 32 | 33 | READ OUT CREG: 34 | 111 35 | [0, 0, 0, 0, 0, 0, 0, 1] 36 | 37 | added noise profile, but using Qeng 38 | q000 -[INIT:PF(0.20)]-[X]-[X:Dep(0.10)]-[NS:BF(0.10)]-[.]---------------[CX:Dep(0.10)]--------------------------------[M]- 39 | | | 40 | q001 -[INIT:PF(0.20)]-------------------[NS:BF(0.10)]-[X]-[CX:BF(0.30)]-[CX:Dep(0.10)]--------------------------------[M]- 41 | | 42 | q002 -[INIT:PF(0.20)]-------------------[NS:BF(0.10)]----------------------------------[X]-[X:Dep(0.10)]-[X:PF(0.10)]-[M]- 43 | | 44 | creg ==================================================================================================================v== 45 | 46 | READ OUT STATE VECTOR: 47 | None 48 | READ OUT CREG: 49 | 111 50 | [0, 0, 0, 0, 0, 0, 0, 100] 51 | -------------------------------------------------------------------------------- /tests/qckt/expected/opmatrix-tests-dm.py.log: -------------------------------------------------------------------------------- 1 | q000 -[X]-[H]-[.]------------------v- 2 | | v 3 | q001 -[X]-----[.]-------------[.]--v- 4 | | | v 5 | q002 ---------[X]-[P]---[.]---[.]--v- 6 | | | v 7 | q003 -----------------[UROTk]-[X]--v- 8 | v 9 | creg ==============================v= 10 | v 11 | 12 | PROBE: Expanded Circuit 13 | 0010 ... | 0.50000000+0.00000000j 14 | 1111 ... | 0.50000000+0.00000000j 15 | CREGISTER: 16 | ==================================== 17 | q000 -[CKT L]--v- 18 | | | v 19 | q001 -[CKT ]--v- 20 | | | v 21 | q002 -[CKT ]--v- 22 | | | v 23 | q003 -[CKT M]--v- 24 | v 25 | creg ==========v= 26 | v 27 | 28 | PROBE: Circuit to_opMatrix() 29 | 0010 ... | 0.50000000+0.00000000j 30 | 1111 ... | 0.50000000+0.00000000j 31 | CREGISTER: 32 | 33 | =================== 34 | BOTH SVECS ARE SAME 35 | =================== 36 | -------------------------------------------------------------------------------- /tests/qckt/expected/opmatrix-tests.py.log: -------------------------------------------------------------------------------- 1 | q000 -[X]-[H]-[.]------------------v- 2 | | v 3 | q001 -[X]-----[.]-------------[.]--v- 4 | | | v 5 | q002 ---------[X]-[P]---[.]---[.]--v- 6 | | | v 7 | q003 -----------------[UROTk]-[X]--v- 8 | v 9 | creg ==============================v= 10 | v 11 | 12 | PROBE: Expanded Circuit 13 | 0010 0.70710678+0.00000000j 14 | 1111 -0.00056309-0.70710656j 15 | CREGISTER: 16 | ==================================== 17 | q000 -[CKT L]--v- 18 | | | v 19 | q001 -[CKT ]--v- 20 | | | v 21 | q002 -[CKT ]--v- 22 | | | v 23 | q003 -[CKT M]--v- 24 | v 25 | creg ==========v= 26 | v 27 | 28 | PROBE: Circuit to_opMatrix() 29 | 0010 0.70710678+0.00000000j 30 | 1111 -0.00056309-0.70710656j 31 | CREGISTER: 32 | 33 | =================== 34 | BOTH SVECS ARE SAME 35 | =================== 36 | -------------------------------------------------------------------------------- /tests/qckt/expected/realign-test-dm.py.log: -------------------------------------------------------------------------------- 1 | q000 -[X]--------- 2 | 3 | q001 -----[H]----- 4 | 5 | q002 ---------[X]- 6 | | 7 | q003 ---------[.]- 8 | 9 | creg ============= 10 | 11 | Realigned with: [4, 5, 2, 3] 12 | q000 ------------- 13 | 14 | q001 ------------- 15 | 16 | q002 -----[H]----- 17 | 18 | q003 -[X]--------- 19 | 20 | q004 ---------[.]- 21 | | 22 | q005 ---------[X]- 23 | 24 | creg ============= 25 | 26 | Initial State 27 | 000000 ... | 1.0000+0.0000j 28 | Mixed State Purity: 1.0000 29 | CREGISTER: 000000 30 | 31 | X Qubit[3] 32 | 001000 ... | 1.0000+0.0000j 33 | Mixed State Purity: 1.0000 34 | CREGISTER: 000000 35 | 36 | H Qubit[2] 37 | 001000 ... | 0.5000+0.0000j 38 | 001100 ... | 0.5000+0.0000j 39 | Mixed State Purity: 1.0000 40 | CREGISTER: 000000 41 | 42 | CX Qubit[4, 5] 43 | 001000 ... | 0.5000+0.0000j 44 | 001100 ... | 0.5000+0.0000j 45 | Mixed State Purity: 1.0000 46 | CREGISTER: 000000 47 | 48 | STATE VECTOR READ OUT 49 | Density matrix DIAGONAL 50 | 001000 0.50000000+0.00000000j 51 | 001100 0.50000000+0.00000000j 52 | 53 | CREGISTER READ OUT 54 | 000000 55 | -------------------------------------------------------------------------------- /tests/qckt/expected/realign-test.py.log: -------------------------------------------------------------------------------- 1 | q000 -[X]--------- 2 | 3 | q001 -----[H]----- 4 | 5 | q002 ---------[X]- 6 | | 7 | q003 ---------[.]- 8 | 9 | creg ============= 10 | 11 | Realigned with: [4, 5, 2, 3] 12 | q000 ------------- 13 | 14 | q001 ------------- 15 | 16 | q002 -----[H]----- 17 | 18 | q003 -[X]--------- 19 | 20 | q004 ---------[.]- 21 | | 22 | q005 ---------[X]- 23 | 24 | creg ============= 25 | 26 | 27 | Initial State 28 | 000000 1.00000000+0.00000000j 29 | CREGISTER: 000000 30 | 31 | X Qubit[3] 32 | 001000 1.00000000+0.00000000j 33 | CREGISTER: 000000 34 | 35 | H Qubit[2] 36 | 001000 0.70710678+0.00000000j 37 | 001100 0.70710678+0.00000000j 38 | CREGISTER: 000000 39 | 40 | CX Qubit[4, 5] 41 | 001000 0.70710678+0.00000000j 42 | 001100 0.70710678+0.00000000j 43 | CREGISTER: 000000 44 | STATE VECTOR READ OUT 45 | 001000 0.70710678+0.00000000j 46 | 001100 0.70710678+0.00000000j 47 | 48 | CREGISTER READ OUT 49 | 000000 50 | -------------------------------------------------------------------------------- /tests/qckt/expected/registry-access-dm.py.log: -------------------------------------------------------------------------------- 1 | Services available 2 | QSystems : qsim simulator from Quantum Systems 3 | ------------------------- 4 | 5 | Using service: QSystems 6 | ------------------------- 7 | 8 | Instances available: 9 | qsim-eng 10 | qsim-deb 11 | dmqsim-eng 12 | dmqsim-deb 13 | ------------------------- 14 | 15 | Using instance: dmqsim-deb 16 | ------------------------- 17 | 18 | q000 -[H]-[.]--#------#--v- 19 | | # # v 20 | q001 -----[X]--#------#--v- 21 | # # v 22 | q002 ----------#-[X]--#--v- 23 | # # v 24 | q003 ----------#-[X]--#--v- 25 | # # v 26 | creg ==========#======#==v= 27 | # # v 28 | 29 | PROBE: point 1 30 | 1100 ... | 0.50000000+0.00000000j 31 | 1111 ... | 0.50000000+0.00000000j 32 | CREGISTER: 0000 33 | ------------------------------- 34 | printing results 35 | Density matrix DIAGONAL 36 | 1100 0.50000000+0.00000000j 37 | 1111 0.50000000+0.00000000j 38 | 39 | 0000 40 | -------------------------------------------------------------------------------- /tests/qckt/expected/registry-access.py.log: -------------------------------------------------------------------------------- 1 | Services available 2 | QSystems : qsim simulator from Quantum Systems 3 | ------------------------- 4 | 5 | Using service: QSystems 6 | ------------------------- 7 | 8 | Instances available: 9 | qsim-eng 10 | qsim-deb 11 | dmqsim-eng 12 | dmqsim-deb 13 | ------------------------- 14 | 15 | Using instance: qsim-deb 16 | ------------------------- 17 | 18 | q000 -[H]-[.]--#------#--v- 19 | | # # v 20 | q001 -----[X]--#------#--v- 21 | # # v 22 | q002 ----------#-[X]--#--v- 23 | # # v 24 | q003 ----------#-[X]--#--v- 25 | # # v 26 | creg ==========#======#==v= 27 | # # v 28 | 29 | PROBE: point 1 30 | 1100 0.70710678+0.00000000j 31 | 1111 0.70710678+0.00000000j 32 | CREGISTER: 0000 33 | ------------------------------- 34 | printing results 35 | 1100 0.70710678+0.00000000j 36 | 1111 0.70710678+0.00000000j 37 | 38 | 0000 39 | -------------------------------------------------------------------------------- /tests/qckt/expected/rgates-test-dm.py.log.1: -------------------------------------------------------------------------------- 1 | q000 -[X]-[H]--v-[Rx]- 2 | V 3 | creg ==========v====== 4 | V 5 | PROBE: 6 | 0 ... | 0.50000000+0.00000000j 7 | 1 ... | 0.50000000+0.00000000j 8 | CREGISTER: 9 | STATE VECTOR READ OUT 10 | Density matrix DIAGONAL 11 | 0 0.50000000+0.00000000j 12 | 1 0.50000000+0.00000000j 13 | 14 | CREGISTER READ OUT: 15 | 16 | q000 -[X]-[H]--v-[Ry]- 17 | V 18 | creg ==========v====== 19 | V 20 | PROBE: 21 | 0 ... | 0.50000000+0.00000000j 22 | 1 ... | 0.50000000+0.00000000j 23 | CREGISTER: 24 | STATE VECTOR READ OUT 25 | Density matrix DIAGONAL 26 | 1 1.00000000+0.00000000j 27 | 28 | CREGISTER READ OUT: 29 | 30 | q000 -[X]-[H]--v-[Rz]- 31 | V 32 | creg ==========v====== 33 | V 34 | PROBE: 35 | 0 ... | 0.50000000+0.00000000j 36 | 1 ... | 0.50000000+0.00000000j 37 | CREGISTER: 38 | STATE VECTOR READ OUT 39 | Density matrix DIAGONAL 40 | 0 0.50000000-0.00000000j 41 | 1 0.50000000+0.00000000j 42 | 43 | CREGISTER READ OUT: 44 | 45 | -------------------------------------------------------------------------------- /tests/qckt/expected/rgates-test-dm.py.log.2: -------------------------------------------------------------------------------- 1 | q000 -[X]-[H]--v-[Rx]- 2 | v 3 | creg ==========v====== 4 | v 5 | 6 | PROBE: 7 | 0 ... | 0.50000000+0.00000000j 8 | 1 ... | 0.50000000+0.00000000j 9 | CREGISTER: 10 | STATE VECTOR READ OUT 11 | Density matrix DIAGONAL 12 | 0 0.50000000+0.00000000j 13 | 1 0.50000000+0.00000000j 14 | 15 | CREGISTER READ OUT: 16 | 17 | q000 -[X]-[H]--v-[Ry]- 18 | v 19 | creg ==========v====== 20 | v 21 | 22 | PROBE: 23 | 0 ... | 0.50000000+0.00000000j 24 | 1 ... | 0.50000000+0.00000000j 25 | CREGISTER: 26 | STATE VECTOR READ OUT 27 | Density matrix DIAGONAL 28 | 1 1.00000000+0.00000000j 29 | 30 | CREGISTER READ OUT: 31 | 32 | q000 -[X]-[H]--v-[Rz]- 33 | v 34 | creg ==========v====== 35 | v 36 | 37 | PROBE: 38 | 0 ... | 0.50000000+0.00000000j 39 | 1 ... | 0.50000000+0.00000000j 40 | CREGISTER: 41 | STATE VECTOR READ OUT 42 | Density matrix DIAGONAL 43 | 0 0.50000000+0.00000000j 44 | 1 0.50000000+0.00000000j 45 | 46 | CREGISTER READ OUT: 47 | 48 | -------------------------------------------------------------------------------- /tests/qckt/expected/rgates-test.py.log: -------------------------------------------------------------------------------- 1 | q000 -[X]-[H]--v-[Rx]- 2 | v 3 | creg ==========v====== 4 | v 5 | 6 | PROBE: 7 | 0 0.70710678+0.00000000j 8 | 1 -0.70710678+0.00000000j 9 | CREGISTER: 10 | STATE VECTOR READ OUT 11 | 0 -0.50000000+0.50000000j 12 | 1 0.50000000-0.50000000j 13 | 14 | CREGISTER READ OUT: 15 | 16 | q000 -[X]-[H]--v-[Ry]- 17 | v 18 | creg ==========v====== 19 | v 20 | 21 | PROBE: 22 | 0 0.70710678+0.00000000j 23 | 1 -0.70710678+0.00000000j 24 | CREGISTER: 25 | STATE VECTOR READ OUT 26 | 1 1.00000000+0.00000000j 27 | 28 | CREGISTER READ OUT: 29 | 30 | q000 -[X]-[H]--v-[Rz]- 31 | v 32 | creg ==========v====== 33 | v 34 | 35 | PROBE: 36 | 0 0.70710678+0.00000000j 37 | 1 -0.70710678+0.00000000j 38 | CREGISTER: 39 | STATE VECTOR READ OUT 40 | 0 -0.50000000-0.50000000j 41 | 1 0.50000000-0.50000000j 42 | 43 | CREGISTER READ OUT: 44 | 45 | -------------------------------------------------------------------------------- /tests/qckt/expected/runstats-dm.py.log: -------------------------------------------------------------------------------- 1 | q000 -[X]------------------------- 2 | 3 | q001 -----[X]---------[H]-----[.]- 4 | | 5 | q002 ---------[X]---------[H]-[X]- 6 | 7 | q003 -------------[X]------------- 8 | 9 | creg ============================= 10 | 11 | Total steps 7 12 | op CX count 1 13 | op H count 2 14 | op X count 4 15 | -------------------------------------------------------------------------------- /tests/qckt/expected/runstats.py.log: -------------------------------------------------------------------------------- 1 | q000 -[X]------------------------- 2 | 3 | q001 -----[X]---------[H]-----[.]- 4 | | 5 | q002 ---------[X]---------[H]-[X]- 6 | 7 | q003 -------------[X]------------- 8 | 9 | creg ============================= 10 | 11 | Total steps 7 12 | op CX count 1 13 | op H count 2 14 | op X count 4 15 | -------------------------------------------------------------------------------- /tests/qckt/gates-test-dm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import qckt 3 | from qckt.backend import * 4 | 5 | # Test 01 6 | ck = qckt.QCkt(4) 7 | ck.X(0) 8 | ck.H(1) 9 | ck.CX(1,2) 10 | ck.draw() 11 | job = qckt.Job(ck) 12 | DMQdeb().runjob(job) 13 | print("STATE VECTOR READ OUT") 14 | print(job.get_svec()) 15 | print("CREGISTER READ OUT: ",end="") 16 | print() 17 | print(job.get_creg()[0]) 18 | 19 | # Test 02 20 | ck = qckt.QCkt(4) 21 | ck.X(0) 22 | ck.H(1) 23 | ck.H(2) 24 | ck.CCX(1,2,3) 25 | ck.draw() 26 | job = qckt.Job(ck) 27 | DMQdeb().runjob(job) 28 | print("STATE VECTOR READ OUT") 29 | print(job.get_svec()) 30 | print("CREGISTER READ OUT: ",end="") 31 | print() 32 | print(job.get_creg()[0]) 33 | 34 | # Test 03 35 | ck = qckt.QCkt(4,4) 36 | ck.X(0) 37 | ck.X(1) 38 | ck.X(2) 39 | ck.X(0) 40 | ck.Y(1) 41 | ck.Z(2) 42 | ck.M([2,1,0]) 43 | ck.draw() 44 | job = qckt.Job(ck) 45 | DMQdeb().runjob(job) 46 | print("STATE VECTOR READ OUT") 47 | print(job.get_svec()) 48 | print("CREGISTER READ OUT: ",end="") 49 | print() 50 | print(job.get_creg()[0]) 51 | 52 | # Test 04 53 | ck = qckt.QCkt(6) 54 | ck.X(0) 55 | ck.X(1) 56 | ck.X(4) 57 | ck.P(np.pi/4.0,0) 58 | ck.CP(np.pi/4.0,1,4) 59 | ck.CP(np.pi/4.0,2,5) 60 | ck.draw() 61 | job = qckt.Job(ck) 62 | DMQdeb().runjob(job) 63 | print("STATE VECTOR READ OUT") 64 | print(job.get_svec()) 65 | print("CREGISTER READ OUT: ",end="") 66 | print() 67 | print(job.get_creg()[0]) 68 | 69 | # Test 05 70 | ck = qckt.QCkt(6) 71 | ck.X(0) 72 | ck.UROTk(3,0) 73 | ck.SWAP(0,4) 74 | ck.draw() 75 | job = qckt.Job(ck) 76 | DMQdeb().runjob(job) 77 | print("STATE VECTOR READ OUT") 78 | print(job.get_svec()) 79 | print("CREGISTER READ OUT: ",end="") 80 | print() 81 | print(job.get_creg()[0]) 82 | 83 | # Test 06 84 | ck = qckt.QCkt(6) 85 | ck.X(0) 86 | ck.X(2) 87 | ck.X(4) 88 | ck.Border() 89 | ck.QFT(4,3,2,1,0) 90 | ck.Border() 91 | ck.draw() 92 | job = qckt.Job(ck) 93 | DMQdeb().runjob(job) 94 | print("STATE VECTOR READ OUT") 95 | print(job.get_svec()) 96 | print("CREGISTER READ OUT: ",end="") 97 | print() 98 | print(job.get_creg()[0]) 99 | -------------------------------------------------------------------------------- /tests/qckt/gates-test.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import qckt 3 | from qckt.backend import * 4 | 5 | # Test 01 6 | ck = qckt.QCkt(4) 7 | ck.X(0) 8 | ck.H(1) 9 | ck.CX(1,2) 10 | ck.draw() 11 | job = qckt.Job(ck) 12 | Qdeb().runjob(job) 13 | print("STATE VECTOR READ OUT") 14 | print(job.get_svec()) 15 | print("CREGISTER READ OUT: ",end="") 16 | print() 17 | print(job.get_creg()[0]) 18 | 19 | # Test 02 20 | ck = qckt.QCkt(4) 21 | ck.X(0) 22 | ck.H(1) 23 | ck.H(2) 24 | ck.CCX(1,2,3) 25 | ck.draw() 26 | job = qckt.Job(ck) 27 | Qdeb().runjob(job) 28 | print("STATE VECTOR READ OUT") 29 | print(job.get_svec()) 30 | print("CREGISTER READ OUT: ",end="") 31 | print() 32 | print(job.get_creg()[0]) 33 | 34 | # Test 03 35 | ck = qckt.QCkt(4,4) 36 | ck.X(0) 37 | ck.X(1) 38 | ck.X(2) 39 | ck.X(0) 40 | ck.Y(1) 41 | ck.Z(2) 42 | ck.M([2,1,0]) 43 | ck.draw() 44 | job = qckt.Job(ck) 45 | Qdeb().runjob(job) 46 | print("STATE VECTOR READ OUT") 47 | print(job.get_svec()) 48 | print("CREGISTER READ OUT: ",end="") 49 | print() 50 | print(job.get_creg()[0]) 51 | 52 | # Test 04 53 | ck = qckt.QCkt(6) 54 | ck.X(0) 55 | ck.X(1) 56 | ck.X(4) 57 | ck.P(np.pi/4.0,0) 58 | ck.CP(np.pi/4.0,1,4) 59 | ck.CP(np.pi/4.0,2,5) 60 | ck.draw() 61 | job = qckt.Job(ck) 62 | Qdeb().runjob(job) 63 | print("STATE VECTOR READ OUT") 64 | print(job.get_svec()) 65 | print("CREGISTER READ OUT: ",end="") 66 | print() 67 | print(job.get_creg()[0]) 68 | 69 | # Test 05 70 | ck = qckt.QCkt(6) 71 | ck.X(0) 72 | ck.UROTk(3,0) 73 | ck.SWAP(0,4) 74 | ck.draw() 75 | job = qckt.Job(ck) 76 | Qdeb().runjob(job) 77 | print("STATE VECTOR READ OUT") 78 | print(job.get_svec()) 79 | print("CREGISTER READ OUT: ",end="") 80 | print() 81 | print(job.get_creg()[0]) 82 | 83 | # Test 06 84 | ck = qckt.QCkt(6) 85 | ck.X(0) 86 | ck.X(2) 87 | ck.X(4) 88 | ck.Border() 89 | ck.QFT(4,3,2,1,0) 90 | ck.Border() 91 | ck.draw() 92 | job = qckt.Job(ck) 93 | Qdeb().runjob(job) 94 | print("STATE VECTOR READ OUT") 95 | print(job.get_svec()) 96 | print("CREGISTER READ OUT: ",end="") 97 | print() 98 | print(job.get_creg()[0]) 99 | -------------------------------------------------------------------------------- /tests/qckt/noise-measurement-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import qckt.backend as bknd 5 | import qckt.noisemodel as ns 6 | 7 | def ghz_ck(n_qubits: int): 8 | ck = qckt.QCkt(n_qubits, n_qubits) 9 | ck.H(0) 10 | for ii in range(0, n_qubits-1): 11 | ck.CX(ii,ii+1) 12 | ck.M(list(range(n_qubits))) 13 | return ck 14 | 15 | print('bit_flip') 16 | ck = ghz_ck(3) 17 | noiseop = ns.bit_flip(0.1) 18 | noise_profile = ns.NoiseProfile(noise_chan_allgates=ns.NoiseChannelSequence(noiseop)) 19 | ck.set_noise_profile(noise_profile=noise_profile) 20 | ck.draw() 21 | shots = 10000 22 | job = qckt.Job(ck, shots=shots) 23 | bk = bknd.DMQeng() 24 | bk.runjob(job=job) 25 | creg_counts = job.get_counts() 26 | creg_pct = [float(ct)/shots for ct in creg_counts] 27 | # print(creg_pct) 28 | 29 | expected_pct = [ 30 | 0.33300000, 31 | 0.07700000, 32 | 0.04500000, 33 | 0.04500000, 34 | 0.04500000, 35 | 0.04500000, 36 | 0.07700000, 37 | 0.33300000, 38 | ] 39 | 40 | # basic sanity test 41 | allerrors = [] 42 | margin_allowed = 0.1 43 | looksgood = True 44 | for i,e in enumerate(expected_pct): 45 | errval = abs(creg_pct[i]-e)/e 46 | allerrors.append(errval) 47 | if errval > margin_allowed: 48 | looksgood = False 49 | 50 | print(f'Measurements within margin of error? {looksgood}') 51 | if not looksgood: 52 | print('Errors in %') 53 | for i,e in enumerate(allerrors): 54 | print(f' {i:03b} {e*100:.2f}%') 55 | 56 | # Expected measurements 57 | # 000 0.33300000+0.00000000j 58 | # 001 0.07700000+0.00000000j 59 | # 010 0.04500000+0.00000000j 60 | # 011 0.04500000+0.00000000j 61 | # 100 0.04500000+0.00000000j 62 | # 101 0.04500000+0.00000000j 63 | # 110 0.07700000+0.00000000j 64 | # 111 0.33300000+0.00000000j -------------------------------------------------------------------------------- /tests/qckt/noise-model-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import qckt.noisemodel as ns 5 | import qckt.backend as bknd 6 | 7 | print('01 adding noise at init, applied to specifc qubits, all gates, all steps') 8 | noise_profile = ns.NoiseProfile( 9 | noise_chan_init=ns.NoiseChannelSequence(ns.phase_flip(probability=0.2)), 10 | noise_chan_allgates=ns.NoiseChannelSequence(ns.depolarizing(probability=0.1)), 11 | noise_chan_qubits=ns.NoiseChannelApplierSequense(ns.NoiseChannelSequence(ns.bit_flip(probability=0.3)),[1]), 12 | noise_chan_allsteps=ns.NoiseChannelApplierSequense(noise_chan=ns.amplitude_damping(gamma=0.1),qubit_list=[0,1]), 13 | ) 14 | 15 | ck = qckt.QCkt(2,2) 16 | ck.H(0) 17 | ck.CX(0,1) 18 | 19 | ck.set_noise_profile(noise_profile=noise_profile) 20 | ck.draw() 21 | 22 | job = qckt.Job(circuit=ck,qtrace=True) 23 | bk = bknd.DMQdeb() 24 | bk.runjob(job=job) 25 | 26 | 27 | print('02 noise at init') 28 | noise_profile = ns.NoiseProfile( 29 | noise_chan_init=ns.NoiseChannelSequence(ns.phase_flip(probability=0.2)), 30 | ) 31 | 32 | ck = qckt.QCkt(2,2) 33 | ck.H(0) 34 | ck.CX(0,1) 35 | 36 | ck.set_noise_profile(noise_profile=noise_profile) 37 | ck.draw() 38 | 39 | job = qckt.Job(circuit=ck,qtrace=True) 40 | bk = bknd.DMQdeb() 41 | bk.runjob(job=job) 42 | 43 | 44 | print('03 noise applied to specifc qubits') 45 | noise_profile = ns.NoiseProfile( 46 | noise_chan_qubits=ns.NoiseChannelApplierSequense(ns.NoiseChannelSequence(ns.bit_flip(probability=0.3)),[1]), 47 | ) 48 | 49 | ck = qckt.QCkt(2,2) 50 | ck.H(0) 51 | ck.CX(0,1) 52 | 53 | ck.set_noise_profile(noise_profile=noise_profile) 54 | ck.draw() 55 | 56 | job = qckt.Job(circuit=ck,qtrace=True) 57 | bk = bknd.DMQdeb() 58 | bk.runjob(job=job) 59 | 60 | 61 | 62 | print('04 noise on all gates') 63 | noise_profile = ns.NoiseProfile( 64 | noise_chan_allgates=ns.NoiseChannelSequence(ns.depolarizing(probability=0.1)), 65 | ) 66 | 67 | ck = qckt.QCkt(2,2) 68 | ck.H(0) 69 | ck.CX(0,1) 70 | 71 | ck.set_noise_profile(noise_profile=noise_profile) 72 | ck.draw() 73 | 74 | job = qckt.Job(circuit=ck,qtrace=True) 75 | bk = bknd.DMQdeb() 76 | bk.runjob(job=job) 77 | 78 | 79 | 80 | print('05 noise at all steps') 81 | noise_profile = ns.NoiseProfile( 82 | noise_chan_allsteps=ns.NoiseChannelApplierSequense(noise_chan=ns.bit_flip(probability=0.1),qubit_list=[0,1]), 83 | ) 84 | 85 | ck = qckt.QCkt(2,2) 86 | ck.H(0) 87 | ck.CX(0,1) 88 | 89 | ck.set_noise_profile(noise_profile=noise_profile) 90 | ck.draw() 91 | 92 | job = qckt.Job(circuit=ck,qtrace=True) 93 | bk = bknd.DMQdeb() 94 | bk.runjob(job=job) -------------------------------------------------------------------------------- /tests/qckt/noise-op-vs-seq.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import qckt.backend as bknd 5 | import qckt.noisemodel as ns 6 | 7 | 8 | print('test 01 - DMQdeb, All NoiseChannelSequence') 9 | ck = qckt.QCkt(3,3) 10 | ck.X([0]) 11 | ck.NOISE(noise_chan=ns.NoiseChannelSequence(ns.bit_flip(probability=0.1)),qbit=[0,1,2]) 12 | ck.CX(0,1) 13 | ck.X([2]).set_noise(ns.NoiseChannelSequence(ns.phase_flip(probability=0.1))) 14 | ck.H([2]) 15 | noise_profile = ns.NoiseProfile( 16 | noise_chan_init=ns.NoiseChannelSequence(ns.phase_flip(probability=0.2)), 17 | noise_chan_allgates=ns.NoiseChannelSequence(ns.depolarizing(probability=0.1)), 18 | noise_chan_qubits=ns.NoiseChannelApplierSequense(ns.NoiseChannelSequence(ns.bit_flip(probability=0.3)),[1]), 19 | ) 20 | ck.set_noise_profile(noise_profile=noise_profile) 21 | ck.draw(show_noise=False) 22 | ck.draw() 23 | job = qckt.Job(ck,qtrace=True, verbose=False) 24 | bk = bknd.DMQdeb() 25 | bk.runjob(job) 26 | svec = job.get_svec() 27 | print("READ OUT STATE VECTOR: ") 28 | print(svec) 29 | 30 | 31 | print('test 02 - DMQdeb, All NoiseChannelSequence') 32 | ck = qckt.QCkt(3,3) 33 | ck.X([0]) 34 | ck.NOISE(noise_chan=ns.bit_flip(probability=0.1),qbit=[0,1,2]) 35 | ck.CX(0,1) 36 | ck.X([2]).set_noise(ns.phase_flip(probability=0.1)) 37 | ck.H([2]) 38 | noise_profile = ns.NoiseProfile( 39 | noise_chan_init=ns.phase_flip(probability=0.2), 40 | noise_chan_allgates=ns.depolarizing(probability=0.1), 41 | noise_chan_qubits=ns.NoiseChannelApplierSequense(ns.bit_flip(probability=0.3),[1]), 42 | ) 43 | ck.set_noise_profile(noise_profile=noise_profile) 44 | ck.draw(show_noise=False) 45 | ck.draw() 46 | job = qckt.Job(ck,qtrace=True, verbose=False) 47 | bk = bknd.DMQdeb() 48 | bk.runjob(job) 49 | svec = job.get_svec() 50 | print("READ OUT STATE VECTOR: ") 51 | print(svec) 52 | 53 | 54 | print('test 03 - DMQeng, All NoiseChannelSequence') 55 | ck = qckt.QCkt(3,3) 56 | ck.X([0]) 57 | ck.NOISE(noise_chan=ns.NoiseChannelSequence(ns.bit_flip(probability=0.1)),qbit=[0,1,2]) 58 | ck.CX(0,1) 59 | ck.X([2]).set_noise(ns.NoiseChannelSequence(ns.phase_flip(probability=0.1))) 60 | ck.H([2]) 61 | noise_profile = ns.NoiseProfile( 62 | noise_chan_init=ns.NoiseChannelSequence(ns.phase_flip(probability=0.2)), 63 | noise_chan_allgates=ns.NoiseChannelSequence(ns.depolarizing(probability=0.1)), 64 | noise_chan_qubits=ns.NoiseChannelApplierSequense(ns.NoiseChannelSequence(ns.bit_flip(probability=0.3)),[1]), 65 | ) 66 | ck.set_noise_profile(noise_profile=noise_profile) 67 | ck.draw(show_noise=False) 68 | ck.draw() 69 | job = qckt.Job(ck,qtrace=False, verbose=False) 70 | bk = bknd.DMQeng() 71 | bk.runjob(job) 72 | svec = job.get_svec() 73 | print("READ OUT STATE VECTOR: ") 74 | print(svec) 75 | 76 | 77 | print('test 04 - DMQeng, All NoiseChannelSequence') 78 | ck = qckt.QCkt(3,3) 79 | ck.X([0]) 80 | ck.NOISE(noise_chan=ns.bit_flip(probability=0.1),qbit=[0,1,2]) 81 | ck.CX(0,1) 82 | ck.X([2]).set_noise(ns.phase_flip(probability=0.1)) 83 | ck.H([2]) 84 | noise_profile = ns.NoiseProfile( 85 | noise_chan_init=ns.phase_flip(probability=0.2), 86 | noise_chan_allgates=ns.depolarizing(probability=0.1), 87 | noise_chan_qubits=ns.NoiseChannelApplierSequense(ns.bit_flip(probability=0.3),[1]), 88 | ) 89 | ck.set_noise_profile(noise_profile=noise_profile) 90 | ck.draw(show_noise=False) 91 | ck.draw() 92 | job = qckt.Job(ck,qtrace=False, verbose=False) 93 | bk = bknd.DMQeng() 94 | bk.runjob(job) 95 | svec = job.get_svec() 96 | print("READ OUT STATE VECTOR: ") 97 | print(svec) 98 | -------------------------------------------------------------------------------- /tests/qckt/noise-qengdeb-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import qckt.backend as bknd 5 | import qckt.noisemodel as ns 6 | 7 | # added noise profile, but using Qdeb 8 | print('added noise profile, but using Qdeb') 9 | ck = qckt.QCkt(3,3) 10 | ck.X([0]) 11 | ck.NOISE(noise_chan=ns.NoiseChannelSequence(ns.bit_flip(probability=0.1)),qbit=[0,1,2]) 12 | ck.CX(0,1) 13 | ck.X([2]).set_noise(ns.NoiseChannelSequence(ns.phase_flip(probability=0.1))) 14 | # ck.H([2]) 15 | ck.M([2,1,0]) 16 | noise_profile = ns.NoiseProfile( 17 | noise_chan_init=ns.NoiseChannelSequence(ns.phase_flip(probability=0.2)), 18 | noise_chan_allgates=ns.NoiseChannelSequence(ns.depolarizing(probability=0.1)), 19 | noise_chan_qubits=ns.NoiseChannelApplierSequense(ns.NoiseChannelSequence(ns.bit_flip(probability=0.3)),[1]), 20 | ) 21 | ck.set_noise_profile(noise_profile=noise_profile) 22 | ck.draw() 23 | job = qckt.Job(ck,qtrace=True, verbose=True) 24 | bk = bknd.Qdeb() 25 | bk.runjob(job) 26 | svec = job.get_svec() 27 | creg = job.get_creg() 28 | cnum = job.get_counts() 29 | print("READ OUT STATE VECTOR: ") 30 | print(svec) 31 | print("READ OUT CREG: ") 32 | print(creg[0]) 33 | print(cnum) 34 | print() 35 | 36 | # added noise profile, but using Qeng 37 | print('added noise profile, but using Qeng') 38 | ck = qckt.QCkt(3,3) 39 | ck.X([0]) 40 | ck.NOISE(noise_chan=ns.NoiseChannelSequence(ns.bit_flip(probability=0.1)),qbit=[0,1,2]) 41 | ck.CX(0,1) 42 | ck.X([2]).set_noise(ns.NoiseChannelSequence(ns.phase_flip(probability=0.1))) 43 | # ck.H([2]) 44 | ck.M([2,1,0]) 45 | noise_profile = ns.NoiseProfile( 46 | noise_chan_init=ns.NoiseChannelSequence(ns.phase_flip(probability=0.2)), 47 | noise_chan_allgates=ns.NoiseChannelSequence(ns.depolarizing(probability=0.1)), 48 | noise_chan_qubits=ns.NoiseChannelApplierSequense(ns.NoiseChannelSequence(ns.bit_flip(probability=0.3)),[1]), 49 | ) 50 | ck.set_noise_profile(noise_profile=noise_profile) 51 | ck.draw() 52 | job = qckt.Job(ck,qtrace=True, verbose=True, shots=100) 53 | bk = bknd.Qeng() 54 | bk.runjob(job) 55 | svec = job.get_svec() 56 | creg = job.get_creg() 57 | cnum = job.get_counts() 58 | print("READ OUT STATE VECTOR: ") 59 | print(svec) 60 | print("READ OUT CREG: ") 61 | print(creg[0]) 62 | print(cnum) 63 | -------------------------------------------------------------------------------- /tests/qckt/noise-quant.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import qckt.backend as bknd 5 | import qckt.noisemodel as ns 6 | 7 | def ghz_ck(n_qubits: int): 8 | ck = qckt.QCkt(n_qubits) 9 | ck.H(0) 10 | for ii in range(0, n_qubits-1): 11 | ck.CX(ii,ii+1) 12 | return ck 13 | 14 | print('bit_flip') 15 | ck = ghz_ck(3) 16 | noiseop = ns.bit_flip(0.1) 17 | noise_profile = ns.NoiseProfile(noise_chan_allgates=ns.NoiseChannelSequence(noiseop)) 18 | ck.set_noise_profile(noise_profile=noise_profile) 19 | ck.draw() 20 | job = qckt.Job(ck) 21 | bk = bknd.DMQdeb() 22 | bk.runjob(job=job) 23 | svec = job.get_svec() 24 | print(svec) 25 | 26 | print('depolarizing') 27 | ck = ghz_ck(3) 28 | noiseop = ns.depolarizing(0.1) 29 | noise_profile = ns.NoiseProfile(noise_chan_allgates=ns.NoiseChannelSequence(noiseop)) 30 | ck.set_noise_profile(noise_profile=noise_profile) 31 | ck.draw() 32 | job = qckt.Job(ck) 33 | bk = bknd.DMQdeb() 34 | bk.runjob(job=job) 35 | svec = job.get_svec() 36 | print(svec) 37 | 38 | print('phase_flip') 39 | ck = ghz_ck(3) 40 | noiseop = ns.phase_flip(0.1) 41 | noise_profile = ns.NoiseProfile(noise_chan_allgates=ns.NoiseChannelSequence(noiseop)) 42 | ck.set_noise_profile(noise_profile=noise_profile) 43 | ck.draw() 44 | job = qckt.Job(ck) 45 | bk = bknd.DMQdeb() 46 | bk.runjob(job=job) 47 | svec = job.get_svec() 48 | print(svec) 49 | 50 | print('amplitude_damping') 51 | ck = ghz_ck(3) 52 | noiseop = ns.amplitude_damping(0.1) 53 | noise_profile = ns.NoiseProfile(noise_chan_allgates=ns.NoiseChannelSequence(noiseop)) 54 | ck.set_noise_profile(noise_profile=noise_profile) 55 | ck.draw() 56 | job = qckt.Job(ck) 57 | bk = bknd.DMQdeb() 58 | bk.runjob(job=job) 59 | svec = job.get_svec() 60 | print(svec) 61 | 62 | print('generalized amplitude_damping') 63 | ck = ghz_ck(3) 64 | noiseop = ns.generalized_amplitude_damping(gamma=0.1, probability=0.1) 65 | noise_profile = ns.NoiseProfile(noise_chan_allgates=ns.NoiseChannelSequence(noiseop)) 66 | ck.set_noise_profile(noise_profile=noise_profile) 67 | ck.draw() 68 | job = qckt.Job(ck) 69 | bk = bknd.DMQdeb() 70 | bk.runjob(job=job) 71 | svec = job.get_svec() 72 | print(svec) 73 | 74 | print('phase_damping') 75 | ck = ghz_ck(3) 76 | noiseop = ns.phase_damping(gamma=0.1) 77 | noise_profile = ns.NoiseProfile(noise_chan_allgates=ns.NoiseChannelSequence(noiseop)) 78 | ck.set_noise_profile(noise_profile=noise_profile) 79 | ck.draw() 80 | job = qckt.Job(ck) 81 | bk = bknd.DMQdeb() 82 | bk.runjob(job=job) 83 | svec = job.get_svec() 84 | print(svec) 85 | 86 | print('pauli_channel') 87 | ck = ghz_ck(3) 88 | noiseop = ns.pauli_channel(probx=0.1, proby=0.2, probz=0.3) 89 | noise_profile = ns.NoiseProfile(noise_chan_allgates=ns.NoiseChannelSequence(noiseop)) 90 | ck.set_noise_profile(noise_profile=noise_profile) 91 | ck.draw() 92 | job = qckt.Job(ck) 93 | bk = bknd.DMQdeb() 94 | bk.runjob(job=job) 95 | svec = job.get_svec() 96 | print(svec) 97 | 98 | print('two_qubit_dephasing') 99 | ck = qckt.QCkt(2,2) 100 | ck.H([0,1]) 101 | ck.NOISE(ns.two_qubit_dephasing(probability=0.1),[0,1]) 102 | ck.H([0,1]) 103 | ck.draw() 104 | job = qckt.Job(ck) 105 | bk = bknd.DMQdeb() 106 | bk.runjob(job=job) 107 | svec = job.get_svec() 108 | print(svec) 109 | 110 | print('two_qubit_depolarizing') 111 | ck = qckt.QCkt(2,2) 112 | ck.H(0) 113 | ck.CX(0,1) 114 | ck.CX.set_noise_on_all(ns.two_qubit_depolarizing(probability=0.1)) 115 | ck.draw() 116 | job = qckt.Job(ck) 117 | bk = bknd.DMQdeb() 118 | bk.runjob(job=job) 119 | svec = job.get_svec() 120 | print(svec) 121 | -------------------------------------------------------------------------------- /tests/qckt/opmatrix-tests-dm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import qckt 3 | from qckt.backend import * 4 | 5 | ck1 = qckt.QCkt(4) 6 | ck1.X([0,1]) 7 | ck1.H(0) 8 | ck1.CX(0,1,2) 9 | ck1.P(3.14/2,2) 10 | ck1.CROTk(4,2,3) 11 | ck1.CCX(1,2,3) 12 | ck1.Probe("Expanded Circuit") 13 | ck1.draw() 14 | op = ck1.to_opMatrix() 15 | 16 | job1 = qckt.Job(ck1) 17 | bk = DMQdeb() 18 | bk.runjob(job1) 19 | svec1 = job1.get_svec() 20 | 21 | print("====================================") 22 | 23 | qckt.define_gate("CKT",op) 24 | 25 | ck2 = qckt.QCkt(4) 26 | ck2.CKT(3,2,1,0) 27 | ck2.Probe("Circuit to_opMatrix()") 28 | ck2.draw() 29 | 30 | job2 = qckt.Job(ck2) 31 | bk = DMQdeb() 32 | bk.runjob(job2) 33 | svec2 = job2.get_svec() 34 | 35 | 36 | ### compare the two svecs 37 | res = True 38 | if len(svec1.value) != len(svec2.value): 39 | print("ERROR - svecs are different - lengths unequal",len(svec1),len(svec2)) 40 | res = False 41 | else: 42 | for i in range(len(svec1.value)): 43 | if np.around(svec1.value[i][i],6) != np.around(svec2.value[i][i],6): 44 | print("ERROR - svecs are different",i,": ",svec1.value[i][i], " != ",svec2.value[i][i]) 45 | res = False 46 | if res: 47 | print() 48 | print("===================") 49 | print("BOTH SVECS ARE SAME") 50 | print("===================") 51 | -------------------------------------------------------------------------------- /tests/qckt/opmatrix-tests.py: -------------------------------------------------------------------------------- 1 | import qckt 2 | from qckt.backend import * 3 | 4 | ck1 = qckt.QCkt(4) 5 | ck1.X([0,1]) 6 | ck1.H(0) 7 | ck1.CX(0,1,2) 8 | ck1.P(3.14/2,2) 9 | ck1.CROTk(4,2,3) 10 | ck1.CCX(1,2,3) 11 | ck1.Probe("Expanded Circuit") 12 | ck1.draw() 13 | op = ck1.to_opMatrix() 14 | 15 | job1 = qckt.Job(ck1) 16 | bk = Qdeb() 17 | bk.runjob(job1) 18 | svec1 = job1.get_svec() 19 | 20 | print("====================================") 21 | 22 | qckt.define_gate("CKT",op) 23 | 24 | ck2 = qckt.QCkt(4) 25 | ck2.CKT(3,2,1,0) 26 | ck2.Probe("Circuit to_opMatrix()") 27 | ck2.draw() 28 | 29 | job2 = qckt.Job(ck2) 30 | bk = Qdeb() 31 | bk.runjob(job2) 32 | svec2 = job2.get_svec() 33 | 34 | 35 | ### compare the two svecs 36 | res = True 37 | if len(svec1.value) != len(svec2.value): 38 | print("ERROR - svecs are different - lengths unequal",len(svec1),len(svec2)) 39 | res = False 40 | else: 41 | for i in range(len(svec1.value)): 42 | if svec1.value[i] != svec2.value[i]: 43 | print("ERROR - svecs are different",i,": ",svec1.value[i], " != ",svec2.value[i]) 44 | res = False 45 | if res: 46 | print() 47 | print("===================") 48 | print("BOTH SVECS ARE SAME") 49 | print("===================") 50 | -------------------------------------------------------------------------------- /tests/qckt/realign-test-dm.py: -------------------------------------------------------------------------------- 1 | import qckt 2 | from qckt.backend import * 3 | 4 | ck = qckt.QCkt(4) 5 | ck.X(0) 6 | ck.H(1) 7 | ck.CX(3,2) 8 | ck.draw() 9 | inpqubits = [4,5,2,3] 10 | ck = ck.realign(6,6,inpqubits) 11 | print("Realigned with:",inpqubits) 12 | ck.draw() 13 | 14 | job = qckt.Job(ck,qtrace=True) 15 | bk = DMQdeb() 16 | bk.runjob(job) 17 | print("STATE VECTOR READ OUT") 18 | print(job.get_svec()) 19 | print("CREGISTER READ OUT") 20 | print(job.get_creg()[0]) 21 | 22 | -------------------------------------------------------------------------------- /tests/qckt/realign-test.py: -------------------------------------------------------------------------------- 1 | import qckt 2 | from qckt.backend import * 3 | 4 | ck = qckt.QCkt(4) 5 | ck.X(0) 6 | ck.H(1) 7 | ck.CX(3,2) 8 | ck.draw() 9 | inpqubits = [4,5,2,3] 10 | ck = ck.realign(6,6,inpqubits) 11 | print("Realigned with:",inpqubits) 12 | ck.draw() 13 | 14 | job = qckt.Job(ck,qtrace=True) 15 | bk = Qdeb() 16 | bk.runjob(job) 17 | print("STATE VECTOR READ OUT") 18 | print(job.get_svec()) 19 | print("CREGISTER READ OUT") 20 | print(job.get_creg()[0]) 21 | 22 | -------------------------------------------------------------------------------- /tests/qckt/registry-access-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import qckt.backend as bknd 5 | 6 | print("Services available") 7 | svclist = bknd.Registry().listSvc() 8 | for i in svclist: print(i[0],":", i[1]) 9 | print("-------------------------") 10 | print() 11 | usesvc = svclist[0][0] 12 | print("Using service:",usesvc) 13 | svc = bknd.Registry().getSvc('QSystems') 14 | # print("Service object:", svc) 15 | print("-------------------------") 16 | print() 17 | svcinsts = svc.listInstances() 18 | print("Instances available:") 19 | for i in svcinsts: 20 | print(i) 21 | print("-------------------------") 22 | print() 23 | print('Using instance:','dmqsim-deb') 24 | engine = svc.getInstance('dmqsim-deb') 25 | print("-------------------------") 26 | print() 27 | 28 | ck = qckt.QCkt(4,4) 29 | ck.H(0) 30 | ck.CX(0,1) 31 | ck.Border() 32 | ck.X([2,3]) 33 | ck.Border() 34 | ck.Probe("point 1") 35 | ck.draw() 36 | 37 | job = qckt.Job(ck,qtrace=False,shots=1) 38 | engine.runjob(job) 39 | print("-------------------------------") 40 | print("printing results") 41 | print(job.get_svec()) 42 | print(job.get_creg()[0]) 43 | -------------------------------------------------------------------------------- /tests/qckt/registry-access.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qckt 4 | import qckt.backend as bknd 5 | 6 | print("Services available") 7 | svclist = bknd.Registry().listSvc() 8 | for i in svclist: print(i[0],":", i[1]) 9 | print("-------------------------") 10 | print() 11 | usesvc = svclist[0][0] 12 | print("Using service:",usesvc) 13 | svc = bknd.Registry().getSvc('QSystems') 14 | # print("Service object:", svc) 15 | print("-------------------------") 16 | print() 17 | svcinsts = svc.listInstances() 18 | print("Instances available:") 19 | for i in svcinsts: 20 | print(i) 21 | print("-------------------------") 22 | print() 23 | print('Using instance:','qsim-deb') 24 | engine = svc.getInstance('qsim-deb') 25 | print("-------------------------") 26 | print() 27 | 28 | ck = qckt.QCkt(4,4) 29 | ck.H(0) 30 | ck.CX(0,1) 31 | ck.Border() 32 | ck.X([2,3]) 33 | ck.Border() 34 | ck.Probe("point 1") 35 | ck.draw() 36 | 37 | job = qckt.Job(ck,qtrace=False,shots=1) 38 | engine.runjob(job) 39 | print("-------------------------------") 40 | print("printing results") 41 | print(job.get_svec()) 42 | print(job.get_creg()[0]) 43 | -------------------------------------------------------------------------------- /tests/qckt/rgates-test-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | import qckt 5 | from qckt.backend import * 6 | 7 | theta = 3*np.pi/2 8 | 9 | ck = qckt.QCkt(1) 10 | ck.X(0) 11 | ck.H(0) 12 | ck.Probe() 13 | ck.Rx(theta,0) 14 | ck.draw() 15 | job = qckt.Job(ck) 16 | DMQdeb().runjob(job) 17 | print("STATE VECTOR READ OUT") 18 | print(job.get_svec()) 19 | print("CREGISTER READ OUT: ",end="") 20 | print() 21 | print(job.get_creg()[0]) 22 | 23 | 24 | ck = qckt.QCkt(1) 25 | ck.X(0) 26 | ck.H(0) 27 | ck.Probe() 28 | ck.Ry(theta,0) 29 | ck.draw() 30 | job = qckt.Job(ck) 31 | DMQdeb().runjob(job) 32 | print("STATE VECTOR READ OUT") 33 | print(job.get_svec()) 34 | print("CREGISTER READ OUT: ",end="") 35 | print() 36 | print(job.get_creg()[0]) 37 | 38 | 39 | ck = qckt.QCkt(1) 40 | ck.X(0) 41 | ck.H(0) 42 | ck.Probe() 43 | ck.Rz(theta,0) 44 | ck.draw() 45 | job = qckt.Job(ck) 46 | DMQdeb().runjob(job) 47 | print("STATE VECTOR READ OUT") 48 | print(job.get_svec()) 49 | print("CREGISTER READ OUT: ",end="") 50 | print() 51 | print(job.get_creg()[0]) 52 | 53 | -------------------------------------------------------------------------------- /tests/qckt/rgates-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | import qckt 5 | from qckt.backend import * 6 | 7 | theta = 3*np.pi/2 8 | 9 | ck = qckt.QCkt(1) 10 | ck.X(0) 11 | ck.H(0) 12 | ck.Probe() 13 | ck.Rx(theta,0) 14 | ck.draw() 15 | job = qckt.Job(ck) 16 | Qdeb().runjob(job) 17 | print("STATE VECTOR READ OUT") 18 | print(job.get_svec()) 19 | print("CREGISTER READ OUT: ",end="") 20 | print() 21 | print(job.get_creg()[0]) 22 | 23 | 24 | ck = qckt.QCkt(1) 25 | ck.X(0) 26 | ck.H(0) 27 | ck.Probe() 28 | ck.Ry(theta,0) 29 | ck.draw() 30 | job = qckt.Job(ck) 31 | Qdeb().runjob(job) 32 | print("STATE VECTOR READ OUT") 33 | print(job.get_svec()) 34 | print("CREGISTER READ OUT: ",end="") 35 | print() 36 | print(job.get_creg()[0]) 37 | 38 | 39 | ck = qckt.QCkt(1) 40 | ck.X(0) 41 | ck.H(0) 42 | ck.Probe() 43 | ck.Rz(theta,0) 44 | ck.draw() 45 | job = qckt.Job(ck) 46 | Qdeb().runjob(job) 47 | print("STATE VECTOR READ OUT") 48 | print(job.get_svec()) 49 | print("CREGISTER READ OUT: ",end="") 50 | print() 51 | print(job.get_creg()[0]) 52 | 53 | -------------------------------------------------------------------------------- /tests/qckt/runstats-dm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import qckt 3 | from qckt.backend import * 4 | 5 | ck = qckt.QCkt(4) 6 | ck.X(0) 7 | ck.X(1) 8 | ck.X(2) 9 | ck.X(3) 10 | ck.H(1) 11 | ck.H(2) 12 | ck.CX(1,2) 13 | ck.draw() 14 | job = qckt.Job(ck) 15 | DMQdeb().runjob(job) 16 | 17 | print('Total steps',job.runstats['QSteps']) 18 | op_names = [k for k in job.runstats['OpCounts'].keys()] 19 | op_names.sort() # so the print order is guaranteed to be the same each time 20 | for k in op_names: 21 | print('op',k,'count',job.runstats['OpCounts'][k]) 22 | 23 | # Not using job.print_runstats(), as the actual execution time measurements will 24 | # be slightly different for each run, so can lead to differnt output each time. 25 | -------------------------------------------------------------------------------- /tests/qckt/runstats.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import qckt 3 | from qckt.backend import * 4 | 5 | ck = qckt.QCkt(4) 6 | ck.X(0) 7 | ck.X(1) 8 | ck.X(2) 9 | ck.X(3) 10 | ck.H(1) 11 | ck.H(2) 12 | ck.CX(1,2) 13 | ck.draw() 14 | job = qckt.Job(ck) 15 | Qdeb().runjob(job) 16 | 17 | print('Total steps',job.runstats['QSteps']) 18 | op_names = [k for k in job.runstats['OpCounts'].keys()] 19 | op_names.sort() # so the print order is guaranteed to be the same each time 20 | for k in op_names: 21 | print('op',k,'count',job.runstats['OpCounts'][k]) 22 | 23 | # Not using job.print_runstats(), as the actual execution time measurements will 24 | # be slightly different for each run, so can lead to differnt output each time. 25 | -------------------------------------------------------------------------------- /tests/qsim/RUN_ALL_TESTS: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BRIEF=0 3 | QUIET=0 4 | while [[ $# -gt 0 ]] 5 | do 6 | key="$1" 7 | 8 | case $key in 9 | -b|--brief) 10 | BRIEF=1 11 | ;; 12 | -q|--quiet) 13 | QUIET=1 14 | ;; 15 | *) 16 | echo "Usage: $0 [-b|--brief] [-q|--quiet]" 17 | exit 1 18 | ;; 19 | esac 20 | shift # past argument or value 21 | done 22 | 23 | list=`ls *.py` 24 | 25 | if [ ! -d runlogs ]; then 26 | mkdir runlogs 27 | fi 28 | overall_ret=0 29 | for f in $list; do 30 | logfile=runlogs/${f}.log 31 | python3 $f > ${logfile} 32 | explist="" 33 | explist=$(ls expected/${f}.log*) 34 | succ=1 35 | if [[ $explist != "" ]]; then 36 | for e in $explist; do 37 | cmp -s $logfile $e 38 | if [ $? = 0 ]; then 39 | succ=0 40 | fi 41 | done 42 | fi 43 | if [ $succ = 0 ]; then 44 | if [[ $BRIEF = 0 && $QUIET = 0 ]]; then 45 | echo "SUCCESS - $f" 46 | fi 47 | else 48 | if [[ $QUIET = 0 ]]; then 49 | echo ">>>>>>> FAILED - $f" 50 | fi 51 | overall_ret=1 52 | fi 53 | done 54 | if [[ $BRIEF = 1 && $QUIET = 0 ]]; then 55 | if [[ $overall_ret = 0 ]]; then 56 | echo "SUCCESS" 57 | fi 58 | fi 59 | exit $overall_ret 60 | -------------------------------------------------------------------------------- /tests/qsim/SHOWDIFF: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | diff -y runlogs/${1}.log expected/${1}.log | less 4 | -------------------------------------------------------------------------------- /tests/qsim/combine-gates-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | 5 | print() 6 | print("Parallel HX--------------------------------------------") 7 | qc = qsim.DMQSimulator(8) 8 | hx = qsim.qcombine_par('HX',[qsim.H(),qsim.X()]) 9 | qc.qgate(hx,[7,6], qtrace=True) 10 | 11 | print() 12 | print("Parallel HHHH and CCCC---------------------------------") 13 | qc = qsim.DMQSimulator(8) 14 | H4 = qsim.qcombine_par("H4",[qsim.H(),qsim.H(),qsim.H(),qsim.H()]) 15 | C4 = qsim.qcombine_par("C4",[qsim.C(),qsim.C(),qsim.C(),qsim.C()]) 16 | qc.qgate(H4,[7,5,3,1], qtrace=True) 17 | qc.qgate(C4,[7,6,5,4,3,2,1,0], qtrace=True) 18 | qc.qgate(qsim.C(),[7,6]) 19 | qc.qgate(qsim.C(),[5,4]) 20 | qc.qgate(qsim.C(),[3,2]) 21 | qc.qgate(qsim.C(),[1,0]) 22 | qc.qreport(header="AFTER 4 individual C's") 23 | qc.qgate(qsim.H(),[7]) 24 | qc.qgate(qsim.H(),[5]) 25 | qc.qgate(qsim.H(),[3]) 26 | qc.qgate(qsim.H(),[1]) 27 | qc.qreport(header="AFTER 4 individual H's") 28 | 29 | print() 30 | print("Sequence HXYZ------------------------------------------") 31 | qc = qsim.DMQSimulator(8,qtrace=True) 32 | HXYZ = qsim.qcombine_seq("HXYZ",[qsim.H(),qsim.X(),qsim.Y(),qsim.Z()]) 33 | ZYXH = qsim.qcombine_seq("ZYXH",[qsim.Z(),qsim.Y(),qsim.X(),qsim.H()]) 34 | qc.qgate(HXYZ,[0],qtrace=True) 35 | qc.qgate(qsim.Z(),[0],qtrace=True) 36 | qc.qgate(qsim.Y(),[0],qtrace=True) 37 | qc.qgate(qsim.X(),[0],qtrace=True) 38 | qc.qgate(qsim.H(),[0],qtrace=True) 39 | -------------------------------------------------------------------------------- /tests/qsim/combine-gates.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | 5 | print() 6 | print("Parallel HX--------------------------------------------") 7 | qc = qsim.QSimulator(8) 8 | hx = qsim.qcombine_par('HX',[qsim.H(),qsim.X()]) 9 | qc.qgate(hx,[7,6], qtrace=True) 10 | 11 | print() 12 | print("Parallel HHHH and CCCC---------------------------------") 13 | qc = qsim.QSimulator(8) 14 | H4 = qsim.qcombine_par("H4",[qsim.H(),qsim.H(),qsim.H(),qsim.H()]) 15 | C4 = qsim.qcombine_par("C4",[qsim.C(),qsim.C(),qsim.C(),qsim.C()]) 16 | qc.qgate(H4,[7,5,3,1], qtrace=True) 17 | qc.qgate(C4,[7,6,5,4,3,2,1,0], qtrace=True) 18 | qc.qgate(qsim.C(),[7,6]) 19 | qc.qgate(qsim.C(),[5,4]) 20 | qc.qgate(qsim.C(),[3,2]) 21 | qc.qgate(qsim.C(),[1,0]) 22 | qc.qreport(header="AFTER 4 individual C's") 23 | qc.qgate(qsim.H(),[7]) 24 | qc.qgate(qsim.H(),[5]) 25 | qc.qgate(qsim.H(),[3]) 26 | qc.qgate(qsim.H(),[1]) 27 | qc.qreport(header="AFTER 4 individual H's") 28 | 29 | print() 30 | print("Sequence HXYZ------------------------------------------") 31 | qc = qsim.QSimulator(8,qtrace=True) 32 | HXYZ = qsim.qcombine_seq("HXYZ",[qsim.H(),qsim.X(),qsim.Y(),qsim.Z()]) 33 | ZYXH = qsim.qcombine_seq("ZYXH",[qsim.Z(),qsim.Y(),qsim.X(),qsim.H()]) 34 | qc.qgate(HXYZ,[0],qtrace=True) 35 | qc.qgate(qsim.Z(),[0],qtrace=True) 36 | qc.qgate(qsim.Y(),[0],qtrace=True) 37 | qc.qgate(qsim.X(),[0],qtrace=True) 38 | qc.qgate(qsim.H(),[0],qtrace=True) 39 | -------------------------------------------------------------------------------- /tests/qsim/expected/combine-gates-dm.py.log: -------------------------------------------------------------------------------- 1 | 2 | Parallel HX-------------------------------------------- 3 | HX Qubit[7, 6] 4 | 01000000 ... | 0.5000+0.0000j 5 | 11000000 ... | 0.5000+0.0000j 6 | Mixed State Purity: 1.0000 7 | CREGISTER: 00000000 8 | 9 | 10 | Parallel HHHH and CCCC--------------------------------- 11 | H4 Qubit[7, 5, 3, 1] 12 | 00000000 ... | 0.0625+0.0000j 13 | 00000010 ... | 0.0625+0.0000j 14 | 00001000 ... | 0.0625+0.0000j 15 | 00001010 ... | 0.0625+0.0000j 16 | 00100000 ... | 0.0625+0.0000j 17 | 00100010 ... | 0.0625+0.0000j 18 | 00101000 ... | 0.0625+0.0000j 19 | 00101010 ... | 0.0625+0.0000j 20 | 10000000 ... | 0.0625+0.0000j 21 | 10000010 ... | 0.0625+0.0000j 22 | 10001000 ... | 0.0625+0.0000j 23 | 10001010 ... | 0.0625+0.0000j 24 | 10100000 ... | 0.0625+0.0000j 25 | 10100010 ... | 0.0625+0.0000j 26 | 10101000 ... | 0.0625+0.0000j 27 | 10101010 ... | 0.0625+0.0000j 28 | Mixed State Purity: 1.0000 29 | CREGISTER: 00000000 30 | 31 | C4 Qubit[7, 6, 5, 4, 3, 2, 1, 0] 32 | 00000000 ... | 0.0625+0.0000j 33 | 00000011 ... | 0.0625+0.0000j 34 | 00001100 ... | 0.0625+0.0000j 35 | 00001111 ... | 0.0625+0.0000j 36 | 00110000 ... | 0.0625+0.0000j 37 | 00110011 ... | 0.0625+0.0000j 38 | 00111100 ... | 0.0625+0.0000j 39 | 00111111 ... | 0.0625+0.0000j 40 | 11000000 ... | 0.0625+0.0000j 41 | 11000011 ... | 0.0625+0.0000j 42 | 11001100 ... | 0.0625+0.0000j 43 | 11001111 ... | 0.0625+0.0000j 44 | 11110000 ... | 0.0625+0.0000j 45 | 11110011 ... | 0.0625+0.0000j 46 | 11111100 ... | 0.0625+0.0000j 47 | 11111111 ... | 0.0625+0.0000j 48 | Mixed State Purity: 1.0000 49 | CREGISTER: 00000000 50 | 51 | AFTER 4 individual C's 52 | 00000000 ... | 0.0625+0.0000j 53 | 00000010 ... | 0.0625+0.0000j 54 | 00001000 ... | 0.0625+0.0000j 55 | 00001010 ... | 0.0625+0.0000j 56 | 00100000 ... | 0.0625+0.0000j 57 | 00100010 ... | 0.0625+0.0000j 58 | 00101000 ... | 0.0625+0.0000j 59 | 00101010 ... | 0.0625+0.0000j 60 | 10000000 ... | 0.0625+0.0000j 61 | 10000010 ... | 0.0625+0.0000j 62 | 10001000 ... | 0.0625+0.0000j 63 | 10001010 ... | 0.0625+0.0000j 64 | 10100000 ... | 0.0625+0.0000j 65 | 10100010 ... | 0.0625+0.0000j 66 | 10101000 ... | 0.0625+0.0000j 67 | 10101010 ... | 0.0625+0.0000j 68 | Mixed State Purity: 1.0000 69 | CREGISTER: 00000000 70 | 71 | AFTER 4 individual H's 72 | 00000000 ... | 1.0000+0.0000j 73 | Mixed State Purity: 1.0000 74 | CREGISTER: 00000000 75 | 76 | 77 | Sequence HXYZ------------------------------------------ 78 | Initial State 79 | 00000000 ... | 1.0000+0.0000j 80 | Mixed State Purity: 1.0000 81 | CREGISTER: 00000000 82 | 83 | HXYZ Qubit[0] 84 | 00000000 ... | 0.5000+0.0000j 85 | 00000001 ... | 0.5000+0.0000j 86 | Mixed State Purity: 1.0000 87 | CREGISTER: 00000000 88 | 89 | Z Qubit[0] 90 | 00000000 ... | 0.5000+0.0000j 91 | 00000001 ... | 0.5000+0.0000j 92 | Mixed State Purity: 1.0000 93 | CREGISTER: 00000000 94 | 95 | Y Qubit[0] 96 | 00000000 ... | 0.5000+0.0000j 97 | 00000001 ... | 0.5000+0.0000j 98 | Mixed State Purity: 1.0000 99 | CREGISTER: 00000000 100 | 101 | X Qubit[0] 102 | 00000000 ... | 0.5000+0.0000j 103 | 00000001 ... | 0.5000+0.0000j 104 | Mixed State Purity: 1.0000 105 | CREGISTER: 00000000 106 | 107 | HADAMARD Qubit[0] 108 | 00000000 ... | 1.0000+0.0000j 109 | Mixed State Purity: 1.0000 110 | CREGISTER: 00000000 111 | 112 | -------------------------------------------------------------------------------- /tests/qsim/expected/combine-gates.py.log: -------------------------------------------------------------------------------- 1 | 2 | Parallel HX-------------------------------------------- 3 | 4 | HX Qubit[7, 6] 5 | 01000000 0.70710678+0.00000000j 6 | 11000000 0.70710678+0.00000000j 7 | CREGISTER: 00000000 8 | 9 | Parallel HHHH and CCCC--------------------------------- 10 | 11 | H4 Qubit[7, 5, 3, 1] 12 | 00000000 0.25000000+0.00000000j 13 | 00000010 0.25000000+0.00000000j 14 | 00001000 0.25000000+0.00000000j 15 | 00001010 0.25000000+0.00000000j 16 | 00100000 0.25000000+0.00000000j 17 | 00100010 0.25000000+0.00000000j 18 | 00101000 0.25000000+0.00000000j 19 | 00101010 0.25000000+0.00000000j 20 | 10000000 0.25000000+0.00000000j 21 | 10000010 0.25000000+0.00000000j 22 | 10001000 0.25000000+0.00000000j 23 | 10001010 0.25000000+0.00000000j 24 | 10100000 0.25000000+0.00000000j 25 | 10100010 0.25000000+0.00000000j 26 | 10101000 0.25000000+0.00000000j 27 | 10101010 0.25000000+0.00000000j 28 | CREGISTER: 00000000 29 | 30 | C4 Qubit[7, 6, 5, 4, 3, 2, 1, 0] 31 | 00000000 0.25000000+0.00000000j 32 | 00000011 0.25000000+0.00000000j 33 | 00001100 0.25000000+0.00000000j 34 | 00001111 0.25000000+0.00000000j 35 | 00110000 0.25000000+0.00000000j 36 | 00110011 0.25000000+0.00000000j 37 | 00111100 0.25000000+0.00000000j 38 | 00111111 0.25000000+0.00000000j 39 | 11000000 0.25000000+0.00000000j 40 | 11000011 0.25000000+0.00000000j 41 | 11001100 0.25000000+0.00000000j 42 | 11001111 0.25000000+0.00000000j 43 | 11110000 0.25000000+0.00000000j 44 | 11110011 0.25000000+0.00000000j 45 | 11111100 0.25000000+0.00000000j 46 | 11111111 0.25000000+0.00000000j 47 | CREGISTER: 00000000 48 | 49 | AFTER 4 individual C's 50 | 00000000 0.25000000+0.00000000j 51 | 00000010 0.25000000+0.00000000j 52 | 00001000 0.25000000+0.00000000j 53 | 00001010 0.25000000+0.00000000j 54 | 00100000 0.25000000+0.00000000j 55 | 00100010 0.25000000+0.00000000j 56 | 00101000 0.25000000+0.00000000j 57 | 00101010 0.25000000+0.00000000j 58 | 10000000 0.25000000+0.00000000j 59 | 10000010 0.25000000+0.00000000j 60 | 10001000 0.25000000+0.00000000j 61 | 10001010 0.25000000+0.00000000j 62 | 10100000 0.25000000+0.00000000j 63 | 10100010 0.25000000+0.00000000j 64 | 10101000 0.25000000+0.00000000j 65 | 10101010 0.25000000+0.00000000j 66 | CREGISTER: 00000000 67 | 68 | AFTER 4 individual H's 69 | 00000000 1.00000000+0.00000000j 70 | CREGISTER: 00000000 71 | 72 | Sequence HXYZ------------------------------------------ 73 | 74 | Initial State 75 | 00000000 1.00000000+0.00000000j 76 | CREGISTER: 00000000 77 | 78 | HXYZ Qubit[0] 79 | 00000000 0.00000000-0.70710678j 80 | 00000001 0.00000000-0.70710678j 81 | CREGISTER: 00000000 82 | 83 | Z Qubit[0] 84 | 00000000 0.00000000-0.70710678j 85 | 00000001 0.00000000+0.70710678j 86 | CREGISTER: 00000000 87 | 88 | Y Qubit[0] 89 | 00000000 0.70710678+0.00000000j 90 | 00000001 0.70710678+0.00000000j 91 | CREGISTER: 00000000 92 | 93 | X Qubit[0] 94 | 00000000 0.70710678+0.00000000j 95 | 00000001 0.70710678+0.00000000j 96 | CREGISTER: 00000000 97 | 98 | HADAMARD Qubit[0] 99 | 00000000 1.00000000+0.00000000j 100 | CREGISTER: 00000000 101 | -------------------------------------------------------------------------------- /tests/qsim/expected/fourier-dm.py.log: -------------------------------------------------------------------------------- 1 | 2 | ------------------------------------------------------------------------------------------------------- 3 | Problem Statement: 4 | Setup an initial prepared state and compute the fourier transform on it. 5 | ------------------------------------------------------------------------------------------------------- 6 | 7 | Initial State 8 | 00000000 ... | 0.1250+0.0000j 9 | 00100000 ... | 0.1250+0.0000j 10 | 01000000 ... | 0.1250+0.0000j 11 | 01100000 ... | 0.1250+0.0000j 12 | 10000000 ... | 0.1250+0.0000j 13 | 10100000 ... | 0.1250+0.0000j 14 | 11000000 ... | 0.1250+0.0000j 15 | 11100000 ... | 0.1250+0.0000j 16 | Mixed State Purity: 1.0000 17 | CREGISTER: 00000000 18 | 19 | QFT(8) Qubit[7, 6, 5, 4, 3, 2, 1, 0] 20 | 00000000 ... | 0.0312+0.0000j 21 | 00001000 ... | 0.0312+0.0000j 22 | 00010000 ... | 0.0312+0.0000j 23 | 00011000 ... | 0.0312+0.0000j 24 | 00100000 ... | 0.0312+0.0000j 25 | 00101000 ... | 0.0312+0.0000j 26 | 00110000 ... | 0.0312+0.0000j 27 | 00111000 ... | 0.0312+0.0000j 28 | 01000000 ... | 0.0312+0.0000j 29 | 01001000 ... | 0.0312+0.0000j 30 | 01010000 ... | 0.0312+0.0000j 31 | 01011000 ... | 0.0312+0.0000j 32 | 01100000 ... | 0.0312+0.0000j 33 | 01101000 ... | 0.0312+0.0000j 34 | 01110000 ... | 0.0312+0.0000j 35 | 01111000 ... | 0.0312+0.0000j 36 | 10000000 ... | 0.0312+0.0000j 37 | 10001000 ... | 0.0312+0.0000j 38 | 10010000 ... | 0.0312+0.0000j 39 | 10011000 ... | 0.0312+0.0000j 40 | 10100000 ... | 0.0312+0.0000j 41 | 10101000 ... | 0.0312+0.0000j 42 | 10110000 ... | 0.0312+0.0000j 43 | 10111000 ... | 0.0312+0.0000j 44 | 11000000 ... | 0.0312+0.0000j 45 | 11001000 ... | 0.0312+0.0000j 46 | 11010000 ... | 0.0312+0.0000j 47 | 11011000 ... | 0.0312+0.0000j 48 | 11100000 ... | 0.0312+0.0000j 49 | 11101000 ... | 0.0312+0.0000j 50 | 11110000 ... | 0.0312+0.0000j 51 | 11111000 ... | 0.0312+0.0000j 52 | Mixed State Purity: 1.0000 53 | CREGISTER: 00000000 54 | 55 | -------------------------------------------------------------------------------- /tests/qsim/expected/fourier.py.log: -------------------------------------------------------------------------------- 1 | 2 | ------------------------------------------------------------------------------------------------------- 3 | Problem Statement: 4 | Setup an initial prepared state and compute the fourier transform on it. 5 | ------------------------------------------------------------------------------------------------------- 6 | 7 | 8 | Initial State 9 | 00000000 0.35355339+0.00000000j 10 | 00100000 0.35355339+0.00000000j 11 | 01000000 0.35355339+0.00000000j 12 | 01100000 0.35355339+0.00000000j 13 | 10000000 0.35355339+0.00000000j 14 | 10100000 0.35355339+0.00000000j 15 | 11000000 0.35355339+0.00000000j 16 | 11100000 0.35355339+0.00000000j 17 | CREGISTER: 00000000 18 | 19 | QFT(8) Qubit[7, 6, 5, 4, 3, 2, 1, 0] 20 | 00000000 0.17677670+0.00000000j 21 | 00001000 0.17677670+0.00000000j 22 | 00010000 0.17677670+0.00000000j 23 | 00011000 0.17677670+0.00000000j 24 | 00100000 0.17677670+0.00000000j 25 | 00101000 0.17677670+0.00000000j 26 | 00110000 0.17677670+0.00000000j 27 | 00111000 0.17677670+0.00000000j 28 | 01000000 0.17677670+0.00000000j 29 | 01001000 0.17677670+0.00000000j 30 | 01010000 0.17677670+0.00000000j 31 | 01011000 0.17677670+0.00000000j 32 | 01100000 0.17677670+0.00000000j 33 | 01101000 0.17677670+0.00000000j 34 | 01110000 0.17677670+0.00000000j 35 | 01111000 0.17677670+0.00000000j 36 | 10000000 0.17677670+0.00000000j 37 | 10001000 0.17677670+0.00000000j 38 | 10010000 0.17677670+0.00000000j 39 | 10011000 0.17677670+0.00000000j 40 | 10100000 0.17677670+0.00000000j 41 | 10101000 0.17677670+0.00000000j 42 | 10110000 0.17677670+0.00000000j 43 | 10111000 0.17677670+0.00000000j 44 | 11000000 0.17677670+0.00000000j 45 | 11001000 0.17677670+0.00000000j 46 | 11010000 0.17677670+0.00000000j 47 | 11011000 0.17677670+0.00000000j 48 | 11100000 0.17677670+0.00000000j 49 | 11101000 0.17677670+0.00000000j 50 | 11110000 0.17677670+0.00000000j 51 | 11111000 0.17677670+0.00000000j 52 | CREGISTER: 00000000 53 | -------------------------------------------------------------------------------- /tests/qsim/expected/gates-test-dm.py.log.1: -------------------------------------------------------------------------------- 1 | Initial State 2 | 0000 ... | 1.0000+0.0000j 3 | Mixed State Purity: 1.0000 4 | CREGISTER: 0000 5 | 6 | X Qubit[0] 7 | 0001 ... | 1.0000+0.0000j 8 | Mixed State Purity: 1.0000 9 | CREGISTER: 0000 10 | 11 | X Qubit[1] 12 | 0011 ... | 1.0000+0.0000j 13 | Mixed State Purity: 1.0000 14 | CREGISTER: 0000 15 | 16 | X Qubit[2] 17 | 0111 ... | 1.0000+0.0000j 18 | Mixed State Purity: 1.0000 19 | CREGISTER: 0000 20 | 21 | X Qubit[3] 22 | 1111 ... | 1.0000+0.0000j 23 | Mixed State Purity: 1.0000 24 | CREGISTER: 0000 25 | 26 | Y Qubit[0] 27 | 1110 ... | 1.0000+0.0000j 28 | Mixed State Purity: 1.0000 29 | CREGISTER: 0000 30 | 31 | Y Qubit[1] 32 | 1100 ... | 1.0000+0.0000j 33 | Mixed State Purity: 1.0000 34 | CREGISTER: 0000 35 | 36 | INV-Y Qubit[1] 37 | 1110 ... | 1.0000+0.0000j 38 | Mixed State Purity: 1.0000 39 | CREGISTER: 0000 40 | 41 | INV-Y Qubit[0] 42 | 1111 ... | 1.0000+0.0000j 43 | Mixed State Purity: 1.0000 44 | CREGISTER: 0000 45 | 46 | Z Qubit[0] 47 | 1111 ... | 1.0000+0.0000j 48 | Mixed State Purity: 1.0000 49 | CREGISTER: 0000 50 | 51 | Z Qubit[1] 52 | 1111 ... | 1.0000+0.0000j 53 | Mixed State Purity: 1.0000 54 | CREGISTER: 0000 55 | 56 | Z Qubit[2] 57 | 1111 ... | 1.0000+0.0000j 58 | Mixed State Purity: 1.0000 59 | CREGISTER: 0000 60 | 61 | Z Qubit[3] 62 | 1111 ... | 1.0000+0.0000j 63 | Mixed State Purity: 1.0000 64 | CREGISTER: 0000 65 | 66 | Initial State 67 | 0000 ... | 1.0000+0.0000j 68 | Mixed State Purity: 1.0000 69 | CREGISTER: 0000 70 | 71 | HADAMARD Qubit[2] 72 | 0000 ... | 0.5000+0.0000j 73 | 0100 ... | 0.5000+0.0000j 74 | Mixed State Purity: 1.0000 75 | CREGISTER: 0000 76 | 77 | HADAMARD Qubit[3] 78 | 0000 ... | 0.2500+0.0000j 79 | 0100 ... | 0.2500+0.0000j 80 | 1000 ... | 0.2500+0.0000j 81 | 1100 ... | 0.2500+0.0000j 82 | Mixed State Purity: 1.0000 83 | CREGISTER: 0000 84 | 85 | CNOT Qubit[2, 0] 86 | 0000 ... | 0.2500+0.0000j 87 | 0101 ... | 0.2500+0.0000j 88 | 1000 ... | 0.2500+0.0000j 89 | 1101 ... | 0.2500+0.0000j 90 | Mixed State Purity: 1.0000 91 | CREGISTER: 0000 92 | 93 | CNOT Qubit[3, 1] 94 | 0000 ... | 0.2500+0.0000j 95 | 0101 ... | 0.2500+0.0000j 96 | 1010 ... | 0.2500+0.0000j 97 | 1111 ... | 0.2500+0.0000j 98 | Mixed State Purity: 1.0000 99 | CREGISTER: 0000 100 | 101 | Initial State 102 | 0000 ... | 1.0000+0.0000j 103 | Mixed State Purity: 1.0000 104 | CREGISTER: 0000 105 | 106 | X Qubit[0] 107 | 0001 ... | 1.0000+0.0000j 108 | Mixed State Purity: 1.0000 109 | CREGISTER: 0000 110 | 111 | X Qubit[1] 112 | 0011 ... | 1.0000+0.0000j 113 | Mixed State Purity: 1.0000 114 | CREGISTER: 0000 115 | 116 | ROTphi(1.5708) Qubit[0] 117 | 0011 ... | 1.0000+0.0000j 118 | Mixed State Purity: 1.0000 119 | CREGISTER: 0000 120 | 121 | ROTphi(0.7854) Qubit[1] 122 | 0011 ... | 1.0000+0.0000j 123 | Mixed State Purity: 1.0000 124 | CREGISTER: 0000 125 | 126 | Initial State 127 | 0000 ... | 1.0000+0.0000j 128 | Mixed State Purity: 1.0000 129 | CREGISTER: 0000 130 | 131 | X Qubit[0] 132 | 0001 ... | 1.0000+0.0000j 133 | Mixed State Purity: 1.0000 134 | CREGISTER: 0000 135 | 136 | SWAP Qubit[0, 1] 137 | 0010 ... | 1.0000+0.0000j 138 | Mixed State Purity: 1.0000 139 | CREGISTER: 0000 140 | 141 | SWAP Qubit[3, 1] 142 | 1000 ... | 1.0000+0.0000j 143 | Mixed State Purity: 1.0000 144 | CREGISTER: 0000 145 | 146 | -------------------------------------------------------------------------------- /tests/qsim/expected/gates-test-dm.py.log.2: -------------------------------------------------------------------------------- 1 | Initial State 2 | 0000 ... | 1.0000+0.0000j 3 | Mixed State Purity: 1.0000 4 | CREGISTER: 0000 5 | 6 | X Qubit[0] 7 | 0001 ... | 1.0000+0.0000j 8 | Mixed State Purity: 1.0000 9 | CREGISTER: 0000 10 | 11 | X Qubit[1] 12 | 0011 ... | 1.0000+0.0000j 13 | Mixed State Purity: 1.0000 14 | CREGISTER: 0000 15 | 16 | X Qubit[2] 17 | 0111 ... | 1.0000+0.0000j 18 | Mixed State Purity: 1.0000 19 | CREGISTER: 0000 20 | 21 | X Qubit[3] 22 | 1111 ... | 1.0000+0.0000j 23 | Mixed State Purity: 1.0000 24 | CREGISTER: 0000 25 | 26 | Y Qubit[0] 27 | 1110 ... | 1.0000+0.0000j 28 | Mixed State Purity: 1.0000 29 | CREGISTER: 0000 30 | 31 | Y Qubit[1] 32 | 1100 ... | 1.0000+0.0000j 33 | Mixed State Purity: 1.0000 34 | CREGISTER: 0000 35 | 36 | INV-Y Qubit[1] 37 | 1110 ... | 1.0000+0.0000j 38 | Mixed State Purity: 1.0000 39 | CREGISTER: 0000 40 | 41 | INV-Y Qubit[0] 42 | 1111 ... | 1.0000+0.0000j 43 | Mixed State Purity: 1.0000 44 | CREGISTER: 0000 45 | 46 | Z Qubit[0] 47 | 1111 ... | 1.0000+0.0000j 48 | Mixed State Purity: 1.0000 49 | CREGISTER: 0000 50 | 51 | Z Qubit[1] 52 | 1111 ... | 1.0000+0.0000j 53 | Mixed State Purity: 1.0000 54 | CREGISTER: 0000 55 | 56 | Z Qubit[2] 57 | 1111 ... | 1.0000+0.0000j 58 | Mixed State Purity: 1.0000 59 | CREGISTER: 0000 60 | 61 | Z Qubit[3] 62 | 1111 ... | 1.0000+0.0000j 63 | Mixed State Purity: 1.0000 64 | CREGISTER: 0000 65 | 66 | Initial State 67 | 0000 ... | 1.0000+0.0000j 68 | Mixed State Purity: 1.0000 69 | CREGISTER: 0000 70 | 71 | HADAMARD Qubit[2] 72 | 0000 ... | 0.5000+0.0000j 73 | 0100 ... | 0.5000+0.0000j 74 | Mixed State Purity: 1.0000 75 | CREGISTER: 0000 76 | 77 | HADAMARD Qubit[3] 78 | 0000 ... | 0.2500+0.0000j 79 | 0100 ... | 0.2500+0.0000j 80 | 1000 ... | 0.2500+0.0000j 81 | 1100 ... | 0.2500+0.0000j 82 | Mixed State Purity: 1.0000 83 | CREGISTER: 0000 84 | 85 | CNOT Qubit[2, 0] 86 | 0000 ... | 0.2500+0.0000j 87 | 0101 ... | 0.2500+0.0000j 88 | 1000 ... | 0.2500+0.0000j 89 | 1101 ... | 0.2500+0.0000j 90 | Mixed State Purity: 1.0000 91 | CREGISTER: 0000 92 | 93 | CNOT Qubit[3, 1] 94 | 0000 ... | 0.2500+0.0000j 95 | 0101 ... | 0.2500+0.0000j 96 | 1010 ... | 0.2500+0.0000j 97 | 1111 ... | 0.2500+0.0000j 98 | Mixed State Purity: 1.0000 99 | CREGISTER: 0000 100 | 101 | Initial State 102 | 0000 ... | 1.0000+0.0000j 103 | Mixed State Purity: 1.0000 104 | CREGISTER: 0000 105 | 106 | X Qubit[0] 107 | 0001 ... | 1.0000+0.0000j 108 | Mixed State Purity: 1.0000 109 | CREGISTER: 0000 110 | 111 | X Qubit[1] 112 | 0011 ... | 1.0000+0.0000j 113 | Mixed State Purity: 1.0000 114 | CREGISTER: 0000 115 | 116 | ROTphi(1.5708) Qubit[0] 117 | 0011 ... | 1.0000+0.0000j 118 | Mixed State Purity: 1.0000 119 | CREGISTER: 0000 120 | 121 | ROTphi(0.7854) Qubit[1] 122 | 0011 ... | 1.0000-0.0000j 123 | Mixed State Purity: 1.0000 124 | CREGISTER: 0000 125 | 126 | Initial State 127 | 0000 ... | 1.0000+0.0000j 128 | Mixed State Purity: 1.0000 129 | CREGISTER: 0000 130 | 131 | X Qubit[0] 132 | 0001 ... | 1.0000+0.0000j 133 | Mixed State Purity: 1.0000 134 | CREGISTER: 0000 135 | 136 | SWAP Qubit[0, 1] 137 | 0010 ... | 1.0000+0.0000j 138 | Mixed State Purity: 1.0000 139 | CREGISTER: 0000 140 | 141 | SWAP Qubit[3, 1] 142 | 1000 ... | 1.0000+0.0000j 143 | Mixed State Purity: 1.0000 144 | CREGISTER: 0000 145 | 146 | -------------------------------------------------------------------------------- /tests/qsim/expected/gates-test.py.log: -------------------------------------------------------------------------------- 1 | 2 | Initial State 3 | 0000 1.00000000+0.00000000j 4 | CREGISTER: 0000 5 | 6 | X Qubit[0] 7 | 0001 1.00000000+0.00000000j 8 | CREGISTER: 0000 9 | 10 | X Qubit[1] 11 | 0011 1.00000000+0.00000000j 12 | CREGISTER: 0000 13 | 14 | X Qubit[2] 15 | 0111 1.00000000+0.00000000j 16 | CREGISTER: 0000 17 | 18 | X Qubit[3] 19 | 1111 1.00000000+0.00000000j 20 | CREGISTER: 0000 21 | 22 | Y Qubit[0] 23 | 1110 0.00000000-1.00000000j 24 | CREGISTER: 0000 25 | 26 | Y Qubit[1] 27 | 1100 -1.00000000+0.00000000j 28 | CREGISTER: 0000 29 | 30 | INV-Y Qubit[1] 31 | 1110 0.00000000-1.00000000j 32 | CREGISTER: 0000 33 | 34 | INV-Y Qubit[0] 35 | 1111 1.00000000+0.00000000j 36 | CREGISTER: 0000 37 | 38 | Z Qubit[0] 39 | 1111 -1.00000000+0.00000000j 40 | CREGISTER: 0000 41 | 42 | Z Qubit[1] 43 | 1111 1.00000000+0.00000000j 44 | CREGISTER: 0000 45 | 46 | Z Qubit[2] 47 | 1111 -1.00000000+0.00000000j 48 | CREGISTER: 0000 49 | 50 | Z Qubit[3] 51 | 1111 1.00000000+0.00000000j 52 | CREGISTER: 0000 53 | 54 | Initial State 55 | 0000 1.00000000+0.00000000j 56 | CREGISTER: 0000 57 | 58 | HADAMARD Qubit[2] 59 | 0000 0.70710678+0.00000000j 60 | 0100 0.70710678+0.00000000j 61 | CREGISTER: 0000 62 | 63 | HADAMARD Qubit[3] 64 | 0000 0.50000000+0.00000000j 65 | 0100 0.50000000+0.00000000j 66 | 1000 0.50000000+0.00000000j 67 | 1100 0.50000000+0.00000000j 68 | CREGISTER: 0000 69 | 70 | CNOT Qubit[2, 0] 71 | 0000 0.50000000+0.00000000j 72 | 0101 0.50000000+0.00000000j 73 | 1000 0.50000000+0.00000000j 74 | 1101 0.50000000+0.00000000j 75 | CREGISTER: 0000 76 | 77 | CNOT Qubit[3, 1] 78 | 0000 0.50000000+0.00000000j 79 | 0101 0.50000000+0.00000000j 80 | 1010 0.50000000+0.00000000j 81 | 1111 0.50000000+0.00000000j 82 | CREGISTER: 0000 83 | 84 | Initial State 85 | 0000 1.00000000+0.00000000j 86 | CREGISTER: 0000 87 | 88 | X Qubit[0] 89 | 0001 1.00000000+0.00000000j 90 | CREGISTER: 0000 91 | 92 | X Qubit[1] 93 | 0011 1.00000000+0.00000000j 94 | CREGISTER: 0000 95 | 96 | ROTphi(1.5708) Qubit[0] 97 | 0011 0.00000000+1.00000000j 98 | CREGISTER: 0000 99 | 100 | ROTphi(0.7854) Qubit[1] 101 | 0011 -0.70710678+0.70710678j 102 | CREGISTER: 0000 103 | 104 | Initial State 105 | 0000 1.00000000+0.00000000j 106 | CREGISTER: 0000 107 | 108 | X Qubit[0] 109 | 0001 1.00000000+0.00000000j 110 | CREGISTER: 0000 111 | 112 | SWAP Qubit[0, 1] 113 | 0010 1.00000000+0.00000000j 114 | CREGISTER: 0000 115 | 116 | SWAP Qubit[3, 1] 117 | 1000 1.00000000+0.00000000j 118 | CREGISTER: 0000 119 | -------------------------------------------------------------------------------- /tests/qsim/expected/helloworld-dm.py.log.1: -------------------------------------------------------------------------------- 1 | 2 | Apply H on 0 then C on 0,3 then Measure 0 3 | Initial State 4 | 00000000 ... | 1.0000+0.0000j 5 | Mixed State Purity: 1.0000 6 | CREGISTER: 00000000 7 | 8 | State 9 | 00000000 ... | 0.5000+0.0000j 10 | 00001001 ... | 0.5000+0.0000j 11 | Mixed State Purity: 1.0000 12 | CREGISTER: 00000000 13 | 14 | State 15 | 00001001 ... | 1.0000+0.0000j 16 | Mixed State Purity: 1.0000 17 | CREGISTER: 00000001 18 | 19 | -------------------------------------------------------------------------------- /tests/qsim/expected/helloworld-dm.py.log.2: -------------------------------------------------------------------------------- 1 | 2 | Apply H on 0 then C on 0,3 then Measure 0 3 | Initial State 4 | 00000000 ... | 1.0000+0.0000j 5 | Mixed State Purity: 1.0000 6 | CREGISTER: 00000000 7 | 8 | State 9 | 00000000 ... | 0.5000+0.0000j 10 | 00001001 ... | 0.5000+0.0000j 11 | Mixed State Purity: 1.0000 12 | CREGISTER: 00000000 13 | 14 | State 15 | 00000000 ... | 1.0000+0.0000j 16 | Mixed State Purity: 1.0000 17 | CREGISTER: 00000000 18 | 19 | -------------------------------------------------------------------------------- /tests/qsim/expected/helloworld-traceON-dm.py.log.1: -------------------------------------------------------------------------------- 1 | 2 | Apply H on 0 then C on 0,3 then Measure 0 3 | Initial State 4 | 00000000 ... | 1.0000+0.0000j 5 | Mixed State Purity: 1.0000 6 | CREGISTER: 00000000 7 | 8 | HADAMARD Qubit[0] 9 | 00000000 ... | 0.5000+0.0000j 10 | 00000001 ... | 0.5000+0.0000j 11 | Mixed State Purity: 1.0000 12 | CREGISTER: 00000000 13 | 14 | CNOT Qubit[0, 3] 15 | 00000000 ... | 0.5000+0.0000j 16 | 00001001 ... | 0.5000+0.0000j 17 | Mixed State Purity: 1.0000 18 | CREGISTER: 00000000 19 | 20 | MEASURED Qubit[0] = [1] with probability = 0.5 21 | 00001001 ... | 1.0000+0.0000j 22 | Mixed State Purity: 1.0000 23 | CREGISTER: 00000001 24 | 25 | -------------------------------------------------------------------------------- /tests/qsim/expected/helloworld-traceON-dm.py.log.2: -------------------------------------------------------------------------------- 1 | 2 | Apply H on 0 then C on 0,3 then Measure 0 3 | Initial State 4 | 00000000 ... | 1.0000+0.0000j 5 | Mixed State Purity: 1.0000 6 | CREGISTER: 00000000 7 | 8 | HADAMARD Qubit[0] 9 | 00000000 ... | 0.5000+0.0000j 10 | 00000001 ... | 0.5000+0.0000j 11 | Mixed State Purity: 1.0000 12 | CREGISTER: 00000000 13 | 14 | CNOT Qubit[0, 3] 15 | 00000000 ... | 0.5000+0.0000j 16 | 00001001 ... | 0.5000+0.0000j 17 | Mixed State Purity: 1.0000 18 | CREGISTER: 00000000 19 | 20 | MEASURED Qubit[0] = [0] with probability = 0.5 21 | 00000000 ... | 1.0000+0.0000j 22 | Mixed State Purity: 1.0000 23 | CREGISTER: 00000000 24 | 25 | -------------------------------------------------------------------------------- /tests/qsim/expected/helloworld-traceON.py.log.1: -------------------------------------------------------------------------------- 1 | 2 | Apply H on 0 then C on 0,3 then Measure 0 3 | 4 | Initial State 5 | 00000000 1.00000000+0.00000000j 6 | CREGISTER: 00000000 7 | 8 | HADAMARD Qubit[0] 9 | 00000000 0.70710678+0.00000000j 10 | 00000001 0.70710678+0.00000000j 11 | CREGISTER: 00000000 12 | 13 | CNOT Qubit[0, 3] 14 | 00000000 0.70710678+0.00000000j 15 | 00001001 0.70710678+0.00000000j 16 | CREGISTER: 00000000 17 | 18 | MEASURED Qubit[0] = [0] with probability = 0.5 19 | 00000000 1.00000000+0.00000000j 20 | CREGISTER: 00000000 21 | -------------------------------------------------------------------------------- /tests/qsim/expected/helloworld-traceON.py.log.2: -------------------------------------------------------------------------------- 1 | 2 | Apply H on 0 then C on 0,3 then Measure 0 3 | 4 | Initial State 5 | 00000000 1.00000000+0.00000000j 6 | CREGISTER: 00000000 7 | 8 | HADAMARD Qubit[0] 9 | 00000000 0.70710678+0.00000000j 10 | 00000001 0.70710678+0.00000000j 11 | CREGISTER: 00000000 12 | 13 | CNOT Qubit[0, 3] 14 | 00000000 0.70710678+0.00000000j 15 | 00001001 0.70710678+0.00000000j 16 | CREGISTER: 00000000 17 | 18 | MEASURED Qubit[0] = [1] with probability = 0.5 19 | 00001001 1.00000000+0.00000000j 20 | CREGISTER: 00000001 21 | -------------------------------------------------------------------------------- /tests/qsim/expected/helloworld.py.log.1: -------------------------------------------------------------------------------- 1 | 2 | Apply H on 0 then C on 0,3 then Measure 0 3 | 4 | Initial State 5 | 00000000 1.00000000+0.00000000j 6 | CREGISTER: 00000000 7 | 8 | State 9 | 00000000 0.70710678+0.00000000j 10 | 00001001 0.70710678+0.00000000j 11 | CREGISTER: 00000000 12 | 13 | State 14 | 00000000 1.00000000+0.00000000j 15 | CREGISTER: 00000000 16 | -------------------------------------------------------------------------------- /tests/qsim/expected/helloworld.py.log.2: -------------------------------------------------------------------------------- 1 | 2 | Apply H on 0 then C on 0,3 then Measure 0 3 | 4 | Initial State 5 | 00000000 1.00000000+0.00000000j 6 | CREGISTER: 00000000 7 | 8 | State 9 | 00000000 0.70710678+0.00000000j 10 | 00001001 0.70710678+0.00000000j 11 | CREGISTER: 00000000 12 | 13 | State 14 | 00001001 1.00000000+0.00000000j 15 | CREGISTER: 00000001 16 | -------------------------------------------------------------------------------- /tests/qsim/expected/ifcbit-dm.py.log: -------------------------------------------------------------------------------- 1 | Initial State 2 | 00000 ... | 1.0000+0.0000j 3 | Mixed State Purity: 1.0000 4 | CREGISTER: 00000 5 | 6 | X Qubit[0] 7 | 00001 ... | 1.0000+0.0000j 8 | Mixed State Purity: 1.0000 9 | CREGISTER: 00000 10 | 11 | MEASURED Qubit[0] = [1] with probability = 1.0 12 | 00001 ... | 1.0000+0.0000j 13 | Mixed State Purity: 1.0000 14 | CREGISTER: 00001 15 | 16 | X Qubit[1] if Cbit0=1 17 | 00011 ... | 1.0000+0.0000j 18 | Mixed State Purity: 1.0000 19 | CREGISTER: 00001 20 | 21 | MEASURED Qubit[1] = [1] with probability = 1.0 22 | 00011 ... | 1.0000+0.0000j 23 | Mixed State Purity: 1.0000 24 | CREGISTER: 00011 25 | 26 | X Qubit[2] if Cbit3=0 27 | 00111 ... | 1.0000+0.0000j 28 | Mixed State Purity: 1.0000 29 | CREGISTER: 00011 30 | 31 | MEASURED Qubit[2] = [1] with probability = 1.0 32 | 00111 ... | 1.0000+0.0000j 33 | Mixed State Purity: 1.0000 34 | CREGISTER: 00111 35 | 36 | -------------------------------------------------------------------------------- /tests/qsim/expected/ifcbit.py.log: -------------------------------------------------------------------------------- 1 | 2 | Initial State 3 | 00000 1.00000000+0.00000000j 4 | CREGISTER: 00000 5 | 6 | X Qubit[0] 7 | 00001 1.00000000+0.00000000j 8 | CREGISTER: 00000 9 | 10 | MEASURED Qubit[0] = [1] with probability = 1.0 11 | 00001 1.00000000+0.00000000j 12 | CREGISTER: 00001 13 | 14 | X Qubit[1] if Cbit0=1 15 | 00011 1.00000000+0.00000000j 16 | CREGISTER: 00001 17 | 18 | MEASURED Qubit[1] = [1] with probability = 1.0 19 | 00011 1.00000000+0.00000000j 20 | CREGISTER: 00011 21 | 22 | X Qubit[2] if Cbit3=0 23 | 00111 1.00000000+0.00000000j 24 | CREGISTER: 00011 25 | 26 | MEASURED Qubit[2] = [1] with probability = 1.0 27 | 00111 1.00000000+0.00000000j 28 | CREGISTER: 00111 29 | -------------------------------------------------------------------------------- /tests/qsim/expected/probestates-qzeros-test-dm.py.log.1: -------------------------------------------------------------------------------- 1 | Initial State 2 | 000 1.00+0.00j | 1.0000+0.0000j 3 | Mixed State Purity: 1.0000 4 | CREGISTER: 000 5 | 6 | HADAMARD Qubit[2] 7 | 000 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 8 | 100 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 9 | Mixed State Purity: 1.0000 10 | CREGISTER: 000 11 | 12 | CNOT Qubit[2, 1] 13 | 000 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 14 | 110 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 15 | Mixed State Purity: 1.0000 16 | CREGISTER: 000 17 | 18 | Entangled state 19 | 000 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 20 | 110 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 21 | Mixed State Purity: 1.0000 22 | CREGISTER: 000 23 | 24 | MEASURED Qubit[2, 1] = [1, 1] with probability = 0.5 25 | 000 ... | 0.0000+0.0000j 26 | 001 ... | 0.0000+0.0000j 27 | 010 ... | 0.0000+0.0000j 28 | 011 ... | 0.0000+0.0000j 29 | 100 ... | 0.0000+0.0000j 30 | 101 ... | 0.0000+0.0000j 31 | 110 ... | 1.0000+0.0000j 32 | 111 ... | 0.0000+0.0000j 33 | Mixed State Purity: 1.0000 34 | CREGISTER: 110 35 | 36 | Final state - Probestates: [0, 7] 37 | 000 ... | 0.0000+0.0000j 38 | 111 ... | 0.0000+0.0000j 39 | Mixed State Purity: 1.0000 40 | CREGISTER: 110 41 | 42 | -------------------------------------------------------------------------------- /tests/qsim/expected/probestates-qzeros-test-dm.py.log.2: -------------------------------------------------------------------------------- 1 | Initial State 2 | 000 1.00+0.00j | 1.0000+0.0000j 3 | Mixed State Purity: 1.0000 4 | CREGISTER: 000 5 | 6 | HADAMARD Qubit[2] 7 | 000 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 8 | 100 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 9 | Mixed State Purity: 1.0000 10 | CREGISTER: 000 11 | 12 | CNOT Qubit[2, 1] 13 | 000 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 14 | 110 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 15 | Mixed State Purity: 1.0000 16 | CREGISTER: 000 17 | 18 | Entangled state 19 | 000 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 20 | 110 0.50+0.00j 0.50+0.00j | 0.5000+0.0000j 21 | Mixed State Purity: 1.0000 22 | CREGISTER: 000 23 | 24 | MEASURED Qubit[2, 1] = [0, 0] with probability = 0.5 25 | 000 ... | 1.0000+0.0000j 26 | 001 ... | 0.0000+0.0000j 27 | 010 ... | 0.0000+0.0000j 28 | 011 ... | 0.0000+0.0000j 29 | 100 ... | 0.0000+0.0000j 30 | 101 ... | 0.0000+0.0000j 31 | 110 ... | 0.0000+0.0000j 32 | 111 ... | 0.0000+0.0000j 33 | Mixed State Purity: 1.0000 34 | CREGISTER: 000 35 | 36 | Final state - Probestates: [0, 7] 37 | 000 ... | 1.0000+0.0000j 38 | 111 ... | 0.0000+0.0000j 39 | Mixed State Purity: 1.0000 40 | CREGISTER: 000 41 | 42 | -------------------------------------------------------------------------------- /tests/qsim/expected/probestates-qzeros-test.py.log.1: -------------------------------------------------------------------------------- 1 | 2 | Initial State 3 | 000 1.00000000+0.00000000j 4 | CREGISTER: 000 5 | 6 | HADAMARD Qubit[2] 7 | 000 0.70710678+0.00000000j 8 | 100 0.70710678+0.00000000j 9 | CREGISTER: 000 10 | 11 | CNOT Qubit[2, 1] 12 | 000 0.70710678+0.00000000j 13 | 110 0.70710678+0.00000000j 14 | CREGISTER: 000 15 | 16 | Entangled state 17 | 000 0.70710678+0.00000000j 18 | 110 0.70710678+0.00000000j 19 | CREGISTER: 000 20 | 21 | MEASURED Qubit[2, 1] = [1, 1] with probability = 0.5 22 | 000 0.00000000+0.00000000j 23 | 001 0.00000000+0.00000000j 24 | 010 0.00000000+0.00000000j 25 | 011 0.00000000+0.00000000j 26 | 100 0.00000000+0.00000000j 27 | 101 0.00000000+0.00000000j 28 | 110 1.00000000+0.00000000j 29 | 111 0.00000000+0.00000000j 30 | CREGISTER: 110 31 | 32 | Final state - Probestates: [0, 7] 33 | 000 0.00000000+0.00000000j 34 | 111 0.00000000+0.00000000j 35 | CREGISTER: 110 36 | -------------------------------------------------------------------------------- /tests/qsim/expected/probestates-qzeros-test.py.log.2: -------------------------------------------------------------------------------- 1 | 2 | Initial State 3 | 000 1.00000000+0.00000000j 4 | CREGISTER: 000 5 | 6 | HADAMARD Qubit[2] 7 | 000 0.70710678+0.00000000j 8 | 100 0.70710678+0.00000000j 9 | CREGISTER: 000 10 | 11 | CNOT Qubit[2, 1] 12 | 000 0.70710678+0.00000000j 13 | 110 0.70710678+0.00000000j 14 | CREGISTER: 000 15 | 16 | Entangled state 17 | 000 0.70710678+0.00000000j 18 | 110 0.70710678+0.00000000j 19 | CREGISTER: 000 20 | 21 | MEASURED Qubit[2, 1] = [0, 0] with probability = 0.5 22 | 000 1.00000000+0.00000000j 23 | 001 0.00000000+0.00000000j 24 | 010 0.00000000+0.00000000j 25 | 011 0.00000000+0.00000000j 26 | 100 0.00000000+0.00000000j 27 | 101 0.00000000+0.00000000j 28 | 110 0.00000000+0.00000000j 29 | 111 0.00000000+0.00000000j 30 | CREGISTER: 000 31 | 32 | Final state - Probestates: [0, 7] 33 | 000 1.00000000+0.00000000j 34 | 111 0.00000000+0.00000000j 35 | CREGISTER: 000 36 | -------------------------------------------------------------------------------- /tests/qsim/expected/qsim-dmqsim-dropinreplacement.py.log: -------------------------------------------------------------------------------- 1 | Initial State NOISE:[(BF(0.05),[0, 1, 2, 3])] 2 | 0000 ... | 0.8145+0.0000j 3 | 0001 ... | 0.0429+0.0000j 4 | 0010 ... | 0.0429+0.0000j 5 | 0011 ... | 0.0023+0.0000j 6 | 0100 ... | 0.0429+0.0000j 7 | 0101 ... | 0.0023+0.0000j 8 | 0110 ... | 0.0023+0.0000j 9 | 0111 ... | 0.0001+0.0000j 10 | 1000 ... | 0.0429+0.0000j 11 | 1001 ... | 0.0023+0.0000j 12 | 1010 ... | 0.0023+0.0000j 13 | 1011 ... | 0.0001+0.0000j 14 | 1100 ... | 0.0023+0.0000j 15 | 1101 ... | 0.0001+0.0000j 16 | 1110 ... | 0.0001+0.0000j 17 | 1111 ... | 0.0000+0.0000j 18 | Mixed State Purity: 0.6708 19 | CREGISTER: 0000 20 | 21 | HADAMARD Qubit[0] NOISE:[(Dep(0.05),[0]),(AD(0.05),[0])] 22 | 0000 ... | 0.4501+0.0000j 23 | 0001 ... | 0.4073+0.0000j 24 | 0010 ... | 0.0237+0.0000j 25 | 0011 ... | 0.0214+0.0000j 26 | 0100 ... | 0.0237+0.0000j 27 | 0101 ... | 0.0214+0.0000j 28 | 0110 ... | 0.0012+0.0000j 29 | 0111 ... | 0.0011+0.0000j 30 | 1000 ... | 0.0237+0.0000j 31 | 1001 ... | 0.0214+0.0000j 32 | 1010 ... | 0.0012+0.0000j 33 | 1011 ... | 0.0011+0.0000j 34 | 1100 ... | 0.0012+0.0000j 35 | 1101 ... | 0.0011+0.0000j 36 | 1110 ... | 0.0001+0.0000j 37 | 1111 ... | 0.0001+0.0000j 38 | Mixed State Purity: 0.6200 39 | CREGISTER: 0000 40 | 41 | CNOT Qubit[0, 3] NOISE:[(Dep(0.05),[0, 3])] 42 | 0000 ... | 0.4225+0.0000j 43 | 0001 ... | 0.0477+0.0000j 44 | 0010 ... | 0.0222+0.0000j 45 | 0011 ... | 0.0025+0.0000j 46 | 0100 ... | 0.0222+0.0000j 47 | 0101 ... | 0.0025+0.0000j 48 | 0110 ... | 0.0012+0.0000j 49 | 0111 ... | 0.0001+0.0000j 50 | 1000 ... | 0.0498+0.0000j 51 | 1001 ... | 0.3825+0.0000j 52 | 1010 ... | 0.0026+0.0000j 53 | 1011 ... | 0.0201+0.0000j 54 | 1100 ... | 0.0026+0.0000j 55 | 1101 ... | 0.0201+0.0000j 56 | 1110 ... | 0.0001+0.0000j 57 | 1111 ... | 0.0011+0.0000j 58 | Mixed State Purity: 0.5199 59 | CREGISTER: 0000 60 | 61 | NOISE:[(2DPH(0.05),[0, 1])] 62 | 0000 ... | 0.4225+0.0000j 63 | 0001 ... | 0.0477+0.0000j 64 | 0010 ... | 0.0222+0.0000j 65 | 0011 ... | 0.0025+0.0000j 66 | 0100 ... | 0.0222+0.0000j 67 | 0101 ... | 0.0025+0.0000j 68 | 0110 ... | 0.0012+0.0000j 69 | 0111 ... | 0.0001+0.0000j 70 | 1000 ... | 0.0498+0.0000j 71 | 1001 ... | 0.3825+0.0000j 72 | 1010 ... | 0.0026+0.0000j 73 | 1011 ... | 0.0201+0.0000j 74 | 1100 ... | 0.0026+0.0000j 75 | 1101 ... | 0.0201+0.0000j 76 | 1110 ... | 0.0001+0.0000j 77 | 1111 ... | 0.0011+0.0000j 78 | Mixed State Purity: 0.4956 79 | CREGISTER: 0000 80 | 81 | WARNING: Ignoring unsupported argument noise_profile in QSimulator(). For noise simulation, use DM simulators. 82 | 83 | Initial State 84 | 0000 1.00000000+0.00000000j 85 | CREGISTER: 0000 86 | WARNING: Ignoring unsupported argument noise_chan in qgate(). For noise simulation, use DM simulators. 87 | 88 | HADAMARD Qubit[0] 89 | 0000 0.70710678+0.00000000j 90 | 0001 0.70710678+0.00000000j 91 | CREGISTER: 0000 92 | 93 | CNOT Qubit[0, 3] 94 | 0000 0.70710678+0.00000000j 95 | 1001 0.70710678+0.00000000j 96 | CREGISTER: 0000 97 | WARNING: Ignoring unsupported function qnoise(). For noise simulation, use DM simulators. 98 | -------------------------------------------------------------------------------- /tests/qsim/expected/qsimcli-test.py.log: -------------------------------------------------------------------------------- 1 | Type '?' for help. 2 | > 3 | Initial State 4 | 0000 1.00000000+0.00000000j 5 | CREGISTER: 0000 6 | > 7 | HADAMARD Qubit[0] 8 | 0000 0.70710678+0.00000000j 9 | 0001 0.70710678+0.00000000j 10 | CREGISTER: 0000 11 | > 12 | CNOT Qubit[0, 1] 13 | 0000 0.70710678+0.00000000j 14 | 0011 0.70710678+0.00000000j 15 | CREGISTER: 0000 16 | > 17 | X Qubit[0] 18 | 0001 0.70710678+0.00000000j 19 | 0010 0.70710678+0.00000000j 20 | CREGISTER: 0000 21 | > 22 | Y Qubit[0] 23 | 0000 0.00000000-0.70710678j 24 | 0011 0.00000000+0.70710678j 25 | CREGISTER: 0000 26 | > 27 | Z Qubit[0] 28 | 0000 0.00000000-0.70710678j 29 | 0011 0.00000000-0.70710678j 30 | CREGISTER: 0000 31 | > -------------------------------------------------------------------------------- /tests/qsim/expected/runstats-dm.py.log: -------------------------------------------------------------------------------- 1 | Initial State 2 | 0000 ... | 1.0000+0.0000j 3 | Mixed State Purity: 1.0000 4 | CREGISTER: 0000 5 | 6 | HADAMARD Qubit[2] 7 | 0000 ... | 0.5000+0.0000j 8 | 0100 ... | 0.5000+0.0000j 9 | Mixed State Purity: 1.0000 10 | CREGISTER: 0000 11 | 12 | HADAMARD Qubit[3] 13 | 0000 ... | 0.2500+0.0000j 14 | 0100 ... | 0.2500+0.0000j 15 | 1000 ... | 0.2500+0.0000j 16 | 1100 ... | 0.2500+0.0000j 17 | Mixed State Purity: 1.0000 18 | CREGISTER: 0000 19 | 20 | CNOT Qubit[2, 0] 21 | 0000 ... | 0.2500+0.0000j 22 | 0101 ... | 0.2500+0.0000j 23 | 1000 ... | 0.2500+0.0000j 24 | 1101 ... | 0.2500+0.0000j 25 | Mixed State Purity: 1.0000 26 | CREGISTER: 0000 27 | 28 | CNOT Qubit[3, 1] 29 | 0000 ... | 0.2500+0.0000j 30 | 0101 ... | 0.2500+0.0000j 31 | 1010 ... | 0.2500+0.0000j 32 | 1111 ... | 0.2500+0.0000j 33 | Mixed State Purity: 1.0000 34 | CREGISTER: 0000 35 | 36 | X Qubit[0] 37 | 0001 ... | 0.2500+0.0000j 38 | 0100 ... | 0.2500+0.0000j 39 | 1011 ... | 0.2500+0.0000j 40 | 1110 ... | 0.2500+0.0000j 41 | Mixed State Purity: 1.0000 42 | CREGISTER: 0000 43 | 44 | X Qubit[1] 45 | 0011 ... | 0.2500+0.0000j 46 | 0110 ... | 0.2500+0.0000j 47 | 1001 ... | 0.2500+0.0000j 48 | 1100 ... | 0.2500+0.0000j 49 | Mixed State Purity: 1.0000 50 | CREGISTER: 0000 51 | 52 | X Qubit[2] 53 | 0010 ... | 0.2500+0.0000j 54 | 0111 ... | 0.2500+0.0000j 55 | 1000 ... | 0.2500+0.0000j 56 | 1101 ... | 0.2500+0.0000j 57 | Mixed State Purity: 1.0000 58 | CREGISTER: 0000 59 | 60 | X Qubit[3] 61 | 0000 ... | 0.2500+0.0000j 62 | 0101 ... | 0.2500+0.0000j 63 | 1010 ... | 0.2500+0.0000j 64 | 1111 ... | 0.2500+0.0000j 65 | Mixed State Purity: 1.0000 66 | CREGISTER: 0000 67 | 68 | Total operation steps 8 69 | CNOT 2 70 | HADAMARD 2 71 | X 4 72 | -------------------------------------------------------------------------------- /tests/qsim/expected/runstats.py.log: -------------------------------------------------------------------------------- 1 | 2 | Initial State 3 | 0000 1.00000000+0.00000000j 4 | CREGISTER: 0000 5 | 6 | HADAMARD Qubit[2] 7 | 0000 0.70710678+0.00000000j 8 | 0100 0.70710678+0.00000000j 9 | CREGISTER: 0000 10 | 11 | HADAMARD Qubit[3] 12 | 0000 0.50000000+0.00000000j 13 | 0100 0.50000000+0.00000000j 14 | 1000 0.50000000+0.00000000j 15 | 1100 0.50000000+0.00000000j 16 | CREGISTER: 0000 17 | 18 | CNOT Qubit[2, 0] 19 | 0000 0.50000000+0.00000000j 20 | 0101 0.50000000+0.00000000j 21 | 1000 0.50000000+0.00000000j 22 | 1101 0.50000000+0.00000000j 23 | CREGISTER: 0000 24 | 25 | CNOT Qubit[3, 1] 26 | 0000 0.50000000+0.00000000j 27 | 0101 0.50000000+0.00000000j 28 | 1010 0.50000000+0.00000000j 29 | 1111 0.50000000+0.00000000j 30 | CREGISTER: 0000 31 | 32 | X Qubit[0] 33 | 0001 0.50000000+0.00000000j 34 | 0100 0.50000000+0.00000000j 35 | 1011 0.50000000+0.00000000j 36 | 1110 0.50000000+0.00000000j 37 | CREGISTER: 0000 38 | 39 | X Qubit[1] 40 | 0011 0.50000000+0.00000000j 41 | 0110 0.50000000+0.00000000j 42 | 1001 0.50000000+0.00000000j 43 | 1100 0.50000000+0.00000000j 44 | CREGISTER: 0000 45 | 46 | X Qubit[2] 47 | 0010 0.50000000+0.00000000j 48 | 0111 0.50000000+0.00000000j 49 | 1000 0.50000000+0.00000000j 50 | 1101 0.50000000+0.00000000j 51 | CREGISTER: 0000 52 | 53 | X Qubit[3] 54 | 0000 0.50000000+0.00000000j 55 | 0101 0.50000000+0.00000000j 56 | 1010 0.50000000+0.00000000j 57 | 1111 0.50000000+0.00000000j 58 | CREGISTER: 0000 59 | Total operation steps 8 60 | CNOT 2 61 | HADAMARD 2 62 | X 4 63 | -------------------------------------------------------------------------------- /tests/qsim/expected/stretch-op-dm.py.log: -------------------------------------------------------------------------------- 1 | Initial State 2 | 00000000 ... | 1.0000+0.0000j 3 | Mixed State Purity: 1.0000 4 | CREGISTER: 00000000 5 | 6 | HADAMARD Qubit[3] 7 | 00000000 ... | 0.5000+0.0000j 8 | 00001000 ... | 0.5000+0.0000j 9 | Mixed State Purity: 1.0000 10 | CREGISTER: 00000000 11 | 12 | CNOT Qubit[3, 0] 13 | 00000000 ... | 0.5000+0.0000j 14 | 00001001 ... | 0.5000+0.0000j 15 | Mixed State Purity: 1.0000 16 | CREGISTER: 00000000 17 | 18 | 19 | ------------------------------------------------------------ 20 | Initial State 21 | 00000000 ... | 1.0000+0.0000j 22 | Mixed State Purity: 1.0000 23 | CREGISTER: 00000000 24 | 25 | HADAMARD Qubit[3] 26 | 00000000 ... | 0.5000+0.0000j 27 | 00001000 ... | 0.5000+0.0000j 28 | Mixed State Purity: 1.0000 29 | CREGISTER: 00000000 30 | 31 | 8Q-CNOT[3, 0] Qubit[7, 6, 5, 4, 3, 2, 1, 0] 32 | 00000000 ... | 0.5000+0.0000j 33 | 00001001 ... | 0.5000+0.0000j 34 | Mixed State Purity: 1.0000 35 | CREGISTER: 00000000 36 | 37 | -------------------------------------------------------------------------------- /tests/qsim/expected/stretch-op.py.log: -------------------------------------------------------------------------------- 1 | 2 | Initial State 3 | 00000000 1.00000000+0.00000000j 4 | CREGISTER: 00000000 5 | 6 | HADAMARD Qubit[3] 7 | 00000000 0.70710678+0.00000000j 8 | 00001000 0.70710678+0.00000000j 9 | CREGISTER: 00000000 10 | 11 | CNOT Qubit[3, 0] 12 | 00000000 0.70710678+0.00000000j 13 | 00001001 0.70710678+0.00000000j 14 | CREGISTER: 00000000 15 | 16 | ------------------------------------------------------------ 17 | 18 | Initial State 19 | 00000000 1.00000000+0.00000000j 20 | CREGISTER: 00000000 21 | 22 | HADAMARD Qubit[3] 23 | 00000000 0.70710678+0.00000000j 24 | 00001000 0.70710678+0.00000000j 25 | CREGISTER: 00000000 26 | 27 | 8Q-CNOT[3, 0] Qubit[7, 6, 5, 4, 3, 2, 1, 0] 28 | 00000000 0.70710678+0.00000000j 29 | 00001001 0.70710678+0.00000000j 30 | CREGISTER: 00000000 31 | -------------------------------------------------------------------------------- /tests/qsim/expected/user-def-gates-dm.py.log: -------------------------------------------------------------------------------- 1 | Initial State 2 | 00000000 ... | 1.0000+0.0000j 3 | Mixed State Purity: 1.0000 4 | CREGISTER: 00000000 5 | 6 | 7 | ------------------------------------------------ 8 | Demonstrating User-defined CNOT gate ... 9 | HADAMARD Qubit[4] 10 | 00000000 ... | 0.5000+0.0000j 11 | 00010000 ... | 0.5000+0.0000j 12 | Mixed State Purity: 1.0000 13 | CREGISTER: 00000000 14 | 15 | MY-CNOT Qubit[4, 7] 16 | 00000000 ... | 0.5000+0.0000j 17 | 10010000 ... | 0.5000+0.0000j 18 | Mixed State Purity: 1.0000 19 | CREGISTER: 00000000 20 | 21 | CNOT Qubit[4, 7] 22 | 00000000 ... | 0.5000+0.0000j 23 | 00010000 ... | 0.5000+0.0000j 24 | Mixed State Purity: 1.0000 25 | CREGISTER: 00000000 26 | 27 | HADAMARD Qubit[4] 28 | 00000000 ... | 1.0000+0.0000j 29 | Mixed State Purity: 1.0000 30 | CREGISTER: 00000000 31 | 32 | 33 | ------------------------------------------------ 34 | Demonstrating User-defined Phase Rotation gate ... 35 | X Qubit[5] 36 | 00100000 ... | 1.0000+0.0000j 37 | Mixed State Purity: 1.0000 38 | CREGISTER: 00000000 39 | 40 | MY-Rotation(1.5708) Qubit[5] 41 | 00100000 ... | 1.0000+0.0000j 42 | Mixed State Purity: 1.0000 43 | CREGISTER: 00000000 44 | 45 | -------------------------------------------------------------------------------- /tests/qsim/expected/user-def-gates.py.log: -------------------------------------------------------------------------------- 1 | 2 | Initial State 3 | 00000000 1.00000000+0.00000000j 4 | CREGISTER: 00000000 5 | 6 | ------------------------------------------------ 7 | Demonstrating User-defined CNOT gate ... 8 | 9 | HADAMARD Qubit[4] 10 | 00000000 0.70710678+0.00000000j 11 | 00010000 0.70710678+0.00000000j 12 | CREGISTER: 00000000 13 | 14 | MY-CNOT Qubit[4, 7] 15 | 00000000 0.70710678+0.00000000j 16 | 10010000 0.70710678+0.00000000j 17 | CREGISTER: 00000000 18 | 19 | CNOT Qubit[4, 7] 20 | 00000000 0.70710678+0.00000000j 21 | 00010000 0.70710678+0.00000000j 22 | CREGISTER: 00000000 23 | 24 | HADAMARD Qubit[4] 25 | 00000000 1.00000000+0.00000000j 26 | CREGISTER: 00000000 27 | 28 | ------------------------------------------------ 29 | Demonstrating User-defined Phase Rotation gate ... 30 | 31 | X Qubit[5] 32 | 00100000 1.00000000+0.00000000j 33 | CREGISTER: 00000000 34 | 35 | MY-Rotation(1.5708) Qubit[5] 36 | 00100000 0.00000000+1.00000000j 37 | CREGISTER: 00000000 38 | -------------------------------------------------------------------------------- /tests/qsim/expected/visualize.py.log: -------------------------------------------------------------------------------- 1 | 2 | Initial State 3 | 0000 1.00000000+0.00000000j |******************** 4 | 0001 0.00000000+0.00000000j x 5 | 0010 0.00000000+0.00000000j x 6 | 0011 0.00000000+0.00000000j x 7 | 0100 0.00000000+0.00000000j x 8 | 0101 0.00000000+0.00000000j x 9 | 0110 0.00000000+0.00000000j x 10 | 0111 0.00000000+0.00000000j x 11 | 1000 0.00000000+0.00000000j x 12 | 1001 0.00000000+0.00000000j x 13 | 1010 0.00000000+0.00000000j x 14 | 1011 0.00000000+0.00000000j x 15 | 1100 0.00000000+0.00000000j x 16 | 1101 0.00000000+0.00000000j x 17 | 1110 0.00000000+0.00000000j x 18 | 1111 0.00000000+0.00000000j x 19 | CREGISTER: 0000 20 | 21 | HADAMARD Qubit[1] 22 | 0000 0.70710678+0.00000000j |***************..... 23 | 0001 0.00000000+0.00000000j x 24 | 0010 0.70710678+0.00000000j |***************..... 25 | 0011 0.00000000+0.00000000j x 26 | 0100 0.00000000+0.00000000j x 27 | 0101 0.00000000+0.00000000j x 28 | 0110 0.00000000+0.00000000j x 29 | 0111 0.00000000+0.00000000j x 30 | 1000 0.00000000+0.00000000j x 31 | 1001 0.00000000+0.00000000j x 32 | 1010 0.00000000+0.00000000j x 33 | 1011 0.00000000+0.00000000j x 34 | 1100 0.00000000+0.00000000j x 35 | 1101 0.00000000+0.00000000j x 36 | 1110 0.00000000+0.00000000j x 37 | 1111 0.00000000+0.00000000j x 38 | CREGISTER: 0000 39 | 40 | CNOT Qubit[1, 0] 41 | 0000 0.70710678+0.00000000j |***************..... 42 | 0001 0.00000000+0.00000000j x 43 | 0010 0.00000000+0.00000000j x 44 | 0011 0.70710678+0.00000000j |***************..... 45 | 0100 0.00000000+0.00000000j x 46 | 0101 0.00000000+0.00000000j x 47 | 0110 0.00000000+0.00000000j x 48 | 0111 0.00000000+0.00000000j x 49 | 1000 0.00000000+0.00000000j x 50 | 1001 0.00000000+0.00000000j x 51 | 1010 0.00000000+0.00000000j x 52 | 1011 0.00000000+0.00000000j x 53 | 1100 0.00000000+0.00000000j x 54 | 1101 0.00000000+0.00000000j x 55 | 1110 0.00000000+0.00000000j x 56 | 1111 0.00000000+0.00000000j x 57 | CREGISTER: 0000 58 | 59 | Probing states - Probestates: [0, 1, 2, 3] 60 | 0000 0.70710678+0.00000000j |***************..... 61 | 0001 0.00000000+0.00000000j x 62 | 0010 0.00000000+0.00000000j x 63 | 0011 0.70710678+0.00000000j |***************..... 64 | CREGISTER: 0000 65 | 66 | HADAMARD Qubit[2] 67 | 0000 0.50000000+0.00000000j |**********.......... 68 | 0001 0.00000000+0.00000000j x 69 | 0010 0.00000000+0.00000000j x 70 | 0011 0.50000000+0.00000000j |**********.......... 71 | 0100 0.50000000+0.00000000j |**********.......... 72 | 0101 0.00000000+0.00000000j x 73 | 0110 0.00000000+0.00000000j x 74 | 0111 0.50000000+0.00000000j |**********.......... 75 | 1000 0.00000000+0.00000000j x 76 | 1001 0.00000000+0.00000000j x 77 | 1010 0.00000000+0.00000000j x 78 | 1011 0.00000000+0.00000000j x 79 | 1100 0.00000000+0.00000000j x 80 | 1101 0.00000000+0.00000000j x 81 | 1110 0.00000000+0.00000000j x 82 | 1111 0.00000000+0.00000000j x 83 | CREGISTER: 0000 84 | 85 | HADAMARD Qubit[3] 86 | 0000 0.35355339+0.00000000j |********............ 87 | 0001 0.00000000+0.00000000j x 88 | 0010 0.00000000+0.00000000j x 89 | 0011 0.35355339+0.00000000j |********............ 90 | 0100 0.35355339+0.00000000j |********............ 91 | 0101 0.00000000+0.00000000j x 92 | 0110 0.00000000+0.00000000j x 93 | 0111 0.35355339+0.00000000j |********............ 94 | 1000 0.35355339+0.00000000j |********............ 95 | 1001 0.00000000+0.00000000j x 96 | 1010 0.00000000+0.00000000j x 97 | 1011 0.35355339+0.00000000j |********............ 98 | 1100 0.35355339+0.00000000j |********............ 99 | 1101 0.00000000+0.00000000j x 100 | 1110 0.00000000+0.00000000j x 101 | 1111 0.35355339+0.00000000j |********............ 102 | CREGISTER: 0000 103 | -------------------------------------------------------------------------------- /tests/qsim/fourier-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | print(""" 4 | ------------------------------------------------------------------------------------------------------- 5 | Problem Statement: 6 | Setup an initial prepared state and compute the fourier transform on it. 7 | ------------------------------------------------------------------------------------------------------- 8 | """) 9 | 10 | import qsim 11 | import numpy as np 12 | 13 | nqbits = 8 14 | 15 | try: 16 | # setup an initial state to try out QFT 17 | initstate = [None]*(2**nqbits) 18 | p = 0 19 | stsz = 2**nqbits 20 | for i in range(stsz): 21 | if (i % (stsz/8)) == 0: 22 | initstate[i] = 1 23 | else: 24 | initstate[i] = 0 25 | p += np.absolute(initstate[i])**2 26 | initstate = np.transpose(np.matrix(initstate,dtype=complex))/np.sqrt(p) 27 | 28 | # Start the Quantum Computer Simulator 29 | q = qsim.DMQSimulator(nqbits,initstate=initstate, qtrace=True) 30 | 31 | # Perform QFT 32 | qftgate = qsim.QFT(nqbits) 33 | q.qgate(qftgate, list(reversed(range(nqbits)))) 34 | 35 | except qsim.QSimError as ex: 36 | print(ex.args) 37 | -------------------------------------------------------------------------------- /tests/qsim/fourier.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | print(""" 4 | ------------------------------------------------------------------------------------------------------- 5 | Problem Statement: 6 | Setup an initial prepared state and compute the fourier transform on it. 7 | ------------------------------------------------------------------------------------------------------- 8 | """) 9 | 10 | import qsim 11 | import numpy as np 12 | 13 | nqbits = 8 14 | 15 | try: 16 | # setup an initial state to try out QFT 17 | initstate = [None]*(2**nqbits) 18 | p = 0 19 | stsz = 2**nqbits 20 | for i in range(stsz): 21 | if (i % (stsz/8)) == 0: 22 | initstate[i] = 1 23 | else: 24 | initstate[i] = 0 25 | p += np.absolute(initstate[i])**2 26 | initstate = np.transpose(np.matrix(initstate,dtype=complex))/np.sqrt(p) 27 | 28 | # Start the Quantum Computer Simulator 29 | q = qsim.QSimulator(nqbits,initstate=initstate, qtrace=True) 30 | 31 | # Perform QFT 32 | qftgate = qsim.QFT(nqbits) 33 | q.qgate(qftgate, list(reversed(range(nqbits)))) 34 | 35 | except qsim.QSimError as ex: 36 | print(ex.args) 37 | -------------------------------------------------------------------------------- /tests/qsim/gates-test-dm.py: -------------------------------------------------------------------------------- 1 | 2 | import qsim 3 | 4 | q = qsim.DMQSimulator(4,qtrace=True) 5 | 6 | ## X gate 7 | q.qgate(qsim.X(),[0]) 8 | q.qgate(qsim.X(),[1]) 9 | q.qgate(qsim.X(),[2]) 10 | q.qgate(qsim.X(),[3]) 11 | 12 | # Y gate 13 | q.qgate(qsim.Y(),[0]) 14 | q.qgate(qsim.Y(),[1]) 15 | invY = q.qinverse(qsim.Y()) 16 | q.qgate(invY,[1]) 17 | q.qgate(invY,[0]) 18 | 19 | # Z gate 20 | q.qgate(qsim.Z(),[0]) 21 | q.qgate(qsim.Z(),[1]) 22 | q.qgate(qsim.Z(),[2]) 23 | q.qgate(qsim.Z(),[3]) 24 | 25 | # H gate 26 | q = qsim.DMQSimulator(4,qtrace=True) 27 | q.qgate(qsim.H(),[2]) 28 | q.qgate(qsim.H(),[3]) 29 | q.qgate(qsim.C(),[2,0]) 30 | q.qgate(qsim.C(),[3,1]) 31 | 32 | # Rphi gate 33 | q = qsim.DMQSimulator(4,qtrace=True) 34 | q.qgate(qsim.X(),[0]) 35 | q.qgate(qsim.X(),[1]) 36 | q.qgate(qsim.Rphi(q.pi/2),[0]) 37 | q.qgate(qsim.Rphi(q.pi/4),[1]) 38 | 39 | # SWAP 40 | q = qsim.DMQSimulator(4,qtrace=True) 41 | q.qgate(qsim.X(),[0]) 42 | q.qgate(qsim.SWAP(),[0,1]) 43 | q.qgate(qsim.SWAP(),[3,1]) 44 | 45 | -------------------------------------------------------------------------------- /tests/qsim/gates-test.py: -------------------------------------------------------------------------------- 1 | 2 | import qsim 3 | 4 | q = qsim.QSimulator(4,qtrace=True) 5 | 6 | ## X gate 7 | q.qgate(qsim.X(),[0]) 8 | q.qgate(qsim.X(),[1]) 9 | q.qgate(qsim.X(),[2]) 10 | q.qgate(qsim.X(),[3]) 11 | 12 | # Y gate 13 | q.qgate(qsim.Y(),[0]) 14 | q.qgate(qsim.Y(),[1]) 15 | invY = q.qinverse(qsim.Y()) 16 | q.qgate(invY,[1]) 17 | q.qgate(invY,[0]) 18 | 19 | # Z gate 20 | q.qgate(qsim.Z(),[0]) 21 | q.qgate(qsim.Z(),[1]) 22 | q.qgate(qsim.Z(),[2]) 23 | q.qgate(qsim.Z(),[3]) 24 | 25 | # H gate 26 | q = qsim.QSimulator(4,qtrace=True) 27 | q.qgate(qsim.H(),[2]) 28 | q.qgate(qsim.H(),[3]) 29 | q.qgate(qsim.C(),[2,0]) 30 | q.qgate(qsim.C(),[3,1]) 31 | 32 | # Rphi gate 33 | q = qsim.QSimulator(4,qtrace=True) 34 | q.qgate(qsim.X(),[0]) 35 | q.qgate(qsim.X(),[1]) 36 | q.qgate(qsim.Rphi(q.pi/2),[0]) 37 | q.qgate(qsim.Rphi(q.pi/4),[1]) 38 | 39 | # SWAP 40 | q = qsim.QSimulator(4,qtrace=True) 41 | q.qgate(qsim.X(),[0]) 42 | q.qgate(qsim.SWAP(),[0,1]) 43 | q.qgate(qsim.SWAP(),[3,1]) 44 | 45 | -------------------------------------------------------------------------------- /tests/qsim/helloworld-dm.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | 3 | print() 4 | print("Apply H on 0 then C on 0,3 then Measure 0") 5 | qc = qsim.DMQSimulator(8) 6 | qc.qreport(header="Initial State") 7 | qc.qgate(qsim.H(),[0]) 8 | qc.qgate(qsim.C(),[0,3]) 9 | qc.qreport() 10 | qc.qmeasure([0]) 11 | qc.qreport() 12 | -------------------------------------------------------------------------------- /tests/qsim/helloworld-traceON-dm.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | 3 | print() 4 | print("Apply H on 0 then C on 0,3 then Measure 0") 5 | qc = qsim.DMQSimulator(8, qtrace=True) 6 | qc.qgate(qsim.H(),[0]) 7 | qc.qgate(qsim.C(),[0,3]) 8 | qc.qmeasure([0]) 9 | -------------------------------------------------------------------------------- /tests/qsim/helloworld-traceON.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | 3 | print() 4 | print("Apply H on 0 then C on 0,3 then Measure 0") 5 | qc = qsim.QSimulator(8, qtrace=True) 6 | qc.qgate(qsim.H(),[0]) 7 | qc.qgate(qsim.C(),[0,3]) 8 | qc.qmeasure([0]) 9 | -------------------------------------------------------------------------------- /tests/qsim/helloworld.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | 3 | print() 4 | print("Apply H on 0 then C on 0,3 then Measure 0") 5 | qc = qsim.QSimulator(8) 6 | qc.qreport(header="Initial State") 7 | qc.qgate(qsim.H(),[0]) 8 | qc.qgate(qsim.C(),[0,3]) 9 | qc.qreport() 10 | qc.qmeasure([0]) 11 | qc.qreport() 12 | -------------------------------------------------------------------------------- /tests/qsim/ifcbit-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | 5 | q = qsim.DMQSimulator(5,qtrace=True) 6 | 7 | q.qgate(qsim.X(),[0]) 8 | q.qmeasure([0]) 9 | q.qgate(qsim.X(),[1], ifcbit=(0,1)) 10 | q.qmeasure([1]) 11 | q.qgate(qsim.X(),[2], ifcbit=(3,0)) 12 | q.qmeasure([2]) 13 | -------------------------------------------------------------------------------- /tests/qsim/ifcbit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | 5 | q = qsim.QSimulator(5,qtrace=True) 6 | 7 | q.qgate(qsim.X(),[0]) 8 | q.qmeasure([0]) 9 | q.qgate(qsim.X(),[1], ifcbit=(0,1)) 10 | q.qmeasure([1]) 11 | q.qgate(qsim.X(),[2], ifcbit=(3,0)) 12 | q.qmeasure([2]) 13 | -------------------------------------------------------------------------------- /tests/qsim/initialize-state-dm.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | import numpy as np 3 | 4 | try: 5 | nqbits = 6 6 | 7 | # initialise with the default state of all qbits = |0> 8 | q = qsim.DMQSimulator(nqbits,qtrace=True) 9 | q.qgate(qsim.H(),[1]) 10 | q.qgate(qsim.C(),[1,0]) 11 | 12 | # initialise with initial states of qbits 13 | q = qsim.DMQSimulator(nqbits,prepqubits=[[1,0],[1,0],[1,0],[0,1],[1,0],[0,1]],qtrace=True) 14 | q.qgate(qsim.H(),[1]) 15 | q.qgate(qsim.C(),[1,0]) 16 | 17 | # or build the full state yourself (good if you need a very custom state, e.g., for testing QFT) 18 | initstate = [None]*(2**nqbits) 19 | p = 0 20 | stsz = 2**nqbits 21 | for i in range(stsz): 22 | c = np.cos(i*2*np.pi/stsz) 23 | s = np.sin(i*2*np.pi/stsz) 24 | initstate[i] = complex(c,s) 25 | p += np.absolute(initstate[i])**2 26 | initstate = np.transpose(np.matrix(initstate,dtype=complex))/np.sqrt(p) 27 | q = qsim.DMQSimulator(nqbits,initstate=initstate, qtrace=True) 28 | q.qgate(qsim.H(),[1]) 29 | q.qgate(qsim.C(),[1,0]) 30 | 31 | except qsim.QSimError as ex: 32 | print(ex.args) 33 | -------------------------------------------------------------------------------- /tests/qsim/initialize-state.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | import numpy as np 3 | 4 | try: 5 | nqbits = 6 6 | 7 | # initialise with the default state of all qbits = |0> 8 | q = qsim.QSimulator(nqbits,qtrace=True) 9 | q.qgate(qsim.H(),[1]) 10 | q.qgate(qsim.C(),[1,0]) 11 | 12 | # initialise with initial states of qbits 13 | q = qsim.QSimulator(nqbits,prepqubits=[[1,0],[1,0],[1,0],[0,1],[1,0],[0,1]],qtrace=True) 14 | q.qgate(qsim.H(),[1]) 15 | q.qgate(qsim.C(),[1,0]) 16 | 17 | # or build the full state yourself (good if you need a very custom state, e.g., for testing QFT) 18 | initstate = [None]*(2**nqbits) 19 | p = 0 20 | stsz = 2**nqbits 21 | for i in range(stsz): 22 | c = np.cos(i*2*np.pi/stsz) 23 | s = np.sin(i*2*np.pi/stsz) 24 | initstate[i] = complex(c,s) 25 | p += np.absolute(initstate[i])**2 26 | initstate = np.transpose(np.matrix(initstate,dtype=complex))/np.sqrt(p) 27 | q = qsim.QSimulator(nqbits,initstate=initstate, qtrace=True) 28 | q.qgate(qsim.H(),[1]) 29 | q.qgate(qsim.C(),[1,0]) 30 | 31 | except qsim.QSimError as ex: 32 | print(ex.args) 33 | -------------------------------------------------------------------------------- /tests/qsim/noise-op-vs-seq.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | import qsim.noisemodel as nmdl 5 | 6 | print('01 All NoiseOperatorSequence') 7 | noise_model = { 8 | 'noise_chan_init': nmdl.qNoiseChannelSequence(nmdl.phase_flip(probability=0.2)), 9 | 'noise_chan_allgates': nmdl.qNoiseChannelSequence(nmdl.depolarizing(probability=0.1)), 10 | 'noise_chan_qubits': nmdl.qNoiseChannelApplierSequense(nmdl.qNoiseChannelSequence(nmdl.bit_flip(probability=0.3)),[1]), 11 | } 12 | q = qsim.DMQSimulator(3, noise_profile=noise_model, qtrace=True, verbose=True) 13 | q.qgate(qsim.X(),[0]) 14 | q.qnoise(noise_chan=nmdl.qNoiseChannelSequence(nmdl.bit_flip(probability=0.1)), qbit_list=[0,1,2], qtrace=True) 15 | q.qgate(qsim.C(),[0,1]) 16 | q.qgate(qsim.X(),[2], noise_chan=nmdl.qNoiseChannelSequence(nmdl.phase_flip(probability=0.1))) 17 | q.qgate(qsim.H(),[2]) 18 | 19 | print('02 All NoiseOperator only') 20 | noise_model = { 21 | 'noise_chan_init': nmdl.phase_flip(probability=0.2), 22 | 'noise_chan_allgates': nmdl.depolarizing(probability=0.1), 23 | 'noise_chan_qubits': nmdl.qNoiseChannelApplierSequense(nmdl.bit_flip(probability=0.3),[1]), 24 | } 25 | q = qsim.DMQSimulator(3, noise_profile=noise_model, qtrace=True, verbose=True) 26 | q.qgate(qsim.X(),[0]) 27 | q.qnoise(noise_chan=nmdl.bit_flip(probability=0.1), qbit_list=[0,1,2], qtrace=True) 28 | q.qgate(qsim.C(),[0,1]) 29 | q.qgate(qsim.X(),[2], noise_chan=nmdl.phase_flip(probability=0.1)) 30 | q.qgate(qsim.H(),[2]) 31 | -------------------------------------------------------------------------------- /tests/qsim/noise-test-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | import qsim.noisemodel as nmdl 5 | 6 | 7 | # print the list of canned kraus channels 8 | noise_channels = list(nmdl.noise_channel_list().keys()) 9 | noise_channels.sort() 10 | print(noise_channels) 11 | print() 12 | 13 | # test 01 - without any noise model 14 | print('test 01 - without any noise model') 15 | q = qsim.DMQSimulator(3,qtrace=True, verbose=True) 16 | q.qgate(qsim.X(),[0]) 17 | q.qgate(qsim.C(),[0,1]) 18 | q.qgate(qsim.X(),[2]) 19 | q.qgate(qsim.H(),[2]) 20 | 21 | # test 02 - direct call to qnoise 22 | print('test 02 - direct call to qnoise') 23 | q = qsim.DMQSimulator(3,qtrace=True, verbose=True) 24 | q.qgate(qsim.X(),[0]) 25 | q.qnoise(noise_chan=nmdl.qNoiseChannelSequence(nmdl.bit_flip(probability=0.1)), qbit_list=[0,1,2], qtrace=True) 26 | q.qgate(qsim.C(),[0,1]) 27 | q.qgate(qsim.X(),[2]) 28 | q.qgate(qsim.H(),[2]) 29 | 30 | # test 03 - adding noise applied to a gate invokation 31 | print('test 03 - adding noise applied to a gate invokation') 32 | q = qsim.DMQSimulator(3,qtrace=True, verbose=True) 33 | q.qgate(qsim.X(),[0]) 34 | q.qnoise(noise_chan=nmdl.qNoiseChannelSequence(nmdl.bit_flip(probability=0.1)), qbit_list=[0,1,2], qtrace=True) 35 | q.qgate(qsim.C(),[0,1]) 36 | q.qgate(qsim.X(),[2], noise_chan=nmdl.qNoiseChannelSequence(nmdl.phase_flip(probability=0.1))) 37 | q.qgate(qsim.H(),[2]) 38 | 39 | # test 04 - adding noise applied to all gates 40 | print('test 04 - adding noise at init, applied to specifc qubits, all gates') 41 | noise_model = { 42 | 'noise_chan_init': nmdl.qNoiseChannelSequence(nmdl.phase_flip(probability=0.2)), 43 | 'noise_chan_allgates': nmdl.qNoiseChannelSequence(nmdl.depolarizing(probability=0.1)), 44 | 'noise_chan_qubits': nmdl.qNoiseChannelApplierSequense(nmdl.qNoiseChannelSequence(nmdl.bit_flip(probability=0.3)),[1]), 45 | } 46 | q = qsim.DMQSimulator(3, noise_profile=noise_model, qtrace=True, verbose=True) 47 | q.qgate(qsim.X(),[0]) 48 | q.qnoise(noise_chan=nmdl.qNoiseChannelSequence(nmdl.bit_flip(probability=0.1)), qbit_list=[0,1,2], qtrace=True) 49 | q.qgate(qsim.C(),[0,1]) 50 | q.qgate(qsim.X(),[2], noise_chan=nmdl.qNoiseChannelSequence(nmdl.phase_flip(probability=0.1))) 51 | q.qgate(qsim.H(),[2]) 52 | 53 | # test 05 - a blanket test for all noise operators applied to all gates, using their default arguments 54 | for nchanid in noise_channels: 55 | if nmdl.noise_channel_lookup(nchanid)().nqubits != 1: 56 | # print(f'skipped {nchanid}') 57 | continue 58 | print(f'test 05 - Blanket test - {nchanid}') 59 | krfn = nmdl.noise_channel_lookup(nchanid) 60 | noise_model = { 61 | 'noise_chan_allgates': nmdl.qNoiseChannelSequence(krfn()), 62 | 'noise_chan_init': None 63 | } 64 | q = qsim.DMQSimulator(3, noise_profile=noise_model, qtrace=True, verbose=True) 65 | q.qgate(qsim.X(),[0]) 66 | q.qnoise(noise_chan=nmdl.qNoiseChannelSequence(nmdl.bit_flip(probability=0.1)), qbit_list=[0,1,2], qtrace=True) 67 | q.qgate(qsim.C(),[0,1]) 68 | q.qgate(qsim.X(),[2], noise_chan=nmdl.qNoiseChannelSequence(nmdl.phase_flip(probability=0.1))) 69 | q.qgate(qsim.H(),[2]) 70 | 71 | # test 06 - 2-qubit noise op - two_qubit_dephasing 72 | print('test 06 - adding noise at init, applied to specifc qubits, all gates') 73 | q = qsim.DMQSimulator(3, noise_profile=None, qtrace=True, verbose=True) 74 | q.qgate(qsim.H(),[0]) 75 | q.qgate(qsim.C(),[0,1], noise_chan=nmdl.two_qubit_dephasing(probability=0.1)) 76 | 77 | # test 07 - 2-qubit noise op - two_qubit_depolarizing 78 | print('test 07 - adding noise at init, applied to specifc qubits, all gates') 79 | q = qsim.DMQSimulator(3, noise_profile=None, qtrace=True, verbose=True) 80 | q.qgate(qsim.H(),[0]) 81 | q.qgate(qsim.C(),[0,1], noise_chan=nmdl.two_qubit_depolarizing(probability=0.1)) 82 | 83 | # test0x - list noise channel/operator signatures 84 | noise_chans_list = nmdl.noise_channel_list() 85 | for nchanid in noise_chans_list.keys(): 86 | print(f'{nchanid:30s} {noise_chans_list[nchanid]}') -------------------------------------------------------------------------------- /tests/qsim/probestates-qzeros-test-dm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | 5 | q = qsim.DMQSimulator(3,qtrace=True, verbose=True) 6 | q.qgate(qsim.H(),[2]) 7 | q.qgate(qsim.C(),[2,1]) 8 | q.qreport('Entangled state') 9 | q.qzerosON(True) 10 | q.qmeasure([2,1]) 11 | q.qreport('Final state', probestates=[0,7]) 12 | 13 | -------------------------------------------------------------------------------- /tests/qsim/probestates-qzeros-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import qsim 4 | 5 | q = qsim.QSimulator(3,qtrace=True, verbose=True) 6 | q.qgate(qsim.H(),[2]) 7 | q.qgate(qsim.C(),[2,1]) 8 | q.qreport('Entangled state') 9 | q.qzerosON(True) 10 | q.qmeasure([2,1]) 11 | q.qreport('Final state', probestates=[0,7]) 12 | 13 | -------------------------------------------------------------------------------- /tests/qsim/qsim-dmqsim-dropinreplacement.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | import qsim.noisemodel as nmdl 3 | 4 | def common_qops(qc:qsim.QSimulator): 5 | qc.qgate(oper=qsim.H(),qbit_list=[0], noise_chan=nmdl.amplitude_damping(gamma=0.05)) 6 | qc.qgate(qsim.C(),[0,3]) 7 | qc.qnoise(noise_chan=nmdl.two_qubit_dephasing(probability=0.05),qbit_list=[0,1]) 8 | 9 | 10 | noise_model = { 11 | 'noise_chan_init': nmdl.bit_flip(probability=0.05), 12 | 'noise_chan_allgates': nmdl.depolarizing(probability=0.05) 13 | } 14 | qc = qsim.DMQSimulator(4, noise_profile=noise_model, qtrace=True) 15 | common_qops(qc) 16 | 17 | 18 | qc = qsim.QSimulator(4, noise_profile=noise_model, qtrace=True) 19 | common_qops(qc) 20 | 21 | -------------------------------------------------------------------------------- /tests/qsim/qsimcli-test.py: -------------------------------------------------------------------------------- 1 | import qsim.qcli as cli 2 | import sys 3 | import io 4 | 5 | cliscript = """i 4 6 | h 0 7 | c 0 1 8 | x 0 9 | y 0 10 | z 0 11 | q 12 | 13 | """ 14 | 15 | sys.stdin= io.StringIO(cliscript) 16 | cli.main() -------------------------------------------------------------------------------- /tests/qsim/runstats-dm.py: -------------------------------------------------------------------------------- 1 | 2 | import qsim 3 | 4 | q = qsim.DMQSimulator(4,qtrace=True) 5 | 6 | # H gate 7 | q.qgate(qsim.H(),[2]) 8 | q.qgate(qsim.H(),[3]) 9 | # C gate 10 | q.qgate(qsim.C(),[2,0]) 11 | q.qgate(qsim.C(),[3,1]) 12 | 13 | ## X gate 14 | q.qgate(qsim.X(),[0]) 15 | q.qgate(qsim.X(),[1]) 16 | q.qgate(qsim.X(),[2]) 17 | q.qgate(qsim.X(),[3]) 18 | 19 | print('Total operation steps', q.qsteps) 20 | op_names = [k for k in q.op_counts] 21 | op_names.sort() 22 | for k in op_names: 23 | print(' ',k, q.op_counts[k]) 24 | -------------------------------------------------------------------------------- /tests/qsim/runstats.py: -------------------------------------------------------------------------------- 1 | 2 | import qsim 3 | 4 | q = qsim.QSimulator(4,qtrace=True) 5 | 6 | # H gate 7 | q.qgate(qsim.H(),[2]) 8 | q.qgate(qsim.H(),[3]) 9 | # C gate 10 | q.qgate(qsim.C(),[2,0]) 11 | q.qgate(qsim.C(),[3,1]) 12 | 13 | ## X gate 14 | q.qgate(qsim.X(),[0]) 15 | q.qgate(qsim.X(),[1]) 16 | q.qgate(qsim.X(),[2]) 17 | q.qgate(qsim.X(),[3]) 18 | 19 | print('Total operation steps', q.qsteps) 20 | op_names = [k for k in q.op_counts] 21 | op_names.sort() 22 | for k in op_names: 23 | print(' ',k, q.op_counts[k]) 24 | -------------------------------------------------------------------------------- /tests/qsim/stretch-op-dm.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | 3 | qc = qsim.DMQSimulator(8,qtrace=True) 4 | qc.qgate(qsim.H(),[3]) 5 | qc.qgate(qsim.C(),[3,0]) 6 | 7 | print() 8 | print("------------------------------------------------------------") 9 | 10 | qc = qsim.DMQSimulator(8,qtrace=True) 11 | qc.qgate(qsim.H(),[3]) 12 | stC = qc.qstretch(qsim.C(),[3,0]) 13 | qc.qgate(stC,[7,6,5,4,3,2,1,0]) 14 | -------------------------------------------------------------------------------- /tests/qsim/stretch-op.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | 3 | qc = qsim.QSimulator(8,qtrace=True) 4 | qc.qgate(qsim.H(),[3]) 5 | qc.qgate(qsim.C(),[3,0]) 6 | 7 | print() 8 | print("------------------------------------------------------------") 9 | 10 | qc = qsim.QSimulator(8,qtrace=True) 11 | qc.qgate(qsim.H(),[3]) 12 | stC = qc.qstretch(qsim.C(),[3,0]) 13 | qc.qgate(stC,[7,6,5,4,3,2,1,0]) 14 | -------------------------------------------------------------------------------- /tests/qsim/user-def-gates-dm.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import qsim 3 | 4 | qc = qsim.DMQSimulator(8,qtrace=True) 5 | 6 | print() 7 | print("------------------------------------------------") 8 | print("Demonstrating User-defined CNOT gate ...") 9 | def myCNOT(): 10 | return ["MY-CNOT", numpy.matrix([[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]],dtype=complex)] 11 | qc.qgate(qsim.H(),[4]) 12 | qc.qgate(myCNOT(),[4,7]) 13 | qc.qgate(qsim.C(),[4,7]) 14 | qc.qgate(qsim.H(),[4]) 15 | 16 | print() 17 | print("------------------------------------------------") 18 | print("Demonstrating User-defined Phase Rotation gate ...") 19 | def myR(theta): 20 | c = numpy.cos(theta) 21 | s = numpy.sin(theta) 22 | return ["MY-Rotation({:0.4f})".format(theta), numpy.matrix([[1,0],[0,complex(c,s)]],dtype=complex)] 23 | qc.qgate(qsim.X(),[5]) 24 | qc.qgate(myR(numpy.pi/2),[5]) 25 | -------------------------------------------------------------------------------- /tests/qsim/user-def-gates.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import qsim 3 | 4 | qc = qsim.QSimulator(8,qtrace=True) 5 | 6 | print() 7 | print("------------------------------------------------") 8 | print("Demonstrating User-defined CNOT gate ...") 9 | def myCNOT(): 10 | return ["MY-CNOT", numpy.matrix([[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]],dtype=complex)] 11 | qc.qgate(qsim.H(),[4]) 12 | qc.qgate(myCNOT(),[4,7]) 13 | qc.qgate(qsim.C(),[4,7]) 14 | qc.qgate(qsim.H(),[4]) 15 | 16 | print() 17 | print("------------------------------------------------") 18 | print("Demonstrating User-defined Phase Rotation gate ...") 19 | def myR(theta): 20 | c = numpy.cos(theta) 21 | s = numpy.sin(theta) 22 | return ["MY-Rotation({:0.4f})".format(theta), numpy.matrix([[1,0],[0,complex(c,s)]],dtype=complex)] 23 | qc.qgate(qsim.X(),[5]) 24 | qc.qgate(myR(numpy.pi/2),[5]) 25 | -------------------------------------------------------------------------------- /tests/qsim/visualize.py: -------------------------------------------------------------------------------- 1 | import qsim 2 | 3 | q = qsim.QSimulator(4,qtrace=True,qzeros=True,visualize=True) 4 | 5 | q.qgate(qsim.H(),[1]) 6 | q.qgate(qsim.C(),[1,0]) 7 | q.qreport(header="Probing states",probestates=[0,1,2,3]) 8 | q.qgate(qsim.H(),[2]) 9 | q.qgate(qsim.H(),[3]) 10 | --------------------------------------------------------------------------------