├── .gitignore ├── LICENSE ├── README ├── TODO ├── bin ├── .gitignore ├── QCV.cfg ├── arch │ └── 4LNN.arch ├── data │ ├── fonts │ │ └── cmbx12.ttf │ ├── pan.png │ └── pan.svg ├── demos │ ├── QFT6.qc │ ├── QFT9.qc │ ├── arithmetic │ │ ├── adders │ │ │ ├── carry_select_adder_16.qc │ │ │ └── ripple_adder_6.qc │ │ └── kara.qc │ ├── euclid.qc │ ├── grover.qc │ ├── nextedexample.qc │ ├── oneBitExample.qc │ ├── qecc │ │ └── 3qubitECC.qc │ └── small_circuits │ │ ├── controlledHPY.qc │ │ └── toffoli-t-depth-4.qc ├── gateLib └── tex │ ├── prauctex.cfg │ ├── prauctex.def │ ├── prcounters.def │ ├── preview.drv │ ├── preview.dtx │ ├── preview.ins │ ├── preview.log │ ├── preview.sty │ ├── prfootnotes.def │ ├── prlyx.def │ ├── prshowbox.def │ ├── prshowlabels.def │ ├── prtightpage.def │ └── prtracingall.def ├── build ├── .gitignore ├── debug │ └── build ├── default │ └── build ├── nightly ├── package-linux ├── package-windows ├── publish └── release │ ├── build │ └── clean ├── docs ├── .gitignore ├── Makefile ├── QCV.bib ├── QCViewer.tex ├── gi.png ├── gp.png ├── grover_circuit.eps ├── grover_netlist.png ├── manual │ ├── Figures │ │ ├── CreateCircuit │ │ │ ├── CNOT.eps │ │ │ ├── Cursor.png │ │ │ ├── DisplayState.png │ │ │ ├── EPRCircuit.eps │ │ │ ├── EPRCircuit2.eps │ │ │ ├── LoadState.png │ │ │ ├── New.png │ │ │ ├── NumberOfQubits.png │ │ │ ├── Properties.png │ │ │ └── TemplateCircuit.eps │ │ ├── DisplayState.png │ │ ├── Gates │ │ │ ├── Gates.png │ │ │ ├── GatesMatrices.png │ │ │ ├── Hadamard.png │ │ │ ├── HadamardViewer.eps │ │ │ ├── Mod2.png │ │ │ ├── PAdjointGate.png │ │ │ ├── PAdjointGateViewer.eps │ │ │ ├── PGate.png │ │ │ ├── PGateViewer.eps │ │ │ ├── RotXGateViewer.eps │ │ │ ├── RotYGateViewer.eps │ │ │ ├── RotZGateViewer.eps │ │ │ ├── RotationDialog.png │ │ │ ├── RotationGate.png │ │ │ ├── SwapGate.png │ │ │ ├── SwapGateViewer.eps │ │ │ ├── TAdjointGate.png │ │ │ ├── TAdjointGateViewer.eps │ │ │ ├── TGate.png │ │ │ ├── TGateViewer.eps │ │ │ ├── XGate.png │ │ │ ├── XGateViewer.eps │ │ │ ├── YGate.png │ │ │ ├── YGateViewer.eps │ │ │ ├── ZGate.png │ │ │ └── ZGateViewer.eps │ │ ├── Logo.png │ │ ├── Menu │ │ │ ├── Circuit.png │ │ │ ├── Diagram.png │ │ │ ├── File.png │ │ │ ├── Help.png │ │ │ ├── MenuBar.png │ │ │ └── Simulate.png │ │ ├── Misc │ │ │ ├── DeleteMenu.png │ │ │ ├── LoopCount.png │ │ │ └── LoopsMenu.png │ │ ├── Navigation │ │ │ ├── DisplayState.png │ │ │ ├── LoadState.png │ │ │ ├── LoadStateDialog.png │ │ │ ├── NavigationBar.png │ │ │ ├── Open.png │ │ │ ├── OpenDialog.png │ │ │ ├── Pan.png │ │ │ ├── PanEnabled.png │ │ │ ├── Ratio.png │ │ │ ├── Reset.png │ │ │ ├── Run.png │ │ │ └── Step.png │ │ ├── QCFiles │ │ │ ├── EPRCircuit.eps │ │ │ ├── EPRCircuitLabel.eps │ │ │ └── EPRQCFile.png │ │ ├── QCViewerGUI.png │ │ ├── SubCircuits │ │ │ ├── GroverCircuit.eps │ │ │ ├── GroverCircuitExpand.eps │ │ │ ├── GroverCircuitUnroll.eps │ │ │ └── SubCircuitMenu.png │ │ ├── iqclogo.eps │ │ ├── iqclogo.svg │ │ └── simulate.png │ ├── Makefile │ └── QCViewerDocumentation.tex ├── poster │ ├── Makefile │ ├── QCViewer_Abstract.tex │ ├── TQCShortAbstract │ │ ├── Makefile │ │ ├── QCV.bib │ │ ├── cc-by.pdf │ │ ├── lipics-logo-bw.pdf │ │ ├── lipics.cls │ │ └── qcv.tex │ ├── beamerposter.sty │ ├── beamerthemeqcv.sty │ ├── figures │ │ ├── CIFAR_Logo.png │ │ ├── Grover_Circuit.eps │ │ ├── Grover_Circuit.png │ │ ├── Grover_Loop.png │ │ ├── Grover_Roll.png │ │ ├── Grover_Simulate1.png │ │ ├── Grover_Simulate2.png │ │ ├── Grover_Text.png │ │ ├── Grover_Unroll.png │ │ ├── Grover_Unrolled.eps │ │ ├── IQC_Logo.png │ │ ├── Motivation.png │ │ ├── NSERC_Logo.png │ │ ├── PI_Logo.png │ │ ├── QCViewerGUI.png │ │ ├── QuantumWorks_Logo.png │ │ ├── Waterloo_Logo.png │ │ ├── iarpa_logo.png │ │ ├── iqclogo.eps │ │ ├── simulate.png │ │ ├── state.png │ │ ├── torque.png │ │ └── uwlogo-bw-08.eps │ ├── grover.qc │ ├── poster.tex │ └── tangocolors.sty ├── simulate.png ├── slides │ ├── Makefile │ ├── grover_circuit.png │ ├── simulate.png │ └── slides.tex └── state.png ├── doxy └── Doxyfile ├── src ├── CMakeLists.txt ├── QCViewer │ ├── CMakeLists.txt │ ├── GateIcon.cpp │ ├── GateIcon.h │ ├── QCLib │ │ ├── .gitignore │ │ ├── FlexLexer.h │ │ ├── QCLexer.l │ │ ├── QCParser.y │ │ ├── QCParserUtils.cpp │ │ ├── QCParserUtils.h │ │ ├── REQUEST │ │ ├── circuit.cpp │ │ ├── circuit.h │ │ ├── circuitImage.cpp │ │ ├── circuitImage.h │ │ ├── circuitParser.h │ │ ├── circuitWriter.cpp │ │ ├── common.cpp │ │ ├── common.h │ │ ├── dirac.cpp │ │ ├── dirac.h │ │ ├── diracLexer.l │ │ ├── diracParser.y │ │ ├── gate.cpp │ │ ├── gate.h │ │ ├── gates │ │ │ ├── GateLexer.l │ │ │ ├── GateParser.y │ │ │ ├── GateParserUtils.h │ │ │ ├── RGate.cpp │ │ │ ├── UGate.cpp │ │ │ ├── UGateLookup.cpp │ │ │ └── UGateLookup.h │ │ ├── hprhelpers.cpp │ │ ├── hprhelpers.h │ │ ├── mat.h │ │ ├── mat_tests.cpp │ │ ├── normalize.cpp │ │ ├── normalize.h │ │ ├── parseNode.h │ │ ├── pdf.cpp │ │ ├── pdf.h │ │ ├── quigl.cpp │ │ ├── real.hpp │ │ ├── rint.cpp │ │ ├── rint.h │ │ ├── simulate.cpp │ │ ├── simulate.h │ │ ├── state.cpp │ │ ├── state.h │ │ ├── subcircuit.cpp │ │ ├── subcircuit.h │ │ ├── text.cpp │ │ ├── text.h │ │ ├── types.h │ │ ├── ucompiler.cpp │ │ ├── ucompiler.h │ │ ├── unistd.h │ │ ├── utility.cpp │ │ └── utility.h │ ├── TODO │ ├── circuitkit │ │ ├── QCParser.y │ │ ├── QCParserUtils.cpp │ │ ├── QCParserUtils.h │ │ ├── circuit.cpp │ │ ├── circuit.h │ │ ├── circuitParser.h │ │ ├── circuitWriter.cpp │ │ ├── gate.cpp │ │ ├── gate.h │ │ ├── qglcc.rkt │ │ ├── subcircuit.cpp │ │ └── subcircuit.h │ ├── circuitwidget.cpp │ ├── circuitwidget.h │ ├── info.h │ ├── options.h │ ├── qcimage │ │ └── qcimage.cpp │ ├── qcqg │ │ ├── FlexLexer.h │ │ ├── Makefile │ │ ├── QCLexer.l │ │ ├── QCParser.y │ │ ├── QCParserUtils.cpp │ │ ├── QCParserUtils.h │ │ ├── circuit.cpp │ │ ├── circuit.h │ │ ├── circuitParser.h │ │ ├── gate.cpp │ │ ├── gate.h │ │ ├── gates │ │ │ ├── GateLexer.l │ │ │ ├── GateParser.y │ │ │ ├── GateParserUtils.h │ │ │ ├── RGate.cpp │ │ │ ├── UGate.cpp │ │ │ ├── UGateLookup.cpp │ │ │ └── UGateLookup.h │ │ ├── qcqg.cpp │ │ ├── subcircuit.cpp │ │ ├── subcircuit.h │ │ ├── types.h │ │ ├── utility.cpp │ │ └── utility.h │ ├── qcviewer │ │ └── qcviewer.cpp │ ├── stateWidget.cpp │ ├── stateWidget.h │ ├── window.cpp │ └── window.h └── format ├── testCircuits ├── errors.qc ├── faults │ └── notes ├── foo.qc ├── fracRGate.qc ├── fredtest.qc ├── fredtest2.qc ├── gf2^18mult_375_1671.qc ├── gf2^512mult_263677_1312253.qc ├── largeTest.qc ├── mod5d4.qc ├── mod5d4orig.qc ├── neg.qc ├── not.qc ├── oneBit │ └── oneBitTest.qc ├── simple.qc └── test1.qc └── utils └── randCirc └── randCirc.py /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | viewer 3 | CMakeCache.txt 4 | CMakeList.txt 5 | CMakeFiles/* 6 | src/Makefile 7 | cmake_install.cmake 8 | .nfs* 9 | *.orig 10 | *.pyc 11 | cscope.out 12 | tags 13 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | #Build Instructions 2 | 3 | Go into the build directory and choose the folder corresponding to the 4 | build type you want. Enter the folder and run ./build. 5 | 6 | #Build Dependencies 7 | 8 | - libpoppler-glib-dev 9 | - libgtkmm-2.4-dev 10 | - bison 11 | - flex 12 | - cmake 13 | - boost >= 1.52.0 14 | - libboost-dev 15 | - libboost-filesystem-dev 16 | - libboost-program-options-dev 17 | - libboost-system-dev 18 | - cairo >= 1.10.2 19 | - mpfr 20 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | TODO 2 | ---- 3 | 4 | Short term: 5 | - Consolidate QCLib code and separate circuit datastructure into circuitkit. 6 | - Symbolic representation of elements in Z[1/sqrt(2), i]. Potentially reuse Vadym's code for sqct. 7 | - UI-triggered MATLAB output of whole-circuit unitary and unitary for selection. 8 | - UI-triggered color-coded rendering of circuit and selection unitary. 9 | - Finish update of documentation, replacing figures and screen captures. 10 | - Set up and begin maintaining regular builds for Mac OS X. 11 | - More stringent checks in cmake file. 12 | - Finish updating user guide. 13 | 14 | Medium term: 15 | - Implement grouping of like-named wires into 'buses' as per discussion with Andrei Lapets. 16 | - Fix remaining rendering bugs in various edge cases. 17 | - Implement visual drag-and-drop: Show gate placement as gate is being dragged over circuit. 18 | - Implement dragging of existing gates from point to point in circuit. 19 | - Review all code, attempt to clean up crashes. 20 | - Finish inline code documentation. 21 | 22 | Long term: 23 | - Implement abstract drawing features as per discussion with Martin. 24 | - Design/implement measurement and classical feedback features. 25 | 26 | New fix suggestions: 27 | - Not needing to hold down the mouse & drag for adding gates would be nice 28 | - Moving existing gates in a diagram 29 | - Save should be under File, and not Circuit 30 | - Save dialog should open to the directory of the previous save command 31 | - Save and Save As... should be distinct commands 32 | - When you save a .qc file, .eps, .png, .svg, etc you should auto-append the file extension 33 | (to prevent accidentally overwriting your saved qc with a png) 34 | - Modal dialog should appear asking to confirm overwriting an existing file during save 35 | - Hotkeys for adding gates to a diagram would be sweet 36 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | qcviewer 2 | qcimage 3 | qcviewer.exe 4 | qcimage.exe 5 | -------------------------------------------------------------------------------- /bin/QCV.cfg: -------------------------------------------------------------------------------- 1 | [draw] 2 | dotradius=10.0 3 | -------------------------------------------------------------------------------- /bin/arch/4LNN.arch: -------------------------------------------------------------------------------- 1 | 4 2 | 1 1 3 | 2 0 2 4 | 2 1 3 5 | 1 2 6 | -------------------------------------------------------------------------------- /bin/data/fonts/cmbx12.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/bin/data/fonts/cmbx12.ttf -------------------------------------------------------------------------------- /bin/data/pan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/bin/data/pan.png -------------------------------------------------------------------------------- /bin/demos/QFT6.qc: -------------------------------------------------------------------------------- 1 | .v 1 2 3 4 5 6 2 | .i 1 2 3 4 5 6 3 | .o 1 2 3 4 5 6 4 | .ol 5 | .c 6 | BEGIN 7 | H 1 8 | RZ(1 pi/2) 2 1 9 | H 2 10 | RZ(1 pi/4) 3 1 11 | RZ(1 pi/2) 3 2 12 | H 3 13 | RZ(1 pi/8) 4 1 14 | RZ(1 pi/4) 4 2 15 | RZ(1 pi/2) 4 3 16 | H 4 17 | RZ(1 pi/16) 5 1 18 | RZ(1 pi/8) 5 2 19 | RZ(1 pi/4) 5 3 20 | RZ(1 pi/2) 5 4 21 | H 5 22 | RZ(1 pi/32) 6 1 23 | RZ(1 pi/16) 6 2 24 | RZ(1 pi/8) 6 3 25 | RZ(1 pi/4) 6 4 26 | RZ(1 pi/2) 6 5 27 | H 6; 28 | END 29 | -------------------------------------------------------------------------------- /bin/demos/QFT9.qc: -------------------------------------------------------------------------------- 1 | .v 1 2 3 4 5 6 7 8 9 2 | .i 1 2 3 4 5 6 7 8 9 3 | .o 1 2 3 4 5 6 7 8 9 4 | .ol 5 | .c 6 | BEGIN 7 | H 1 8 | RZ(1) 2 1 9 | H 2 10 | RZ(0.5) 3 1 11 | RZ(1) 3 2 12 | H 3 13 | RZ(0.25) 4 1 14 | RZ(0.5) 4 2 15 | RZ(1) 4 3 16 | H 4 17 | RZ(0.125) 5 1 18 | RZ(0.25) 5 2 19 | RZ(0.5) 5 3 20 | RZ(1) 5 4 21 | H 5 22 | RZ(0.0625) 6 1 23 | RZ(0.125) 6 2 24 | RZ(0.25) 6 3 25 | RZ(0.5) 6 4 26 | RZ(1) 6 5 27 | H 6 28 | RZ(0.03125) 7 1 29 | RZ(0.0625) 7 2 30 | RZ(0.125) 7 3 31 | RZ(0.25) 7 4 32 | RZ(0.5) 7 5 33 | RZ(1) 7 6 34 | H 7 35 | RZ(0.015625) 8 1 36 | RZ(0.03125) 8 2 37 | RZ(0.0625) 8 3 38 | RZ(0.125) 8 4 39 | RZ(0.25) 8 5 40 | RZ(0.5) 8 6 41 | RZ(1) 8 7 42 | H 8 43 | RZ(0.0078125) 9 1 44 | RZ(0.015625) 9 2 45 | RZ(0.03125) 9 3 46 | RZ(0.0625) 9 4 47 | RZ(0.125) 9 5 48 | RZ(0.25) 9 6 49 | RZ(0.5) 9 7 50 | RZ(1) 9 8 51 | H 9 52 | END 53 | -------------------------------------------------------------------------------- /bin/demos/arithmetic/adders/ripple_adder_6.qc: -------------------------------------------------------------------------------- 1 | # A 6 bit reversible adder using the design from 2 | .v b0 a0 0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 3 | .i b0 a0 0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 4 | .o b0 a0 0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 5 | .ol s0 a0 0 s1 a1 s2 a2 s3 a3 s4 a4 s5 a5 z 6 | 7 | BEGIN 8 | tof a1 b1 9 | tof a2 b2 10 | tof a3 b3 11 | tof a4 b4 12 | tof a5 b5 13 | tof a1 0 14 | tof a0 b0 15 | tof 0 16 | tof a2 a1 17 | tof 0 b1 a1 18 | tof a3 a2 19 | tof a1 b2 a2 20 | tof a4 a3 21 | tof a2 b3 a3 22 | tof a5 a4 23 | tof a3 b4 a4 24 | tof a5 z 25 | tof a4 b5 z 26 | tof b2 27 | tof b3; 28 | tof b4 29 | tof b1 30 | tof a1 b2 31 | tof a2 b3 32 | tof a3 b4 33 | tof 0 b1 34 | tof a3 b4 a4 35 | tof b4 36 | tof a5 a4 37 | tof a2 b3 a3 38 | tof b3 39 | tof a4 a3 40 | tof a1 b2 a2 41 | tof b2 42 | tof a3 a2 43 | tof 0 b1 a1 44 | tof a2 a1 45 | tof b1 46 | tof b0 a0 0 47 | tof a1 0 48 | tof a0 b0 49 | tof a1 b1 50 | tof a2 b2 51 | tof a3 b3 52 | tof a4 b4 53 | tof a5 b5 54 | END 55 | -------------------------------------------------------------------------------- /bin/demos/euclid.qc: -------------------------------------------------------------------------------- 1 | .v f11 gr11 f10 gr10 f9 gr9 f8 gr8 f7 gr7 f6 gr6 f5 gr5 f4 gr4 f3 gr3 f2 gr2 f1 gr1 r f gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 2 | .i 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 3 | .o f11 gr11 f10 gr10 f9 gr9 f8 gr8 f7 gr7 f6 gr6 f5 gr5 f4 gr4 f3 gr3 f2 gr2 f1 gr1 r f gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 4 | .ol f11 gr11 f10 gr10 f9 gr9 f8 gr8 f7 gr7 f6 gr6 f5 gr5 f4 gr4 f3 gr3 f2 gr2 f1 gr1 r f gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 5 | 6 | BEGIN MAJ(1 2 3) 7 | tof 3 2 8 | tof 3 1 9 | tof 2 1 3 10 | END MAJ 11 | 12 | BEGIN IMAJ(1 2 3) 13 | tof 2 1 3 14 | tof 3 1 15 | tof 3 2 16 | END MAJ 17 | 18 | BEGIN UMA (1 2 3) 19 | tof 2 1 3 20 | tof 3 1 21 | tof 1 2 22 | END UMA 23 | 24 | BEGIN ADDER(0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z) 25 | MAJ 0 b0 a0 26 | MAJ a0 b1 a1 27 | MAJ a1 b2 a2 28 | MAJ a2 b3 a3 29 | MAJ a3 b4 a4 30 | MAJ a4 b5 a5 31 | tof a5 z 32 | UMA a4 b5 a5 33 | UMA a3 b4 a4 34 | UMA a2 b3 a3 35 | UMA a1 b2 a2 36 | UMA a0 b1 a1 37 | UMA 0 b0 a0 38 | END ADDER 39 | 40 | BEGIN SUBTRACTOR(0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z) 41 | tof a0; tof a1; tof a2; tof a3; tof a4; tof a5 42 | ADDER 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 43 | tof b0; tof a0 44 | tof b1; tof a1 45 | tof b2; tof a2 46 | tof b3; tof a3 47 | tof b4; tof a4 48 | tof b5; tof a5 49 | END SUBTRACTOR 50 | 51 | BEGIN COMPARATOR(0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z) 52 | tof a0; tof a1; tof a2; tof a3; tof a4; tof a5 53 | 54 | MAJ 0 b0 a0 55 | MAJ a0 b1 a1 56 | MAJ a1 b2 a2 57 | MAJ a2 b3 a3 58 | MAJ a3 b4 a4 59 | MAJ a4 b5 a5 60 | tof a5 z 61 | IMAJ a4 b5 a5 62 | IMAJ a3 b4 a4 63 | IMAJ a2 b3 a3 64 | IMAJ a1 b2 a2 65 | IMAJ a0 b1 a1 66 | IMAJ 0 b0 a0 67 | 68 | tof a0; tof a1; tof a2; tof a3; tof a4; tof a5 69 | END COMPARATOR 70 | 71 | BEGIN ITER(f1 r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z) 72 | COMPARATOR 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 73 | fred z gr 74 | fred gr b0 a0 75 | fred gr b1 a1 76 | fred gr b2 a2 77 | fred gr b3 a3 78 | fred gr b4 a4 79 | fred gr b5 a5 80 | SUBTRACTOR r | 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 81 | tof r b0' b1' b2' b3' b4' b5' f1 82 | fred gr b5 a5 83 | fred gr b4 a4 84 | fred gr b3 a3 85 | fred gr b2 a2 86 | fred gr b1 a1 87 | fred gr b0 a0 88 | END ITER 89 | 90 | BEGIN 91 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 92 | fred f f1; fred gr gr1; tof f1 r; 93 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 94 | fred f f2; fred gr gr2; tof f2 r; 95 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 96 | fred f f3; fred gr gr3; tof f3 r; 97 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 98 | fred f f4; fred gr gr4; tof f4 r; 99 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 100 | fred f f5; fred gr gr5; tof f5 r; 101 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 102 | fred f f6; fred gr gr6; tof f6 r; 103 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 104 | fred f f7; fred gr gr7; tof f7 r; 105 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 106 | fred f f8; fred gr gr8; tof f8 r; 107 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 108 | fred f f9; fred gr gr9; tof f9 r; 109 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 110 | fred f f10; fred gr gr10; tof f10 r; 111 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 112 | fred f f11; fred gr gr11; tof f11 r; 113 | ITER f r gr 0 b0 a0 b1 a1 b2 a2 b3 a3 b4 a4 b5 a5 z 114 | END 115 | -------------------------------------------------------------------------------- /bin/demos/grover.qc: -------------------------------------------------------------------------------- 1 | #Use the input state "|0>^5|1>". After each iteration you should see the state corresponding 2 | #the toffoli oracle increase in amplitude maximizing at the 4th iteration. 3 | 4 | .v a b c d e Workspace 5 | .i a b c d e Workspace 6 | .o a b c d e 7 | .c 8 | BEGIN H5(a b c d e) 9 | H a 10 | H b 11 | H c 12 | H d 13 | H e 14 | END H5 15 | 16 | BEGIN GroverIterate (a b c d e Workspace) 17 | H Workspace 18 | T5 a' b' c d e' Workspace 19 | H Workspace 20 | 21 | H5 a b c d e 22 | 23 | X e 24 | Z a' b' c' d' e 25 | X e 26 | 27 | H5 a b c d e 28 | END GroverIterate 29 | 30 | BEGIN 31 | H5 a b c d e 32 | 33 | GroverIterate^4 a b c d e Workspace 34 | END 35 | -------------------------------------------------------------------------------- /bin/demos/nextedexample.qc: -------------------------------------------------------------------------------- 1 | .v 1 2 2 | .i 1 2 3 | .o 1 2 4 | .ol 1 2 5 | .c 6 | 7 | BEGIN sub1(1 2) 8 | tof 1 2 9 | END sub1 10 | 11 | BEGIN sub2(1 2) 12 | sub1 1 2 13 | sub1 1 2 14 | sub1 1 2 15 | END sub2 16 | 17 | BEGIN sub3(1 2) 18 | sub2 1 2 19 | sub2 1 2 20 | sub2 1 2 21 | END sub3 22 | 23 | BEGIN sub4(1 2) 24 | sub3 1 2 25 | sub3 1 2 26 | sub3 1 2 27 | END sub4 28 | 29 | BEGIN sub5(1 2) 30 | sub4 1 2 31 | sub4 1 2 32 | sub4 1 2 33 | END sub5 34 | 35 | BEGIN sub6(1 2) 36 | sub5 1 2 37 | sub5 1 2 38 | sub5 1 2 39 | END sub6 40 | 41 | BEGIN sub7(1 2) 42 | sub6 1 2 43 | sub6 1 2 44 | sub6 1 2 45 | END sub7 46 | 47 | BEGIN sub8(1 2) 48 | sub7 1 2 49 | sub7 1 2 50 | sub7 1 2 51 | END sub8 52 | 53 | 54 | BEGIN 55 | sub8 1 2 56 | END 57 | -------------------------------------------------------------------------------- /bin/demos/oneBitExample.qc: -------------------------------------------------------------------------------- 1 | .v 1 2 3 2 | .i 1 2 3 3 | .o 1 2 3 4 | 5 | BEGIN 6 | H 3 7 | 1 : HTXHTHYTH 8 | T 2 9 | TOF 1 2 3 10 | END 11 | -------------------------------------------------------------------------------- /bin/demos/qecc/3qubitECC.qc: -------------------------------------------------------------------------------- 1 | .v 1 2 3 4 5 2 | .i 1 2 3 4 5 3 | .o 1 2 3 4 5 4 | .ol 1 2 3 4 5 5 | .c 6 | BEGIN 7 | X 1 2 8 | X 1 3 9 | X 1 4 10 | X 2 4 11 | X 1 5 12 | X 3 5 13 | sadfsadf 4 5 1 14 | X 4 5' 2 15 | X 4' 5 3 16 | X 1 3 17 | X 1 2 18 | END 19 | 20 | -------------------------------------------------------------------------------- /bin/demos/small_circuits/controlledHPY.qc: -------------------------------------------------------------------------------- 1 | .v 1 2 2 | .i 1 2 3 | .o 1 2 4 | .ol 1 2 5 | .c 6 | 7 | BEGIN ControlledH (c, t) 8 | 9 | P* t 10 | H t 11 | T* t 12 | tof c t 13 | T t 14 | H t 15 | P t 16 | 17 | END ControlledH 18 | 19 | BEGIN ControlledP (c, t) 20 | 21 | t2 c t 22 | T* c 23 | T* t 24 | t2 c t 25 | P c 26 | T t 27 | 28 | END ControlledP 29 | 30 | BEGIN ControlledY (c, t) 31 | 32 | p* t 33 | not c t 34 | p t 35 | 36 | END ControlledY 37 | 38 | BEGIN 39 | 40 | ControlledH 1 2 41 | ControlledP 1 2 42 | ControlledY 1 2 43 | 44 | END 45 | -------------------------------------------------------------------------------- /bin/demos/small_circuits/toffoli-t-depth-4.qc: -------------------------------------------------------------------------------- 1 | # found by Matt Amy 2 | .v 1 2 3 3 | .i 1 2 3 4 | .o 1 2 3 5 | .ol 1 2 3 6 | .c 7 | BEGIN 8 | H 2 9 | tof 3 1 10 | T* 2 11 | P 3 12 | tof 1 2 13 | T* 2 14 | T 1 15 | tof 3 2 16 | T* 3 17 | T 2 18 | P* 3 19 | tof 1 2 20 | tof 3 1 21 | T* 1 22 | T 2 23 | tof 3 2 24 | H 2 25 | END 26 | -------------------------------------------------------------------------------- /bin/gateLib: -------------------------------------------------------------------------------- 1 | NAME Hadamard 2 | SYMBOL H 3 | 1/sqrt(2) , 1/sqrt(2) 4 | 1/sqrt(2) , -1/sqrt(2) 5 | 6 | NAME PauliX 7 | SYMBOL X 8 | 0 , 1 9 | 1 , 0 10 | 11 | NAME PauliY 12 | SYMBOL Y 13 | 0 , i 14 | i , 0 15 | 16 | NAME PauliZ 17 | SYMBOL Z 18 | 1 , 0 19 | 0 , -1 20 | 21 | NAME Fred 22 | SYMBOL F 23 | 1 , 0 , 0 , 0 24 | 0 , 0 , 1 , 0 25 | 0 , 1 , 0 , 0 26 | 0 , 0 , 0 , 1 27 | 28 | NAME TGate 29 | SYMBOL T 30 | 1 , 0 31 | 0 , 1/sqrt(2) + i*1/sqrt(2) 32 | 33 | NAME TGateConj 34 | DRAWNAME "T" 35 | LATEXNAME "T^\dagger" 36 | SYMBOL T* 37 | 1 , 0 38 | 0 , 1/sqrt(2) - i*1/sqrt(2) 39 | 40 | NAME PGate 41 | DRAWNAME "S" 42 | SYMBOL P 43 | 1 , 0 44 | 0 , i 45 | 46 | NAME PGateConj 47 | DRAWNAME "S" 48 | LATEXNAME "S^\dagger" 49 | SYMBOL P* 50 | 1 , 0 51 | 0 , -i 52 | -------------------------------------------------------------------------------- /bin/tex/prauctex.cfg: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `prauctex.cfg', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `auccfg') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from prauctex.cfg. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \PreviewMacro*[[][#1{}]\footnote 26 | \PreviewMacro*[?[{@{[]}}{}][#1]\item 27 | \PreviewMacro*\emph 28 | \PreviewMacro*\textrm 29 | \PreviewMacro*\textit 30 | \PreviewMacro*\textsc 31 | \PreviewMacro*\textsf 32 | \PreviewMacro*\textsl 33 | \PreviewMacro*\texttt 34 | \PreviewMacro*\textcolor 35 | \PreviewMacro*\mbox 36 | \PreviewMacro*[][#1{}]\author 37 | \PreviewMacro*[][#1{}]\title 38 | \PreviewMacro*\and 39 | \PreviewMacro*\thanks 40 | \PreviewMacro*[][#1{}]\caption 41 | \preview@delay{\@ifundefined{pr@\string\@startsection}{% 42 | \PreviewMacro*[!!!!!!*][#1{}]\@startsection}{}} 43 | \preview@delay{\@ifundefined{pr@\string\chapter}{% 44 | \PreviewMacro*[*][#1{}]\chapter}{}} 45 | \PreviewMacro*\index 46 | \endinput 47 | %% 48 | %% End of file `prauctex.cfg'. 49 | -------------------------------------------------------------------------------- /bin/tex/prauctex.def: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `prauctex.def', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `auctex') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from prauctex.def. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \ifPreview\else\expandafter\endinput\fi 26 | \nofiles 27 | \preview@delay{\nonstopmode} 28 | \begingroup 29 | \lccode`\~=`\- 30 | \lccode`\{=`\< 31 | \lccode`\}=`\> 32 | \lowercase{\endgroup 33 | \def\pr@msgi{{~}}} 34 | \def\pr@msgii{Preview: 35 | Snippet \number\pr@snippet\space} 36 | \begingroup 37 | \catcode`\-=13 38 | \catcode`\<=13 39 | \@firstofone{\endgroup 40 | \def\pr@msg#1{{% 41 | \let<\pr@msgi 42 | \def-{\pr@msgii#1}% 43 | \errhelp{Not a real error.}% 44 | \errmessage<}}} 45 | \g@addto@macro\pr@ship@start{\pr@msg{started}} 46 | \g@addto@macro\pr@ship@end{\pr@msg{ended.% 47 | (\number\ht\pr@box+\number\dp\pr@box x\number\wd\pr@box)}} 48 | \hbadness=\maxdimen 49 | \newcount\hbadness 50 | \vbadness=\maxdimen 51 | \let\vbadness=\hbadness 52 | \hfuzz=\maxdimen 53 | \newdimen\hfuzz 54 | \vfuzz=\maxdimen 55 | \let\vfuzz=\hfuzz 56 | \showboxdepth=-1 57 | \showboxbreadth=-1 58 | \pr@loadcfg{prauctex} 59 | \endinput 60 | %% 61 | %% End of file `prauctex.def'. 62 | -------------------------------------------------------------------------------- /bin/tex/prcounters.def: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `prcounters.def', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `counters') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from prcounters.def. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \ifPreview\else\expandafter\endinput\fi 26 | \def\pr@eltprint#1{\expandafter\@gobble\ifnum\value{#1}=0% 27 | \csname pr@c@#1\endcsname\else\relax 28 | \space{#1}{\arabic{#1}}\fi} 29 | \def\pr@eltdef#1{\expandafter\xdef 30 | \csname pr@c@#1\endcsname{\arabic{#1}}} 31 | \def\pr@ckpt#1{{\let\@elt\pr@eltprint\edef\next{\cl@@ckpt}% 32 | \ifx\next\@empty\else\typeout{Preview: Counters\next#1}% 33 | \let\@elt\pr@eltdef\cl@@ckpt\fi}} 34 | \pr@addto@front\pr@ship@start{\pr@ckpt:} 35 | \pr@addto@front\pr@ship@end{\pr@ckpt.} 36 | \endinput 37 | %% 38 | %% End of file `prcounters.def'. 39 | -------------------------------------------------------------------------------- /bin/tex/preview.drv: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `preview.drv', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `driver') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from preview.drv. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \documentclass{ltxdoc} 26 | \usepackage{preview} 27 | \let\ifPreview\relax 28 | \newcommand\previewlatex{\texttt{preview-latex}} 29 | \begin{document} 30 | \DocInput{preview.dtx} 31 | \end{document} 32 | \endinput 33 | %% 34 | %% End of file `preview.drv'. 35 | -------------------------------------------------------------------------------- /bin/tex/preview.ins: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `preview.ins', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `installer') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from preview.ins. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \input docstrip 26 | \generate{ 27 | \file{preview.drv}{\from{preview.dtx}{driver}} 28 | \usedir{tex/latex/preview} 29 | \file{preview.sty}{\from{preview.dtx}{style} 30 | \from{preview.dtx}{style,active}} 31 | \file{prauctex.def}{\from{preview.dtx}{auctex}} 32 | \file{prauctex.cfg}{\from{preview.dtx}{auccfg}} 33 | \file{prshowbox.def}{\from{preview.dtx}{showbox}} 34 | \file{prshowlabels.def}{\from{preview.dtx}{showlabels}} 35 | \file{prtracingall.def}{\from{preview.dtx}{tracingall}} 36 | \file{prtightpage.def}{\from{preview.dtx}{tightpage}} 37 | \file{prlyx.def}{\from{preview.dtx}{lyx}} 38 | \file{prcounters.def}{\from{preview.dtx}{counters}} 39 | \file{prfootnotes.def}{\from{preview.dtx}{footnotes}} 40 | } 41 | \endbatchfile 42 | \endinput 43 | %% 44 | %% End of file `preview.ins'. 45 | -------------------------------------------------------------------------------- /bin/tex/prfootnotes.def: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `prfootnotes.def', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `footnotes') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from prfootnotes.def. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \PreviewMacro[[!]\footnote %] 26 | \endinput 27 | %% 28 | %% End of file `prfootnotes.def'. 29 | -------------------------------------------------------------------------------- /bin/tex/prlyx.def: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `prlyx.def', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `lyx') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from prlyx.def. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \ifPreview\else\expandafter\endinput\fi 26 | \pr@loadcfg{prlyx} 27 | \g@addto@macro\pr@ship@end{\typeout{Preview: 28 | Snippet \number\pr@snippet\space 29 | \number\ht\pr@box\space \number\dp\pr@box \space\number\wd\pr@box}} 30 | \endinput 31 | %% 32 | %% End of file `prlyx.def'. 33 | -------------------------------------------------------------------------------- /bin/tex/prshowbox.def: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `prshowbox.def', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `showbox') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from prshowbox.def. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \ifPreview\else\expandafter\endinput\fi 26 | \AtEndOfPackage{% 27 | \showboxbreadth\maxdimen 28 | \showboxdepth\maxdimen} 29 | \g@addto@macro\pr@ship@end{\showbox\pr@box} 30 | \endinput 31 | %% 32 | %% End of file `prshowbox.def'. 33 | -------------------------------------------------------------------------------- /bin/tex/prshowlabels.def: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `prshowlabels.def', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `showlabels') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from prshowlabels.def. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \ifPreview\else\expandafter\endinput\fi 26 | \newbox\pr@labelbox 27 | \def\pr@label#1{\pr@@label{#1}% 28 | \ifpr@setbox\z@{#1}% 29 | \global\setbox\pr@labelbox\vbox{\unvbox\pr@labelbox 30 | \box\z@}\egroup\fi} 31 | \def\ifpr@setbox#1#2{% 32 | \romannumeral% 33 | \ifx\protect\@typeset@protect\ifpr@outer\else 34 | \z@\bgroup 35 | \protected@edef\next{#2}\@onelevel@sanitize\next 36 | \ifx\next\@empty\egroup\romannumeral\else 37 | \ifx\next\pr@lastlabel\egroup\romannumeral\else 38 | \global\let\pr@lastlabel\next 39 | \setbox#1\pr@boxlabel\pr@lastlabel 40 | \expandafter\expandafter\romannumeral\fi\fi\fi\fi 41 | \z@\iffalse\iftrue\fi} 42 | \def\pr@boxlabel#1{\hbox{\normalfont 43 | \footnotesize\ttfamily\fboxsep0.4ex\relax\fbox{#1}}} 44 | \def\pr@maketag#1{\pr@@maketag{#1}% 45 | \ifpr@setbox\z@{\df@label}% 46 | \global\setbox\pr@labelbox\vbox{% 47 | \hrule\@width\wd\z@\@height\z@ 48 | \unvbox\pr@labelbox}% 49 | \wd\z@\z@\box\z@ \egroup\fi} 50 | \g@addto@macro\pr@ship@start{% 51 | \global\setbox\pr@labelbox\box\voidb@x 52 | \xdef\pr@lastlabel{}% 53 | \global\let\pr@@label\label \let\label\pr@label 54 | \global\let\pr@@maketag\maketag@@@ 55 | \let\maketag@@@\pr@maketag 56 | } 57 | \pr@addto@front\pr@ship@end{% 58 | \ifx \label\pr@label \global\let\label\pr@@label \fi 59 | \ifx \maketag@@@\pr@maketag 60 | \global\let\maketag@@@\pr@@maketag \fi 61 | \ifvoid\pr@labelbox 62 | \else \setbox\pr@box\hbox{% 63 | \box\pr@box\,\box\pr@labelbox}% 64 | \fi} 65 | \endinput 66 | %% 67 | %% End of file `prshowlabels.def'. 68 | -------------------------------------------------------------------------------- /bin/tex/prtracingall.def: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `prtracingall.def', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% preview.dtx (with options: `tracingall') 8 | %% 9 | %% IMPORTANT NOTICE: 10 | %% 11 | %% For the copyright see the source file. 12 | %% 13 | %% Any modified versions of this file must be renamed 14 | %% with new filenames distinct from prtracingall.def. 15 | %% 16 | %% For distribution of the original source see the terms 17 | %% for copying and modification in the file preview.dtx. 18 | %% 19 | %% This generated file may be distributed as long as the 20 | %% original source files, as listed above, are part of the 21 | %% same distribution. (The sources need not necessarily be 22 | %% in the same archive or directory.) 23 | %% The preview style for extracting previews from LaTeX documents. 24 | %% Developed as part of AUCTeX . 25 | \ifPreview\else\expandafter\endinput\fi 26 | \pr@addto@front\pr@ship@start{\let\tracingonline\count@ 27 | \let\errorstopmode\@empty\tracingall} 28 | \endinput 29 | %% 30 | %% End of file `prtracingall.def'. 31 | -------------------------------------------------------------------------------- /build/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | -------------------------------------------------------------------------------- /build/debug/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -f CMakeCache.txt 3 | if [ "$1" == "win32" ]; then 4 | . ../cross/setup 5 | cmake -DCMAKE_BUILD_TYPE=debug -DCMAKE_TOOLCHAIN_FILE=../cross/toolchain.cross ../../src 6 | else 7 | cmake -DCMAKE_BUILD_TYPE=debug ../../src 8 | fi 9 | make -j4 install 10 | -------------------------------------------------------------------------------- /build/default/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -f CMakeCache.txt 3 | if [ "$1" == "win32" ]; then 4 | . ../cross/setup 5 | cmake -DCMAKE_TOOLCHAIN_FILE=../cross/toolchain.cross ../../src 6 | else 7 | cmake ../../src 8 | fi 9 | make -j4 install 10 | -------------------------------------------------------------------------------- /build/nightly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function die { 3 | u=$? 4 | echo "$@" >&2 5 | exit $? 6 | } 7 | 8 | nightly="`realpath $0`" 9 | builddir="${nightly%/*}" 10 | mkdir -p "$builddir/log" || die "Couldn't create log directory." 11 | cd "$builddir/release" 12 | git clean -f -X > /dev/null 2>&1 13 | echo "Building documentation..." 14 | for i in docs docs/manual docs/poster docs/slides; do 15 | ( cd "$builddir/../$i" && make ) >> "$builddir/log/latex" 2>&1 16 | done 17 | echo "Building release binaries for Linux..." 18 | ./clean 19 | ./build > "$builddir/log/linux" 2>&1 || die "ERROR during Linux release build!" 20 | echo "Building release binaries for Windows..." 21 | ./clean 22 | ./build win32 > "$builddir/log/windows" 2>&1 || die "ERROR during Windows release build!" 23 | 24 | for i in qcviewer qcimage qcviewer.exe qcimage.exe; do 25 | [ -f ../../bin/$i ] || die "Executable $i was not built." 26 | done 27 | 28 | cd .. 29 | 30 | echo "Creating Linux package..." 31 | ./package-linux || die "ERROR creating Linux package!" 32 | 33 | echo "Creating Windows package..." 34 | ./package-windows || die "ERROR creating Windows package!" 35 | 36 | exit 0 37 | 38 | -------------------------------------------------------------------------------- /build/package-linux: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script packages the Linux build of QCViewer into a 3 | # tarball. 4 | 5 | BINDEPS=/home/aparent/QCViewer-Deps/qcdist 6 | 7 | function die { 8 | u=$? 9 | echo "$@" >&2 10 | exit $? 11 | } 12 | 13 | # Assume we are in the build directory. 14 | ver=`git describe --tags --abbrev=0` 15 | destname="QCViewer-${ver}-`date +%Y-%m-%d`" 16 | workdir=`mktemp -d` 17 | [ -d "$workdir" ] || die "Couldn't create a temporary directory." 18 | 19 | mkdir "$workdir/QCViewer-$ver" 20 | 21 | # Copy documentation 22 | mkdir "$workdir/QCViewer-$ver/docs" 23 | for i in `find ../docs -name '*.tex'`; do 24 | cp `dirname "$i"`/`basename "$i" .tex`.pdf "$workdir/QCViewer-$ver/docs/`basename "$i" .tex`.pdf" > /dev/null 2>&1 25 | done 26 | 27 | cp -r ../bin/* "$workdir/QCViewer-$ver"/ || die "Couldn't copy QCViewer binaries!" 28 | 29 | # Remove non-Linux executables, if they exist. 30 | rm -f "$workdir/QCViewer-$ver"/{qcviewer.exe,qcimage.exe} 31 | 32 | mkdir -p packages || die "Couldn't create packages directory!" 33 | destarc="`realpath packages`/${destname}.tar.gz" 34 | 35 | # Replace an existing archive. 36 | rm -f "$destarc" 37 | 38 | ( cd "$workdir" && tar -zcf "$destarc" "QCViewer-$ver" ) || die "Couldn't create archive!" 39 | 40 | # Clean up. 41 | rm -fr "$workdir" 42 | exit 0 43 | -------------------------------------------------------------------------------- /build/package-windows: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script packages the Windows build of QCViewer into a 3 | # self-contained zip file. 4 | 5 | # The directory containing binary dependencies for QCViewer. 6 | BINDEPS=/home/aparent/QCViewer-Deps/qcdist 7 | 8 | function die { 9 | u=$? 10 | echo "$@" >&2 11 | exit $? 12 | } 13 | 14 | function assert_exe { 15 | which $1 >/dev/null 2>&1 16 | } 17 | 18 | assert_exe zip || die "No zip executable." 19 | 20 | # Assume we are in the build directory. 21 | 22 | ver=`git describe --tags --abbrev=0` 23 | destname="QCViewer-${ver}-`date +%Y-%m-%d`" 24 | workdir=`mktemp -d` 25 | [ -d "$workdir" ] || die "Couldn't create a temporary directory." 26 | 27 | mkdir "$workdir/QCViewer-$ver" 28 | 29 | # Copy documentation 30 | mkdir "$workdir/QCViewer-$ver/docs" 31 | for i in `find ../docs -name '*.tex'`; do 32 | cp `dirname "$i"`/`basename "$i" .tex`.pdf "$workdir/QCViewer-$ver/docs/`basename "$i" .tex`.pdf" > /dev/null 2>&1 33 | done 34 | 35 | cp -r $BINDEPS/* "$workdir/QCViewer-$ver"/ || die "Couldn't copy dependencies!" 36 | cp -r ../bin/* "$workdir/QCViewer-$ver"/ || die "Couldn't copy QCViewer binaries!" 37 | #mv "$workdir/QCViewer-$ver/"*.exe "$workdir/QCViewer-$ver/" || die "Couldn't move QCViewer binaries into bin!" 38 | 39 | # Remove non-Windows executables, if they exist. 40 | # Also remove qcimage as it does not need to be packaged with the windows build 41 | rm -f "$workdir/QCViewer-$ver"/{qcviewer,qcimage,qcimage.exe} 42 | 43 | mkdir -p packages || die "Couldn't create packages directory!" 44 | destarc="`realpath packages`/${destname}.zip" 45 | 46 | # Replace an existing archive. 47 | rm -f "$destarc" 48 | 49 | ( cd "$workdir" && zip -qr "$destarc" "QCViewer-$ver" ) || die "Couldn't create archive!" 50 | 51 | # Clean up. 52 | rm -fr "$workdir" 53 | exit 0 54 | -------------------------------------------------------------------------------- /build/publish: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Your public key must be installed in the build account. 3 | git push qcbuild@hfcs.uwaterloo.ca:QCViewer 4 | -------------------------------------------------------------------------------- /build/release/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -f CMakeCache.txt 3 | if [ "$1" == "win32" ]; then 4 | cmake -DCMAKE_BUILD_TYPE=release -DCMAKE_TOOLCHAIN_FILE=/home/aparent/QCViewer-Deps/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake ../../src 5 | else 6 | cmake -DCMAKE_BUILD_TYPE=release ../../src 7 | fi 8 | make -j4 install 9 | -------------------------------------------------------------------------------- /build/release/clean: -------------------------------------------------------------------------------- 1 | rm -r CMakeCache.txt CMakeFiles/ cmake_install.cmake CMakeTmp/ install_manifest.txt Makefile QCViewer/ 2 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | *.pdf 2 | *.aux 3 | *.bbl 4 | *.blg 5 | *.log 6 | *.out 7 | *.bib 8 | *.nav 9 | *.snm 10 | *.toc 11 | *.vrb 12 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | pdflatex --shell-escape QCViewer.tex 3 | bibtex QCViewer.aux 4 | pdflatex QCViewer.tex 5 | pdflatex QCViewer.tex 6 | -------------------------------------------------------------------------------- /docs/QCV.bib: -------------------------------------------------------------------------------- 1 | @unpublished{maslovBench, 2 | author = "Dmitri Maslov", 3 | title = "Reversible Logic Synthesis Benchmarks Page", 4 | note = "last accessed November 2011", 5 | url = "http://webhome.cs.uvic.ca/~dmaslov/", 6 | } 7 | 8 | @Book{nielsen2000quantum, 9 | author = "Michael A. Nielsen and Isaac L. Chuang", 10 | title = {Quantum computation and quantum information}, 11 | publisher = {Cambridge University Press}, 12 | year = {2000}, 13 | address = {Cambridge New York}, 14 | isbn = {0521635039} 15 | } 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/gi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/gi.png -------------------------------------------------------------------------------- /docs/gp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/gp.png -------------------------------------------------------------------------------- /docs/grover_netlist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/grover_netlist.png -------------------------------------------------------------------------------- /docs/manual/Figures/CreateCircuit/CNOT.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: cairo 1.10.2 (http://cairographics.org) 3 | %%CreationDate: Wed Apr 18 18:52:56 2012 4 | %%Pages: 1 5 | %%BoundingBox: 0 0 60 32 6 | %%DocumentData: Clean7Bit 7 | %%LanguageLevel: 2 8 | %%EndComments 9 | %%BeginProlog 10 | /cairo_eps_state save def 11 | /dict_count countdictstack def 12 | /op_count count 1 sub def 13 | userdict begin 14 | /q { gsave } bind def 15 | /Q { grestore } bind def 16 | /cm { 6 array astore concat } bind def 17 | /w { setlinewidth } bind def 18 | /J { setlinecap } bind def 19 | /j { setlinejoin } bind def 20 | /M { setmiterlimit } bind def 21 | /d { setdash } bind def 22 | /m { moveto } bind def 23 | /l { lineto } bind def 24 | /c { curveto } bind def 25 | /h { closepath } bind def 26 | /re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto 27 | 0 exch rlineto 0 rlineto closepath } bind def 28 | /S { stroke } bind def 29 | /f { fill } bind def 30 | /f* { eofill } bind def 31 | /n { newpath } bind def 32 | /W { clip } bind def 33 | /W* { eoclip } bind def 34 | /BT { } bind def 35 | /ET { } bind def 36 | /pdfmark where { pop globaldict /?pdfmark /exec load put } 37 | { globaldict begin /?pdfmark /pop load def /pdfmark 38 | /cleartomark load def end } ifelse 39 | /BDC { mark 3 1 roll /BDC pdfmark } bind def 40 | /EMC { mark /EMC pdfmark } bind def 41 | /cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def 42 | /Tj { show currentpoint cairo_store_point } bind def 43 | /TJ { 44 | { 45 | dup 46 | type /stringtype eq 47 | { show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse 48 | } forall 49 | currentpoint cairo_store_point 50 | } bind def 51 | /cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore 52 | cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def 53 | /Tf { pop /cairo_font exch def /cairo_font_matrix where 54 | { pop cairo_selectfont } if } bind def 55 | /Td { matrix translate cairo_font_matrix matrix concatmatrix dup 56 | /cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point 57 | /cairo_font where { pop cairo_selectfont } if } bind def 58 | /Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def 59 | cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def 60 | /g { setgray } bind def 61 | /rg { setrgbcolor } bind def 62 | /d1 { setcachedevice } bind def 63 | %%EndProlog 64 | %%Page: 1 1 65 | %%BeginPageSetup 66 | %%PageBoundingBox: 0 0 60 32 67 | %%EndPageSetup 68 | q 0 0 60 32 rectclip q 69 | 0 g 70 | 2 w 71 | 0 J 72 | 0 j 73 | [] 0.0 d 74 | 10 M q 1 0 0 1 0 32 cm 75 | 0 -16 m 60 -16 l S Q 76 | q 1 0 0 1 0 32 cm 77 | 45 -16 m 45 -24.285 38.285 -31 30 -31 c 21.715 -31 15 -24.285 15 -16 c 78 | 15 -7.715 21.715 -1 30 -1 c 38.285 -1 45 -7.715 45 -16 c S Q 79 | q 1 0 0 1 0 32 cm 80 | 15 -16 m 45 -16 l S Q 81 | q 1 0 0 1 0 32 cm 82 | 30 -1 m 30 -31 l S Q 83 | Q Q 84 | showpage 85 | %%Trailer 86 | count op_count sub {pop} repeat 87 | countdictstack dict_count sub {end} repeat 88 | cairo_eps_state restore 89 | %%EOF 90 | -------------------------------------------------------------------------------- /docs/manual/Figures/CreateCircuit/Cursor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/CreateCircuit/Cursor.png -------------------------------------------------------------------------------- /docs/manual/Figures/CreateCircuit/DisplayState.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/CreateCircuit/DisplayState.png -------------------------------------------------------------------------------- /docs/manual/Figures/CreateCircuit/LoadState.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/CreateCircuit/LoadState.png -------------------------------------------------------------------------------- /docs/manual/Figures/CreateCircuit/New.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/CreateCircuit/New.png -------------------------------------------------------------------------------- /docs/manual/Figures/CreateCircuit/NumberOfQubits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/CreateCircuit/NumberOfQubits.png -------------------------------------------------------------------------------- /docs/manual/Figures/CreateCircuit/Properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/CreateCircuit/Properties.png -------------------------------------------------------------------------------- /docs/manual/Figures/DisplayState.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/DisplayState.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/Gates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/Gates.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/GatesMatrices.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/GatesMatrices.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/Hadamard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/Hadamard.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/Mod2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/Mod2.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/PAdjointGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/PAdjointGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/PGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/PGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/RotationDialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/RotationDialog.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/RotationGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/RotationGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/SwapGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/SwapGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/SwapGateViewer.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: cairo 1.10.2 (http://cairographics.org) 3 | %%CreationDate: Thu May 10 18:36:15 2012 4 | %%Pages: 1 5 | %%BoundingBox: 0 -1 52 63 6 | %%DocumentData: Clean7Bit 7 | %%LanguageLevel: 2 8 | %%EndComments 9 | %%BeginProlog 10 | /cairo_eps_state save def 11 | /dict_count countdictstack def 12 | /op_count count 1 sub def 13 | userdict begin 14 | /q { gsave } bind def 15 | /Q { grestore } bind def 16 | /cm { 6 array astore concat } bind def 17 | /w { setlinewidth } bind def 18 | /J { setlinecap } bind def 19 | /j { setlinejoin } bind def 20 | /M { setmiterlimit } bind def 21 | /d { setdash } bind def 22 | /m { moveto } bind def 23 | /l { lineto } bind def 24 | /c { curveto } bind def 25 | /h { closepath } bind def 26 | /re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto 27 | 0 exch rlineto 0 rlineto closepath } bind def 28 | /S { stroke } bind def 29 | /f { fill } bind def 30 | /f* { eofill } bind def 31 | /n { newpath } bind def 32 | /W { clip } bind def 33 | /W* { eoclip } bind def 34 | /BT { } bind def 35 | /ET { } bind def 36 | /pdfmark where { pop globaldict /?pdfmark /exec load put } 37 | { globaldict begin /?pdfmark /pop load def /pdfmark 38 | /cleartomark load def end } ifelse 39 | /BDC { mark 3 1 roll /BDC pdfmark } bind def 40 | /EMC { mark /EMC pdfmark } bind def 41 | /cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def 42 | /Tj { show currentpoint cairo_store_point } bind def 43 | /TJ { 44 | { 45 | dup 46 | type /stringtype eq 47 | { show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse 48 | } forall 49 | currentpoint cairo_store_point 50 | } bind def 51 | /cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore 52 | cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def 53 | /Tf { pop /cairo_font exch def /cairo_font_matrix where 54 | { pop cairo_selectfont } if } bind def 55 | /Td { matrix translate cairo_font_matrix matrix concatmatrix dup 56 | /cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point 57 | /cairo_font where { pop cairo_selectfont } if } bind def 58 | /Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def 59 | cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def 60 | /g { setgray } bind def 61 | /rg { setrgbcolor } bind def 62 | /d1 { setcachedevice } bind def 63 | %%EndProlog 64 | %%Page: 1 1 65 | %%BeginPageSetup 66 | %%PageBoundingBox: 0 -1 52 63 67 | %%EndPageSetup 68 | q 0 -1 52 64 rectclip q 69 | 0 62.625 52 -63 re W n 70 | 0 g 71 | 2 w 72 | 0 J 73 | 0 j 74 | [] 0.0 d 75 | 10 M q 1 0 0 1 0 62.625 cm 76 | 0 -11.312 m 51.215 -11.312 l S Q 77 | q 1 0 0 1 0 62.625 cm 78 | 0 -51.312 m 51.215 -51.312 l S Q 79 | q 1 0 0 1 0 62.625 cm 80 | 14.395 -0.707 m 35.605 -21.918 l S Q 81 | q 1 0 0 1 0 62.625 cm 82 | 35.605 -0.707 m 14.395 -21.918 l S Q 83 | q 1 0 0 1 0 62.625 cm 84 | 14.395 -40.707 m 35.605 -61.918 l S Q 85 | q 1 0 0 1 0 62.625 cm 86 | 35.605 -40.707 m 14.395 -61.918 l S Q 87 | q 1 0 0 1 0 62.625 cm 88 | 25 -11.312 m 25 -51.312 l S Q 89 | Q Q 90 | showpage 91 | %%Trailer 92 | count op_count sub {pop} repeat 93 | countdictstack dict_count sub {end} repeat 94 | cairo_eps_state restore 95 | %%EOF 96 | -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/TAdjointGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/TAdjointGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/TGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/TGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/XGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/XGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/YGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/YGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Gates/ZGate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Gates/ZGate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Logo.png -------------------------------------------------------------------------------- /docs/manual/Figures/Menu/Circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Menu/Circuit.png -------------------------------------------------------------------------------- /docs/manual/Figures/Menu/Diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Menu/Diagram.png -------------------------------------------------------------------------------- /docs/manual/Figures/Menu/File.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Menu/File.png -------------------------------------------------------------------------------- /docs/manual/Figures/Menu/Help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Menu/Help.png -------------------------------------------------------------------------------- /docs/manual/Figures/Menu/MenuBar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Menu/MenuBar.png -------------------------------------------------------------------------------- /docs/manual/Figures/Menu/Simulate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Menu/Simulate.png -------------------------------------------------------------------------------- /docs/manual/Figures/Misc/DeleteMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Misc/DeleteMenu.png -------------------------------------------------------------------------------- /docs/manual/Figures/Misc/LoopCount.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Misc/LoopCount.png -------------------------------------------------------------------------------- /docs/manual/Figures/Misc/LoopsMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Misc/LoopsMenu.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/DisplayState.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/DisplayState.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/LoadState.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/LoadState.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/LoadStateDialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/LoadStateDialog.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/NavigationBar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/NavigationBar.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/Open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/Open.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/OpenDialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/OpenDialog.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/Pan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/Pan.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/PanEnabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/PanEnabled.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/Ratio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/Ratio.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/Reset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/Reset.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/Run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/Run.png -------------------------------------------------------------------------------- /docs/manual/Figures/Navigation/Step.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/Navigation/Step.png -------------------------------------------------------------------------------- /docs/manual/Figures/QCFiles/EPRQCFile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/QCFiles/EPRQCFile.png -------------------------------------------------------------------------------- /docs/manual/Figures/QCViewerGUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/QCViewerGUI.png -------------------------------------------------------------------------------- /docs/manual/Figures/SubCircuits/SubCircuitMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/SubCircuits/SubCircuitMenu.png -------------------------------------------------------------------------------- /docs/manual/Figures/simulate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/manual/Figures/simulate.png -------------------------------------------------------------------------------- /docs/manual/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | pdflatex --shell-escape QCViewerDocumentation.tex 3 | pdflatex QCViewerDocumentation.tex 4 | -------------------------------------------------------------------------------- /docs/poster/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | pdflatex --shell-escape poster.tex 3 | pdflatex poster.tex 4 | -------------------------------------------------------------------------------- /docs/poster/TQCShortAbstract/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | pdflatex --shell-escape qcv.tex 3 | bibtex qcv.aux 4 | pdflatex qcv.tex 5 | pdflatex qcv.tex 6 | -------------------------------------------------------------------------------- /docs/poster/TQCShortAbstract/QCV.bib: -------------------------------------------------------------------------------- 1 | @unpublished{maslovBench, 2 | author = "Dmitri Maslov", 3 | title = "Reversible Logic Synthesis Benchmarks Page", 4 | note = "last accessed November 2011", 5 | url = "http://webhome.cs.uvic.ca/~dmaslov/", 6 | } 7 | 8 | @Book{nielsen2000quantum, 9 | author = "Michael A. Nielsen and Isaac L. Chuang", 10 | title = {Quantum computation and quantum information}, 11 | publisher = {Cambridge University Press}, 12 | year = {2000}, 13 | address = {Cambridge New York}, 14 | isbn = {0521635039} 15 | } 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/poster/TQCShortAbstract/cc-by.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/TQCShortAbstract/cc-by.pdf -------------------------------------------------------------------------------- /docs/poster/TQCShortAbstract/lipics-logo-bw.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/TQCShortAbstract/lipics-logo-bw.pdf -------------------------------------------------------------------------------- /docs/poster/figures/CIFAR_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/CIFAR_Logo.png -------------------------------------------------------------------------------- /docs/poster/figures/Grover_Circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Grover_Circuit.png -------------------------------------------------------------------------------- /docs/poster/figures/Grover_Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Grover_Loop.png -------------------------------------------------------------------------------- /docs/poster/figures/Grover_Roll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Grover_Roll.png -------------------------------------------------------------------------------- /docs/poster/figures/Grover_Simulate1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Grover_Simulate1.png -------------------------------------------------------------------------------- /docs/poster/figures/Grover_Simulate2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Grover_Simulate2.png -------------------------------------------------------------------------------- /docs/poster/figures/Grover_Text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Grover_Text.png -------------------------------------------------------------------------------- /docs/poster/figures/Grover_Unroll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Grover_Unroll.png -------------------------------------------------------------------------------- /docs/poster/figures/IQC_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/IQC_Logo.png -------------------------------------------------------------------------------- /docs/poster/figures/Motivation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Motivation.png -------------------------------------------------------------------------------- /docs/poster/figures/NSERC_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/NSERC_Logo.png -------------------------------------------------------------------------------- /docs/poster/figures/PI_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/PI_Logo.png -------------------------------------------------------------------------------- /docs/poster/figures/QCViewerGUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/QCViewerGUI.png -------------------------------------------------------------------------------- /docs/poster/figures/QuantumWorks_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/QuantumWorks_Logo.png -------------------------------------------------------------------------------- /docs/poster/figures/Waterloo_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/Waterloo_Logo.png -------------------------------------------------------------------------------- /docs/poster/figures/iarpa_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/iarpa_logo.png -------------------------------------------------------------------------------- /docs/poster/figures/simulate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/simulate.png -------------------------------------------------------------------------------- /docs/poster/figures/state.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/state.png -------------------------------------------------------------------------------- /docs/poster/figures/torque.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/poster/figures/torque.png -------------------------------------------------------------------------------- /docs/poster/grover.qc: -------------------------------------------------------------------------------- 1 | .v a b c d e Workspace 2 | .i a b c d e Workspace 3 | .o a b c d e 4 | BEGIN H5(a b c d e) 5 | H a 6 | H b 7 | H c 8 | H d 9 | H e 10 | END H5 11 | 12 | BEGIN GroverIterate (a b c d e Workspace) 13 | H Workspace 14 | T5 a' b' c d e' Workspace 15 | H Workspace 16 | H5 a b c d e 17 | X e 18 | Z a' b' c' d' e 19 | X e 20 | H5 a b c d e 21 | END GroverIterate 22 | 23 | BEGIN 24 | H5 a b c d e 25 | GroverIterate^4 a b c d e Workspace 26 | END 27 | -------------------------------------------------------------------------------- /docs/poster/tangocolors.sty: -------------------------------------------------------------------------------- 1 | % Defines the tango palette for use with LaTeX. 2 | % 3 | % Copyright 2006 by Patrick Pletscher 4 | % 5 | % This program can be redistributed and/or modified under the terms 6 | % of the GNU Public License, version 2. 7 | 8 | % butter (yellowish) 9 | \definecolor{tabutter}{rgb}{0.98824, 0.91373, 0.30980} % #fce94f 10 | \definecolor{ta2butter}{rgb}{0.92941, 0.83137, 0} % #edd400 11 | \definecolor{ta3butter}{rgb}{0.76863, 0.62745, 0} % #c4a000 12 | 13 | % orange 14 | \definecolor{taorange}{rgb}{0.98824, 0.68627, 0.24314} % #fcaf3e 15 | \definecolor{ta2orange}{rgb}{0.96078, 0.47451, 0} % #f57900 16 | \definecolor{ta3orange}{rgb}{0.80784, 0.36078, 0} % #ce5c00 17 | 18 | % chocolate (brownish) 19 | \definecolor{tachocolate}{rgb}{0.91373, 0.72549, 0.43137} % #e9b96e 20 | \definecolor{ta2chocolate}{rgb}{0.75686, 0.49020, 0.066667} % #c17d11 21 | \definecolor{ta3chocolate}{rgb}{0.56078, 0.34902, 0.0078431} % #8f5902 22 | 23 | % chameleon (greenish) 24 | \definecolor{tachameleon}{rgb}{0.54118, 0.88627, 0.20392} % #8ae234 25 | \definecolor{ta2chameleon}{rgb}{0.45098, 0.82353, 0.086275} % #73d216 26 | \definecolor{ta3chameleon}{rgb}{0.30588, 0.60392, 0.023529} % #4e9a06 27 | 28 | % sky blue 29 | \definecolor{taskyblue}{rgb}{0.44706, 0.56078, 0.81176} % #728fcf 30 | \definecolor{ta2skyblue}{rgb}{0.20392, 0.39608, 0.64314} % #3465a4 31 | \definecolor{ta3skyblue}{rgb}{0.12549, 0.29020, 0.52941} % #204a87 32 | 33 | % plum (violettish) 34 | \definecolor{taplum}{rgb}{0.67843, 0.49804, 0.65882} % #ad7fa8 35 | \definecolor{ta2plum}{rgb}{0.45882, 0.31373, 0.48235} % #75507b 36 | \definecolor{ta3plum}{rgb}{0.36078, 0.20784, 0.4} % #5c3566 37 | 38 | % scarlet red 39 | \definecolor{tascarletred}{rgb}{0.93725, 0.16078, 0.16078} % #ef2929 40 | \definecolor{ta2scarletred}{rgb}{0.8, 0, 0} % #cc0000 41 | \definecolor{ta3scarletred}{rgb}{0.64314, 0, 0} % #a40000 42 | 43 | % aluminium 44 | \definecolor{taaluminium}{rgb}{0.93333, 0.93333, 0.92549} % #eeeeec 45 | \definecolor{ta2aluminium}{rgb}{0.82745, 0.84314, 0.81176} % #d3d7cf 46 | \definecolor{ta3aluminium}{rgb}{0.72941, 0.74118, 0.71373} % #babdb6 47 | 48 | % gray 49 | \definecolor{tagray}{rgb}{0.53333, 0.54118, 0.52157} % #888a85 50 | \definecolor{ta2gray}{rgb}{0.33333, 0.34118, 0.32549} % #555753 51 | \definecolor{ta3gray}{rgb}{0.18039, 0.20392, 0.21176} % #2e3436 52 | -------------------------------------------------------------------------------- /docs/simulate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/simulate.png -------------------------------------------------------------------------------- /docs/slides/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | pdflatex slides.tex 3 | pdflatex slides.tex 4 | #pdflatex presentation.tex 5 | #pdflatex presentation.tex 6 | -------------------------------------------------------------------------------- /docs/slides/grover_circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/slides/grover_circuit.png -------------------------------------------------------------------------------- /docs/slides/simulate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/slides/simulate.png -------------------------------------------------------------------------------- /docs/slides/slides.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | %\usepackage{tikz} 3 | \usepackage{fancyvrb} 4 | \usepackage{mathtools} 5 | \usetheme{CambridgeUS} 6 | \title{QCViewer} 7 | \author{Alex Parent} 8 | \institute{University of Waterloo, IQC} 9 | \date{January 17th, 2012} 10 | \begin{document} 11 | 12 | \begin{frame} 13 | \titlepage 14 | \end{frame} 15 | 16 | \begin{frame}{Outline} 17 | Quantum Circuit 18 | \begin{itemize} 19 | \item Design 20 | \item Visualization 21 | \item Simulation 22 | \end{itemize} 23 | \end{frame} 24 | 25 | \begin{frame}{Visualization} 26 | Produces Diagrams and outputs publication friendly formats 27 | such as .eps .svg and .png. 28 | 29 | Example: Grover's Algorithm 30 | \begin{center} 31 | \includegraphics[scale=0.32]{grover_circuit} 32 | \end{center} 33 | \end{frame} 34 | 35 | \begin{frame}[fragile]{File Format} 36 | Simple intuitive circuit format. 37 | 38 | Example: Circuit file for Grover's Algorithm 39 | \begin{center} 40 | \begin{tiny} 41 | \begin{BVerbatim}[boxwidth=auto] 42 | .v a b c d e Workspace 43 | .i a b c d e Workspace 44 | .o a b c d e 45 | 46 | BEGIN 5H (a, b, c, d, e) 47 | H a; H b; H c; H d; H e 48 | END 5H 49 | 50 | BEGIN GroverIterate (a, b, c, d, e, Workspace) 51 | H Workspace 52 | T a' b' c d e' Workspace 53 | H Workspace 54 | 5H a b c d e 55 | X e 56 | Z a' b' c' d' e 57 | X e 58 | 5H a b c d e 59 | END GroverIterate 60 | 61 | BEGIN 62 | H5 a b c d e 63 | GroverIterate^4 a b c d e Workspace 64 | END 65 | \end{BVerbatim} 66 | \end{tiny} 67 | 68 | \end{center} 69 | 70 | \end{frame} 71 | 72 | \begin{frame}{Simulation} 73 | Graphical readout of simulation. 74 | \begin{center} 75 | \includegraphics[scale=0.11]{simulate} 76 | \end{center} 77 | \end{frame} 78 | 79 | 80 | \end{document} 81 | -------------------------------------------------------------------------------- /docs/state.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aparent/QCViewer/6202f0ee829cac59ea4e13d7c61d98aa543589d2/docs/state.png -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | project(QCViewer) 3 | 4 | find_package(PkgConfig) 5 | pkg_check_modules(GTKMM gtkmm-2.4 freetype2 poppler-glib) 6 | 7 | 8 | add_subdirectory(QCViewer) 9 | -------------------------------------------------------------------------------- /src/QCViewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_FLAGS "-Wall -pedantic -std=gnu++0x") 2 | set(CMAKE_CXX_FLAGS_DEBUG "-g -pg -Wall -Wextra -pedantic -std=gnu++0x") 3 | set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -Werror -pedantic -std=gnu++0x -s") 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | 8 | file(GLOB QCLIB_SRC_FILES "QCLib/*.cpp" "QCLib/gates/*.cpp") 9 | file(GLOB QCVIEWER_SRC_FILES "*.cpp") 10 | 11 | LIST(APPEND QCLIB_SRC_FILES 12 | diracLexer.cpp 13 | diracParser.cpp 14 | QCParser.cpp 15 | QCLexer.cpp 16 | GateParser.cpp 17 | GateLexer.cpp 18 | ) 19 | 20 | add_custom_command ( 21 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/QCParser.cpp ${CMAKE_CURRENT_BINARY_DIR}/QCParser.h 22 | COMMAND bison ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/QCParser.y 23 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/QCParser.y 24 | ) 25 | add_custom_command ( 26 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/QCLexer.cpp 27 | COMMAND flex ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/QCLexer.l 28 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/QCLexer.l 29 | ) 30 | add_custom_command ( 31 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/diracLexer.cpp 32 | COMMAND flex ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/diracLexer.l 33 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/diracLexer.l 34 | ) 35 | add_custom_command ( 36 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/diracParser.cpp ${CMAKE_CURRENT_BINARY_DIR}/diracParser.h 37 | COMMAND bison -d -v -o diracParser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/diracParser.y 38 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/diracParser.y 39 | ) 40 | add_custom_command ( 41 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/GateLexer.cpp 42 | COMMAND flex ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/gates/GateLexer.l 43 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/gates/GateLexer.l 44 | ) 45 | add_custom_command ( 46 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/GateParser.cpp ${CMAKE_CURRENT_BINARY_DIR}/GateParser.h 47 | COMMAND bison ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/gates/GateParser.y 48 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/QCLib/gates/GateParser.y 49 | ) 50 | 51 | set(MPFR_LIBS "-lmpfr") 52 | 53 | if(WIN32) 54 | set(LCMS_LIBS "-llcms2") 55 | endif(WIN32) 56 | 57 | 58 | set(Boost_USE_STATIC_LIBS ON) 59 | FIND_PACKAGE(Boost 1.52.0 REQUIRED COMPONENTS system program_options filesystem) 60 | INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR}) 61 | set(Boost_USE_STATIC_LIBS ON) 62 | 63 | FIND_PACKAGE(Poppler REQUIRED) 64 | LINK_DIRECTORIES(${Poppler_LIBRARY_DIR}) 65 | include_directories(${Poppler_INCLUDE_DIR}) 66 | 67 | include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) 68 | 69 | message(STATUS "gtkmm: ${GTKMM_LIBRARY_DIRS}") 70 | include_directories(${GTKMM_INCLUDE_DIRS}) 71 | LINK_DIRECTORIES(${GTKMM_LIBRARY_DIRS}) 72 | 73 | include_directories(${Freetype_INCLUDE_DIRS}) 74 | LINK_DIRECTORIES(${Freetype_LIBRARY_DIRS}) 75 | 76 | include_directories( ${QCViewer_SOURCE_DIR}/QCLib) 77 | 78 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") 79 | 80 | add_library(qc ${QCLIB_SRC_FILES}) 81 | add_executable (qcviewer WIN32 ${CMAKE_CURRENT_SOURCE_DIR}/qcviewer/qcviewer.cpp ${QCVIEWER_SRC_FILES} ) 82 | add_executable (qcimage ${CMAKE_CURRENT_SOURCE_DIR}/qcimage/qcimage.cpp) 83 | 84 | target_link_libraries(qcviewer qc) 85 | target_link_libraries(qcviewer ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${GTKMM_LIBRARIES} ${MPFR_LIBS} ${LCMS_LIBS}) 86 | target_link_libraries(qcimage qc) 87 | target_link_libraries(qcimage ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${GTKMM_LIBRARIES} ${MPFR_LIBS} ${LCMS_LIBS}) 88 | 89 | install(TARGETS qcviewer DESTINATION ${QCViewer_SOURCE_DIR}/../bin) 90 | install(TARGETS qcimage DESTINATION ${QCViewer_SOURCE_DIR}/../bin) 91 | 92 | -------------------------------------------------------------------------------- /src/QCViewer/GateIcon.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | QCViewer is a trademark of the of the The University of Waterloo, 20 | Institute for Quantum Computing, Quantum Circuits Group 21 | 22 | Authors: Alex Parent, Jacob Parker 23 | ---------------------------------------------------------------------*/ 24 | 25 | #ifndef GATEICON__INCLUDED 26 | #define GATEICON__INCLUDED 27 | #include 28 | #include 29 | #include "QCLib/text.h" 30 | 31 | class GateIcon : public Gtk::DrawingArea 32 | { 33 | public: 34 | enum GateType { NOT, R, SWAP, MEASURE, DEFAULT }; 35 | GateIcon (); 36 | GateIcon (std::string,std::string); 37 | GateIcon (GateType); 38 | GateType type; 39 | std::string symbol; 40 | std::string dname; 41 | virtual bool on_expose_event(GdkEventExpose* event); 42 | private: 43 | TextEngine textEngine; 44 | void drawWire (cairo_t *cr, double x1, double y1, double x2, double y2); 45 | void drawShowU (cairo_t *cr, double xc, double yc, double width, std::string name); 46 | void drawShowMeasure (cairo_t *cr, double xc, double yc, double width); 47 | void drawShowNOT (cairo_t *cr, double xc, double yc, double radius); 48 | void drawShowRotation (cairo_t *cr, double xc, double yc, double radius); 49 | void drawX (cairo_t *cr, double xc, double yc, double radius); 50 | void drawShowFred (cairo_t *cr, double width, double height); 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/.gitignore: -------------------------------------------------------------------------------- 1 | diracParser.output 2 | *.o 3 | simTest 4 | CMakeCache.txt 5 | CMakeFiles/* 6 | a.out 7 | .*swp 8 | .nfs* 9 | *.png 10 | testCircuits/huge.tfc 11 | testParser 12 | libQC.a 13 | cmake_install.cmake 14 | diracTest 15 | Makefile 16 | QCLexer.cpp 17 | diracLexer.cpp 18 | diracParser.cpp 19 | diracParser.h 20 | QCLang/QCLLexer.cpp 21 | QCLang/QCLParser.cpp 22 | QCLang/QCLParser.h 23 | QCLang/QCLParser.output 24 | QCLang/QCLTest 25 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/QCLexer.l: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------------- 3 | QCViewer 4 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 5 | Institute for Quantum Computing, Quantum Circuits Group 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | QCViewer is a trademark of the of the The University of Waterloo, 23 | Institute for Quantum Computing, Quantum Circuits Group 24 | 25 | Authors: Alex Parent, Jacob Parker 26 | ---------------------------------------------------------------------*/ 27 | 28 | %option noyywrap 29 | %option nounput 30 | %option never-interactive 31 | %option outfile="QCLexer.cpp" 32 | %option prefix="QC_" 33 | %{ 34 | #include "QCParser.h" 35 | #include "QCLib/utility.h" 36 | #include 37 | #define SAVE_TOKEN {/*std::cout << yytext << std::endl;*/ QC_lval.string = strdup(yytext);} 38 | #define REMOVE_QUOTES_SAVE_TOKEN {std::string s = yytext; s.erase(s.begin()); s.erase(s.end()-1); QC_lval.string = strdup(s.c_str());} 39 | #define TOKEN(t) (QC_lval.token = t) 40 | #define printok(t) std::cout<. 21 | 22 | QCViewer is a trademark of the of the The University of Waterloo, 23 | Institute for Quantum Computing, Quantum Circuits Group 24 | 25 | Authors: Alex Parent, Jacob Parker 26 | ---------------------------------------------------------------------*/ 27 | 28 | #ifndef QC_PARSER_UTILS 29 | #define QC_PARSER_UTILS 30 | #include 31 | #include "circuit.h" 32 | class name_node 33 | { 34 | public: 35 | name_node(std::string n_name, name_node *n_next); 36 | name_node(std::string n_name, name_node *n_next, bool n_neg); 37 | ~name_node(); 38 | std::string name; 39 | bool neg; 40 | name_node *next; 41 | }; 42 | 43 | void add_one_bit_gates (std::shared_ptr circ, std::string qubit, std::string gateStr); 44 | void cleanup_bad_gates(std::shared_ptr c,std::vector& error_log); 45 | void add_lines (std::shared_ptr circ, name_node *names); 46 | void add_inputs (std::shared_ptr circ, name_node *names); 47 | void add_outputs (std::shared_ptr circ, name_node *names); 48 | void add_constants (std::shared_ptr circ, name_node *names); 49 | void add_outlabels (std::shared_ptr circ, name_node *names); 50 | void add_gate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp,std::vector& error_log); 51 | void add_gate (std::shared_ptr circ, std::string gateName, name_node *controls,name_node *targets, unsigned int exp, std::vector& error_log); 52 | void addRGate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp, double rot); 53 | void addFracRGate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp, int num, int denom); 54 | void link_subcircs (std::shared_ptr circ); 55 | void insert_break(std::shared_ptrcirc); 56 | //! Checks to see if lines with these names exist in the circuit 57 | bool check_names (std::shared_ptr circ, name_node *names,std::vector& error_log,std::string id); 58 | #endif 59 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/REQUEST: -------------------------------------------------------------------------------- 1 | vadym: 2 | - state preparation, measurement, classical feedback? 3 | - "temporary" qubits (long term) 4 | - gates sharing same controls (many-target CNOT) 5 | - Do above in pre-render pass (find parallel CNOT gates and pack into multi-target CNOT) 6 | 7 | ----- 8 | - Matt and Vadym have code for doing symbolic arithmetic over Z[1/sqrt(2), i]. 9 | (Consider using it). 10 | 11 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/circuitParser.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #ifndef CIRCUIT_PARSER 29 | #define CIRCUIT_PARSER 30 | #include 31 | #include "circuit.h" 32 | #include "utility.h" 33 | 34 | 35 | std::shared_ptr parseCircuit (std::string file,std::vector& error_log_r); 36 | void saveCircuit(std::shared_ptr circ, std::string filename); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/common.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | #include "common.h" 28 | 29 | 30 | using namespace std; 31 | 32 | 33 | Selection::Selection() 34 | { 35 | gate = 0; 36 | } 37 | 38 | Selection::Selection(uint32_t n) 39 | { 40 | gate = n; 41 | } 42 | 43 | Selection::Selection(uint32_t n, vector s) 44 | { 45 | gate = n; 46 | sub = s; 47 | } 48 | 49 | gateRect::gateRect() : x0(0),y0(0),width(0),height(0) {} 50 | 51 | gateRect& gateRect::operator+= (const gateRect& rhs) 52 | { 53 | gateRect ans; 54 | ans.x0 = min(x0, rhs.x0); 55 | ans.y0 = min(y0, rhs.y0); 56 | ans.width = max (x0-ans.x0 + width, rhs.x0 - ans.x0 + rhs.width); 57 | ans.height = max (y0-ans.y0 + height, rhs.y0 - ans.y0 + rhs.height); 58 | *this = ans; 59 | return *this; 60 | 61 | } 62 | 63 | int pickRect (const vector &rects, double x, double y, vector &selections) 64 | { 65 | for (int i = 0; i < (int)rects.size (); i++) { 66 | if (rects[i].x0 <= x && rects[i].x0+rects[i].width >= x && rects[i].y0 <= y && rects[i].y0 + rects[i].height >= y) selections.push_back(i); 67 | if (!rects[i].subRects.empty()) { 68 | pickRect (rects[i].subRects,x,y,selections); 69 | } 70 | } 71 | if (!selections.empty()) { 72 | return selections.at(0); 73 | } 74 | return -1; 75 | } 76 | 77 | vector pickRects (const vector &rects, const gateRect &s) 78 | { 79 | vector ans; 80 | for (uint32_t i = 0; i < (uint32_t)rects.size (); i++) { 81 | if (rects[i].x0 <= s.x0 && rects[i].x0+rects[i].width <= s.x0) continue; 82 | if (s.x0 <= rects[i].x0 && s.x0+s.width <= rects[i].x0) continue; 83 | if (rects[i].y0 <= s.y0 && rects[i].y0+rects[i].height <= s.y0) continue; 84 | if (s.y0 <= rects[i].y0 && s.y0+s.height <= rects[i].y0) continue; 85 | if (!rects[i].subRects.empty()) { 86 | vector sub; 87 | sub = pickRects (rects[i].subRects, s); 88 | ans.push_back (Selection(i,sub)); 89 | } else { 90 | ans.push_back (Selection(i)); 91 | } 92 | } 93 | return ans; 94 | } 95 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/common.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | /*! \file common.h 28 | \brief Defines some classes used by many parts of the code 29 | */ 30 | 31 | #ifndef __COMMON__INCLUDED 32 | #define __COMMON__INCLUDED 33 | 34 | #ifndef NULL 35 | #define NULL 0 36 | #endif 37 | 38 | #include 39 | #include 40 | 41 | class Selection 42 | { 43 | public: 44 | Selection(); 45 | Selection(uint32_t n); 46 | Selection(uint32_t n, std::vector s); 47 | uint32_t gate; 48 | std::vector sub; 49 | }; 50 | 51 | /*! \brief Rectangle that defines the area taken up by a gate 52 | 53 | Can also contain subrectangles in the case where the gate is 54 | a subcircuit 55 | */ 56 | class gateRect 57 | { 58 | public: 59 | gateRect(); 60 | //! The x position of the rectangle 61 | double x0; 62 | //! The y position of the rectangle 63 | double y0; 64 | //! The width of the rectangle 65 | double width; 66 | //! The height of the rectangle 67 | double height; 68 | //! Contains subrectangles in the case of an expanded subcircuit 69 | std::vector subRects; 70 | //! Combines 2 rectangles into a minimum bounding box which contains both 71 | gateRect& operator+= (const gateRect&); 72 | }; 73 | 74 | int pickRect (const std::vector &rects, double x, double y, std::vector &selections); 75 | std::vector pickRects (const std::vector &rects, const gateRect &s); 76 | 77 | class LayoutColumn 78 | { 79 | public: 80 | LayoutColumn (uint32_t g) : lastGateID(g) {} 81 | uint32_t lastGateID; 82 | }; 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/dirac.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #ifndef DIRAC_INCLUDE 29 | #define DIRAC_INCLUDE 30 | 31 | #include 32 | #include "state.h" 33 | 34 | State *getStateVec (std::string,bool=false); 35 | #endif 36 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/diracLexer.l: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | %option noyywrap 29 | %option nounput 30 | %option never-interactive 31 | %option unistd 32 | %option outfile="diracLexer.cpp" 33 | %{ 34 | #include "QCLib/parseNode.h" 35 | #include 36 | #include 37 | #include "QCLib/utility.h" 38 | #define YYSTYPE parseNode* 39 | #include "diracParser.h" 40 | using namespace std; 41 | stringstream temp; 42 | parseNode *setupNode(int type, string value); 43 | %} 44 | 45 | %x ket 46 | %x ketmult 47 | 48 | %% 49 | "sqrt" yylval = new parseNode(SQRT,"SQRT"); return SQRT; 50 | "+" yylval = new parseNode(PLUS,"+"); return PLUS; 51 | "-" yylval = new parseNode(MINUS,"-"); return MINUS; 52 | "*" yylval = new parseNode(TIMES,"*"); return TIMES; 53 | "/" yylval = new parseNode(DIV,"/"); return DIV; 54 | "^" yylval = new parseNode(EXPON,"^"); return EXPON; 55 | "i" yylval = new parseNode(CNUM,"1"); return CNUM; 56 | [0-9]+ yylval = new parseNode(NUM,string(yytext)); return NUM; 57 | [0-9]+\.[0-9] yylval = new parseNode(NUM,string(yytext)); return NUM; 58 | "|" BEGIN(ket); 59 | 60 | [0-1]+ yylval = new parseNode(KET,string(yytext)); return KET; 61 | \> BEGIN(INITIAL); 62 | 63 | <*>[ \t\n]+ /* eat whitespace */ 64 | . return(yytext[0]); 65 | 66 | 67 | %% 68 | 69 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/diracParser.y: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | %{ 29 | #include 30 | #include 31 | #include 32 | #include "QCLib/parseNode.h" 33 | #define YYSTYPE parseNode* 34 | using namespace std; 35 | string printTree(parseNode *node); 36 | void yyerror(const char *s); 37 | int yylex(); 38 | int yy_scan_string(const char*); 39 | parseNode *final; 40 | %} 41 | %debug 42 | %error-verbose 43 | %verbose 44 | %expect 4 45 | %defines "diracParser.h" 46 | %start input 47 | %token CNUM NUM KET PLUS MINUS TIMES DIV SQRT /* CNUM is for complex numbers */ 48 | %left low 49 | %left MINUS PLUS 50 | %left TIMES 51 | %left DIV 52 | %left SQRT 53 | %left EXPON 54 | 55 | %% 56 | input: /*empty*/ 57 | | exp { final = $1; } 58 | | error { if ($1!=NULL) delete $1; final = NULL; } 59 | ; 60 | exp: subex { $$ = $1; } 61 | | exp PLUS exp { $2->left = $1; $2->right=$3; $$ = $2; } 62 | | exp MINUS exp { $2->left = $1; $2->right=$3; $$ = $2; } 63 | | exp TIMES exp { $2->left = $1; $2->right=$3; $$ = $2; } 64 | ; 65 | subex: term 66 | | subex subex %prec low { parseNode * val = new parseNode(TIMES,"*"); 67 | val->left = $1; val->right=$2; 68 | $$ = val; } 69 | | subex DIV NUM { $2->left = $1; $2->right=$3; $$ = $2; } 70 | | subex EXPON NUM { $2->left = $1; $2->right=$3; $$ = $2; } 71 | | subex DIV '(' exp ')' { $2->left = $1; $2->right=$4; $$ = $2; } 72 | | subex DIV SQRT '(' exp ')' { $2->left = $1; $2->right=$3; $3->right = $5; $$ = $2; } 73 | | SQRT '(' exp ')' { $1->right = $3; $$ = $1; } 74 | | '(' exp ')' { $$ = $2; } 75 | ; 76 | 77 | term: KET { $$ = $1; } 78 | |NUM { $$ = $1; } 79 | |CNUM { $$ = $1; } 80 | ; 81 | %% 82 | 83 | parseNode *parseDirac(string input){ 84 | char *in = (char*)malloc(input.length() + 1); 85 | strcpy(in,input.c_str()); 86 | yy_scan_string(in); 87 | final = NULL; 88 | yyparse(); 89 | return final; 90 | } 91 | 92 | void yyerror (const char *s){ /* Called by yyparse on error */ 93 | printf ("%s\n", s); 94 | } 95 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/gate.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #include "gate.h" 29 | #include "utility.h" 30 | 31 | #include 32 | 33 | using namespace std; 34 | 35 | Control::Control(int setWire, bool setPol) : wire(setWire), polarity (setPol) {} 36 | 37 | Gate::Gate() 38 | { 39 | breakpoint = false; 40 | colbreak = false; 41 | ctrls = false; 42 | loop_count = 0; 43 | drawType = DEFAULT; 44 | } 45 | 46 | Gate::~Gate() {} 47 | 48 | void Gate::setLoopCount(unsigned int loops) 49 | { 50 | loop_count = loops; 51 | } 52 | 53 | unsigned int Gate::getLoopCount() const 54 | { 55 | return loop_count; 56 | } 57 | 58 | unsigned int Gate::getNumGates() const 59 | { 60 | return 1; 61 | } 62 | 63 | void minmaxWire (const vector &ctrl, const vector &targ, unsigned int &minw, unsigned int &maxw) 64 | { 65 | if (!targ.empty()) { 66 | maxw = minw = targ.at(0); 67 | } else if (!ctrl.empty()) { 68 | maxw = minw = ctrl.at(0).wire; 69 | } else { 70 | maxw = minw = 0; 71 | } 72 | for (unsigned int i = 0; i < targ.size (); i++) { 73 | minw = min (minw, targ[i]); 74 | maxw = max (maxw, targ[i]); 75 | } 76 | for (unsigned int i = 0; i < ctrl.size (); i++) { 77 | minw = min (minw, ctrl[i].wire); 78 | maxw = max (maxw, ctrl[i].wire); 79 | } 80 | } 81 | 82 | gateMatrix::~gateMatrix() 83 | { 84 | } 85 | 86 | gateMatrix::gateMatrix(int n_dim) 87 | { 88 | data = NULL; 89 | dim = n_dim; 90 | } 91 | 92 | gateMatrix::gateMatrix() 93 | { 94 | data = NULL; 95 | dim = 0; 96 | } 97 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/gates/GateLexer.l: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | %option noyywrap 28 | %option nounput 29 | %option never-interactive 30 | %option outfile="GateLexer.cpp" 31 | %option prefix="Gate_" 32 | %{ 33 | #include "GateParser.h" 34 | #include 35 | #include 36 | #define SAVE_TOKEN Gate_lval.string = strdup(yytext); 37 | #define TOKEN(t) (Gate_lval.token = t) 38 | %} 39 | 40 | quote [^\"\n]* 41 | word [[:alnum:]]+\*? 42 | digit [0-9] 43 | int {digit}+ 44 | float {int}\.{int} 45 | num {float}|{int} 46 | whitespace [ \t] 47 | comment #.* 48 | 49 | %x TEXT 50 | %x QUOTE 51 | %% 52 | 53 | 54 | "^" return TOKEN(EXPONENT); 55 | "+" return TOKEN(PLUS); 56 | "-" return TOKEN(MINUS); 57 | "*" return TOKEN(TIMES); 58 | "/" return TOKEN(DIV); 59 | "i" return TOKEN(IMAG); 60 | "(" return TOKEN(LPAREN); 61 | ")" return TOKEN(RPAREN); 62 | "," return TOKEN(COMMA); 63 | "\n" return TOKEN(NEWLINE); 64 | "NAME" BEGIN(TEXT); return TOKEN(NAME); 65 | "DRAWNAME" BEGIN(TEXT); return TOKEN(DRAWNAME); 66 | "LATEXNAME" BEGIN(TEXT); return TOKEN(LATEXNAME); 67 | "SYMBOL" BEGIN(TEXT); return TOKEN(SYMBOL); 68 | "COST" return TOKEN(COST); 69 | {word} BEGIN(INITIAL); SAVE_TOKEN; return WORD; 70 | \" BEGIN(QUOTE); 71 | {quote} SAVE_TOKEN; return WORD; 72 | \" BEGIN(INITIAL); 73 | "sqrt" return TOKEN(SQRT); 74 | {num} SAVE_TOKEN; return NUM; 75 | 76 | 77 | <*>{whitespace} 78 | <*>{comment} 79 | %% 80 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/gates/GateParser.y: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | %{ 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "QCLib/gates/GateParserUtils.h" 33 | void Gate_error(const char *s); 34 | int Gate_lex (); 35 | int Gate__scan_string(const char*); 36 | gate_node *gate_final; 37 | using namespace std; 38 | %} 39 | 40 | %code requires{ 41 | #include "QCLib/gates/GateParserUtils.h" 42 | } 43 | %union { 44 | std::complex *val; 45 | char *string; 46 | row_terms *terms; 47 | matrix_row *rows; 48 | gate_node *gates; 49 | int token; 50 | } 51 | 52 | %name-prefix "Gate_" 53 | %error-verbose 54 | %verbose 55 | %defines "GateParser.h" 56 | %output "GateParser.cpp" 57 | 58 | %token NAME DRAWNAME LATEXNAME WORD NUM COMMA NEWLINE LPAREN RPAREN 59 | %token SYMBOL COST 60 | 61 | %left MINUS PLUS 62 | %left TIMES DIV 63 | %right SQRT EXPONENT 64 | %left IMAG 65 | 66 | %type exp 67 | %type WORD NUM 68 | %type input gate 69 | %type matrix 70 | %type row 71 | 72 | %% 73 | input: /* empty */ {$$ = NULL;} 74 | | input NEWLINE {$$ = $1; gate_final = $1;} 75 | | input gate {$2->next = $1; $$ = $2; gate_final = $2;} 76 | ; 77 | 78 | gate: NAME WORD NEWLINE SYMBOL WORD NEWLINE matrix {$$ = new gate_node($2, $5, $7);} 79 | | NAME WORD NEWLINE DRAWNAME WORD NEWLINE SYMBOL WORD NEWLINE matrix {$$ = new gate_node($2, $5, $8, $10);} 80 | | NAME WORD NEWLINE DRAWNAME WORD NEWLINE LATEXNAME WORD NEWLINE SYMBOL WORD NEWLINE matrix {$$ = new gate_node($2, $5, $8, $11,$13);} 81 | ; 82 | 83 | matrix: row NEWLINE matrix {$$ = new matrix_row($1,$3);} 84 | | NEWLINE {$$ = NULL;} 85 | ; 86 | 87 | row: exp {$$ = new row_terms($1);} 88 | | exp COMMA row {$$ = new row_terms($1,$3);} 89 | ; 90 | exp: NUM { $$ = new complex(atof($1),0);} 91 | | IMAG { $$ = new complex(0,1);} 92 | | exp MINUS exp { $$ = new complex(*$1 - *$3); delete $1; delete $3;} 93 | | exp PLUS exp { $$ = new complex(*$1 + *$3); delete $1; delete $3;} 94 | | exp TIMES exp { $$ = new complex(*$1 * *$3); delete $1; delete $3;} 95 | | exp DIV exp { $$ = new complex(*$1 / *$3); delete $1; delete $3;} 96 | | exp EXPONENT exp { $$ = new complex(pow(*$1,*$3)); delete $1; delete $3;} 97 | | SQRT exp { *$2 = sqrt(*$2); $$ = $2; } 98 | | exp IMAG { $$ = new complex(-imag(*$1),real(*$1)); delete $1;} 99 | | MINUS exp { *$2 = -*$2; $$ = $2;} 100 | | LPAREN exp RPAREN { $$ = $2;} 101 | ; 102 | %% 103 | 104 | void Gate_error (const char *s){ /* Called by yyparse on error */ 105 | printf ("%s\n", s); 106 | } 107 | 108 | gate_node *parse_gates(string input){ 109 | char *in = (char*)malloc(input.length() + 1); 110 | strcpy(in,input.c_str()); 111 | Gate__scan_string(in); 112 | free(in); 113 | Gate_parse (); 114 | return gate_final; 115 | } 116 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/gates/GateParserUtils.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef GATE_PARSE_UTILS 28 | #define GATE_PARSE_UTILS 29 | #include 30 | #include 31 | struct row_terms { 32 | std::complex *val; 33 | row_terms *next; 34 | row_terms(std::complex *n_val, row_terms *n_next) 35 | { 36 | next = n_next; 37 | val = n_val; 38 | } 39 | row_terms(std::complex *n_val) 40 | { 41 | next = NULL; 42 | val = n_val; 43 | } 44 | ~row_terms() 45 | { 46 | if (next!= NULL) delete next; 47 | if (val != NULL) delete val; 48 | } 49 | }; 50 | 51 | struct matrix_row { 52 | row_terms *terms; 53 | matrix_row *next; 54 | matrix_row(matrix_row *n_next) 55 | { 56 | next = n_next; 57 | terms = NULL; 58 | } 59 | matrix_row(row_terms *n_val, matrix_row *n_next) 60 | { 61 | next = n_next; 62 | terms = n_val; 63 | } 64 | ~matrix_row() 65 | { 66 | if (next!= NULL) delete next; 67 | if (terms != NULL) delete terms; 68 | } 69 | }; 70 | 71 | struct gate_node { 72 | gate_node* next; 73 | std::string name; 74 | std::string drawName; 75 | std::string latexName; 76 | std::string symbol; 77 | matrix_row *row; 78 | gate_node(char* n_name, char* n_dname, char* n_latex_name, char* n_symbol, matrix_row *n_row ) 79 | : name(n_name), drawName(n_dname), latexName(n_latex_name), symbol(n_symbol) 80 | { 81 | next = NULL; 82 | row = n_row; 83 | } 84 | gate_node(char* n_name, char* n_symbol, matrix_row *n_row ) 85 | : name(n_name), drawName(n_symbol), latexName(n_symbol), symbol(n_symbol) 86 | { 87 | next = NULL; 88 | row = n_row; 89 | } 90 | gate_node(char* n_name, char* n_dname, char* n_symbol, matrix_row *n_row ) 91 | : name(n_name), drawName(n_dname), latexName(n_symbol), symbol(n_symbol) 92 | { 93 | next = NULL; 94 | row = n_row; 95 | } 96 | ~gate_node() 97 | { 98 | if (next!= NULL) delete next; 99 | if (row != NULL) delete row; 100 | } 101 | }; 102 | #endif 103 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/gates/UGateLookup.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #ifndef UGATE_LOOKUP_INC 29 | #define UGATE_LOOKUP_INC 30 | 31 | #include 32 | #include 33 | #include "../gate.h" //for gateMatrix 34 | #include "GateParserUtils.h" 35 | 36 | gate_node *parse_gates(std::string input); 37 | //Function for looking up the matrix of a given ugate Will return null if no matrix is found 38 | gateMatrix UGateLookup(std::string name); 39 | std::vector UGateNames(); 40 | std::vector UGateDNames(); 41 | 42 | //adds a matrix and name 43 | void UGateLoad(std::string name, gateMatrix mat); 44 | 45 | void UGateSetup(); 46 | #endif 47 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/hprhelpers.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Vadym Kliuchnikov sqct(dot)software(at)gmail(dot)com, Dmitri Maslov, Michele Mosca 2 | // 3 | // This file is part of SQCT. 4 | // 5 | // SQCT is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // SQCT is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with SQCT. If not, see . 17 | // 18 | 19 | #define MPFR_REAL_DATA_PUBLIC 20 | #include "hprhelpers.h" 21 | 22 | void hprHelpers::convert(const hprHelpers::hpr_complex &in, std::complex &out) 23 | { 24 | out = std::complex( mpfr_get_d( in.real()._x , MPFR_RNDN) , mpfr_get_d( in.imag()._x , MPFR_RNDN) ); 25 | } 26 | 27 | void hprHelpers::convert(const hprHelpers::hpr_real &from, double &to) 28 | { 29 | to = mpfr_get_d( from._x , MPFR_RNDN); 30 | } 31 | 32 | double hprHelpers::toMachine(const hprHelpers::hpr_real &from) 33 | { 34 | return mpfr_get_d( from._x , MPFR_RNDN); 35 | } 36 | 37 | std::complex hprHelpers::toMachine(const hprHelpers::hpr_complex &in) 38 | { 39 | return std::complex( mpfr_get_d( in.real()._x , MPFR_RNDN) , mpfr_get_d( in.imag()._x , MPFR_RNDN) ); 40 | } 41 | 42 | /// \brief Holds string for Pi computed with high precision 43 | struct piData { 44 | hprHelpers::hpr_real pi;///< Pi 45 | piData() 46 | { 47 | pi = std::string( "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798" 48 | "2148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786" 49 | "78316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882" 50 | "04665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733" 51 | "62440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637" 52 | "1787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317" 53 | "328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083" 54 | "8142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642" 55 | "0198938095257201065485863279" ); 56 | } 57 | }; 58 | 59 | const hprHelpers::hpr_real &hprHelpers::pi() 60 | { 61 | static piData d; 62 | return d.pi; 63 | } 64 | 65 | const hprHelpers::hpr_real &hprHelpers::one() 66 | { 67 | static hpr_real m_one(1.0); 68 | return m_one; 69 | } 70 | 71 | const hprHelpers::hpr_real &hprHelpers::two() 72 | { 73 | static hpr_real m_two(2.0); 74 | return m_two; 75 | } 76 | 77 | const hprHelpers::hpr_real &hprHelpers::half() 78 | { 79 | static hpr_real m_half( one() / two() ); 80 | return m_half; 81 | } 82 | 83 | const hprHelpers::hpr_real &hprHelpers::mhalf() 84 | { 85 | static hpr_real m_mhalf( - one() / two() ); 86 | return m_mhalf; 87 | } 88 | 89 | const hprHelpers::hpr_real &hprHelpers::sqrt2ov2() 90 | { 91 | static hpr_real m_s( sqrt(two()) / two() ); 92 | return m_s; 93 | } 94 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/hprhelpers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Vadym Kliuchnikov sqct(dot)software(at)gmail(dot)com, Dmitri Maslov, Michele Mosca 2 | // 3 | // This file is part of SQCT. 4 | // 5 | // SQCT is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // SQCT is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU Lesser General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with SQCT. If not, see . 17 | // 18 | 19 | #ifndef HPRHELPERS_H 20 | #define HPRHELPERS_H 21 | 22 | #include "real.hpp" 23 | #include 24 | 25 | /// \brief Helper functions and data for high precision arithmetic 26 | class hprHelpers 27 | { 28 | public: 29 | /// \brief High precision real type used in the project 30 | typedef mpfr::real<4096> hpr_real; 31 | /// \brief High precision complex type used in the project 32 | typedef std::complex hpr_complex; 33 | /// \brief Transforms high precision complex number into machine complex 34 | static void convert( const hpr_complex& from, std::complex& to ); 35 | /// \brief Transforms high precision real number into double 36 | static void convert( const hpr_real& from, double& to ); 37 | /// \brief Transforms high precision real number into double 38 | static double toMachine( const hpr_real& from ); 39 | /// \brief Transforms high precision complex number into machine complex 40 | static std::complex toMachine( const hpr_complex& from ); 41 | 42 | /// \brief High precision \f$ \pi \f$ 43 | static const hpr_real& pi(); 44 | /// \brief High precision one 45 | static const hpr_real& one(); 46 | /// \brief High precision one 47 | static const hpr_real& two(); 48 | /// \brief High precision 1/2 49 | static const hpr_real& half(); 50 | /// \brief High precision -1/2 51 | static const hpr_real& mhalf(); 52 | /// \brief High precision \f$ \frac{\sqrt{2}}{2} \f$ 53 | static const hpr_real& sqrt2ov2(); 54 | }; 55 | 56 | #endif // HPRHELPERS_H 57 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/mat_tests.cpp: -------------------------------------------------------------------------------- 1 | #include "mat.h" 2 | #include 3 | 4 | void test_mat() 5 | { 6 | Matrix u(4,5,0.f); 7 | u.set(2,3,11.f); 8 | u.set(0,0,12.f); 9 | u.set(1,0,13.f); 10 | u.set(0,1,14.f); 11 | 12 | Matrix v(4,5,0.f); 13 | v.set(2,2,15.f); 14 | v.set(2,3,-12.f); 15 | v.set(0,0,-11.f); 16 | 17 | Matrix w = u.transpose(); 18 | Matrix uu = 2.f * u * 2.f; 19 | uu *= 1.f/2.f; 20 | 21 | std::cout << u.toString() << "\n" << v.toString() << "\n" << (u += v).toString() 22 | << "\n\n" << (w * v).toString() << "\n" << (v * w).toString() << "\n"; 23 | 24 | std::cout << Matrix(uu).vappend(v).toString() << "\n" << Matrix(uu).happend(v).toString(); 25 | 26 | std::cout << u.toString() << "\n" << v.toString() << "\n" << (u % v).toString() << "\n" << (v % u).toString(); 27 | } 28 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/normalize.h: -------------------------------------------------------------------------------- 1 | #ifndef _NORMALIZE_H_ 2 | #define _NORMALIZE_H_ 3 | #include "circuit.h" 4 | #include "gate.h" 5 | #include "types.h" 6 | #include "subcircuit.h" 7 | #include 8 | #include 9 | #include 10 | 11 | class CircuitNormalizer 12 | { 13 | public: 14 | static std::shared_ptr normalize(std::shared_ptr c, bool useCNOT = false); 15 | 16 | private: 17 | using u32 = uint32_t; 18 | using swaplist = std::vector>; 19 | static void subcirc_flatten(std::shared_ptr sub, std::shared_ptr accum); 20 | static std::shared_ptr circ_flatten(std::shared_ptr in); 21 | static swaplist remove_id_swaps(const swaplist & swaps); 22 | static swaplist unit_swaps(const swaplist & swaps); 23 | static void swaps_to_circ(std::shared_ptr c, swaplist & swaps, bool useCNOT); 24 | static void nots_to_circ(std::shared_ptr c, std::vector nots); 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/parseNode.h: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------------- 3 | QCViewer 4 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 5 | Institute for Quantum Computing, Quantum Circuits Group 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | QCViewer is a trademark of the of the The University of Waterloo, 23 | Institute for Quantum Computing, Quantum Circuits Group 24 | 25 | Authors: Alex Parent, Jacob Parker 26 | ---------------------------------------------------------------------*/ 27 | 28 | #ifndef PARSE_NODE 29 | #define PARSE_NODE 30 | 31 | #include 32 | 33 | struct parseNode { 34 | parseNode(int n_type, std::string n_value) : value(n_value) 35 | { 36 | left = NULL; 37 | right = NULL; 38 | type = n_type; 39 | } 40 | ~parseNode() 41 | { 42 | if (left) delete left; 43 | if (right) delete right; 44 | } 45 | int type; 46 | std::string value; 47 | parseNode * left; 48 | parseNode * right; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/pdf.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "pdf.h" 6 | 7 | #define LATEX_SCALEF 2.5 8 | 9 | PDFReader::PDFReader(const char * filename) 10 | { 11 | GError* error = NULL; 12 | gchar* absolute; 13 | gchar* uri; 14 | if(g_path_is_absolute(filename)) { 15 | absolute = g_strdup(filename); 16 | } else { 17 | gchar* dir = g_get_current_dir(); 18 | absolute = g_build_filename(dir, filename, (gchar*)0); 19 | free(dir); 20 | } 21 | 22 | uri = g_filename_to_uri(absolute, NULL, &error); 23 | free(absolute); 24 | if(uri == NULL) { 25 | throw std::string("PDFReader: Couldn't convert PDF filename to URI."); 26 | } 27 | 28 | document = poppler_document_new_from_file(uri, NULL, &error); 29 | 30 | if(document == NULL) { 31 | throw std::string("PDFReader: Couldn't open PDF document."); 32 | } 33 | 34 | int num_pages = poppler_document_get_n_pages(document); 35 | pages.reserve(num_pages); 36 | 37 | for(int i=0; i(new PopplerContainer(page))); 43 | } 44 | } 45 | 46 | PDFReader::~PDFReader() 47 | { 48 | g_object_unref(document); 49 | } 50 | 51 | uint32_t PDFReader::getNumPages() 52 | { 53 | return pages.size(); 54 | } 55 | 56 | std::shared_ptr 57 | PDFReader::getPage(int n) 58 | { 59 | std::shared_ptr page = pages.at(n); 60 | if(!page) { 61 | throw std::string("PDFReader: Requested a nonexistent page."); 62 | } 63 | return page; 64 | } 65 | 66 | PopplerContainer::~PopplerContainer() 67 | { 68 | g_object_unref(page); 69 | } 70 | 71 | void PopplerContainer::getPageDimensions(double &width, double &height) 72 | { 73 | poppler_page_get_size(page, &width, &height); 74 | width *= LATEX_SCALEF; 75 | height *= LATEX_SCALEF; 76 | } 77 | 78 | void PopplerContainer::draw(cairo_t* cr) 79 | { 80 | assert(page != NULL); 81 | assert(cr != NULL); 82 | cairo_scale(cr, LATEX_SCALEF, LATEX_SCALEF); 83 | poppler_page_render(page, cr); 84 | cairo_scale(cr, 1.0/LATEX_SCALEF, 1.0/LATEX_SCALEF); 85 | } 86 | 87 | PopplerContainer::PopplerContainer(PopplerPage * pg) 88 | { 89 | page = pg; 90 | } 91 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/pdf.h: -------------------------------------------------------------------------------- 1 | #ifndef _PDF_INCLUDED_ 2 | #define _PDF_INCLUDED_ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class PDFReader; 10 | 11 | class PopplerContainer 12 | { 13 | public: 14 | ~PopplerContainer(); 15 | void getPageDimensions(double&, double&); 16 | void draw(cairo_t* cr); 17 | 18 | private: 19 | PopplerContainer(PopplerPage * pg); 20 | PopplerPage* page; 21 | friend class PDFReader; 22 | }; 23 | 24 | class PDFReader 25 | { 26 | public: 27 | PDFReader(const char*); 28 | ~PDFReader(); 29 | uint32_t getNumPages(); 30 | std::shared_ptr getPage(int); 31 | 32 | private: 33 | std::vector > pages; 34 | PopplerDocument* document; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/simulate.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------------- 3 | QCViewer 4 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 5 | Institute for Quantum Computing, Quantum Circuits Group 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | QCViewer is a trademark of the of the The University of Waterloo, 23 | Institute for Quantum Computing, Quantum Circuits Group 24 | 25 | Authors: Alex Parent, Jacob Parker 26 | ---------------------------------------------------------------------*/ 27 | #include "circuit.h" 28 | #include "simulate.h" 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "utility.h" 34 | #include "gates/UGateLookup.h" 35 | #include "circuit.h" 36 | #include "subcircuit.h" 37 | 38 | using namespace std; 39 | 40 | gateMatrix getGateMatrix(Gate*);//defined below 41 | 42 | /* 43 | This function takes an input quantum state and a gate. 44 | It splits the input superposition into basis states (in the computational basis, 45 | i.e. into class bit strings.) It runs the gate on each of these, and collates 46 | the answers (weighed appropriately) into the answer. 47 | NULL on error (couldn't find a unitary.). 48 | The application of the gate is left up to the gate class. This allows per gate class 49 | optimization if nessicary. (For a good example of how this works see gates/UGate.cpp 50 | */ 51 | State ApplyGate (const State &in, const std::shared_ptr &g) 52 | { 53 | State s = in; 54 | if (g->drawType == Gate::MEASURE) { 55 | assert(g->targets.size() > 0); //Gate has a target 56 | s.measure(g->targets.at(0)); 57 | return s; 58 | } else if (g->drawType == Gate::SELECTZERO) { 59 | assert(g->targets.size() > 0); //Gate has a target 60 | s.selectZero(g->targets.at(0)); 61 | return s; 62 | } else if (g->drawType == Gate::SELECTONE) { 63 | assert(g->targets.size() > 0); //Gate has a target 64 | s.selectOne(g->targets.at(0)); 65 | return s; 66 | } 67 | for (unsigned int i = 0; i < g->getLoopCount(); i++) { 68 | State out = State(s.dim); 69 | for (StateMap::const_iterator it = s.data.begin(); it != s.data.end(); ++it) { 70 | State tmp = g->applyToBasis(it->first); 71 | complex foo = (*it).second; 72 | tmp *= foo; 73 | out += tmp; 74 | } 75 | s = out; 76 | } 77 | return s; 78 | } 79 | 80 | State ApplyCircuit (const State &in, const Circuit &circ) 81 | { 82 | State s = in; 83 | for (unsigned int i = 0; i < circ.numGates(); i++) { 84 | s = ApplyGate(s,circ.getGate(i)); 85 | } 86 | return s; 87 | } 88 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/simulate.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef QC_SIM_INCL 28 | #define QC_SIM_INCL 29 | 30 | #include "gate.h" 31 | #include "circuit.h" 32 | #include "state.h" 33 | 34 | State ApplyGate (const State &in, const std::shared_ptr &g); 35 | State ApplyCircuit (const State &in, const Circuit &circ); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/state.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef STATE__INCLUDED 28 | #define STATE__INCLUDED 29 | #include 30 | #include 31 | #include 32 | #include "types.h" 33 | 34 | // If it is desired to up the accuracy later, or change the maximum 35 | // qubit size, change this. 36 | typedef std::map > StateMap; 37 | 38 | class State 39 | { 40 | public: 41 | State (); 42 | State (index_t); 43 | State (std::complex amp, index_t bits); 44 | 45 | void print(); 46 | 47 | std::complex getAmplitude (index_t bits); 48 | const State& operator+= (const State &r); 49 | const State& operator-= (const State &r); 50 | const State& operator*= (const std::complex); 51 | void normalize(); 52 | //! Simulates a measurment of a specified bit in the computational basis 53 | void measure(int bit); 54 | void selectOne(int bit); 55 | void selectZero(int bit); 56 | unsigned int numBits() const; 57 | 58 | index_t dim; 59 | StateMap data; 60 | }; 61 | 62 | State kron (const State &l,const State &r); 63 | #endif // STATE__INCLUDED 64 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/subcircuit.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef SUBCIRCUIT_H 28 | #define SUBCIRCUIT_H 29 | 30 | #include "gate.h" 31 | #include "circuit.h" 32 | #include 33 | #include 34 | 35 | //A subcircuit gate contains 36 | class Subcircuit : public Gate 37 | { 38 | public: 39 | Subcircuit(std::shared_ptr, const std::vector&,unsigned int); 40 | std::shared_ptr clone() const; 41 | std::string getName() const; 42 | std::string getDrawName(); 43 | std::string getLatexName(); 44 | void setName(std::string name); 45 | State applyToBasis(index_t) const; 46 | unsigned int getNumGates() const; 47 | State applySubcirc(const State&) const; 48 | unsigned int numGates() const; 49 | 50 | //! Steps the subcircuit through the next gate. 51 | bool step (State &s); 52 | //! Resets current gate to the beginning of the subcircuit. 53 | void reset (); 54 | 55 | 56 | std::shared_ptr getGate(int pos) const; 57 | std::shared_ptr getCircuit(); 58 | std::vector getGreedyParallel() const; //Returns a vector of ints specifying the last gate in each parallel block. 59 | 60 | //! Set true is circuit should be draw in expanded mode 61 | bool expand; 62 | //! Set true is circuit should be draw in unrolled mode 63 | bool unroll; 64 | std::shared_ptr simState; 65 | std::shared_ptr circ; 66 | 67 | 68 | protected: 69 | std::vector lineMap; 70 | private: 71 | index_t BuildBitString (index_t, unsigned int); 72 | }; 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/text.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #ifndef TEXT_H 8 | #define TEXT_H 9 | 10 | enum TextMode { 11 | TEXT_PANGO, 12 | TEXT_LATEX 13 | }; 14 | 15 | class TextObject 16 | { 17 | public: 18 | TextObject() : width(0), height(0), x(0), y(0) { }; 19 | virtual ~TextObject() {}; 20 | virtual void draw(cairo_t* cr, double x, double y) = 0; 21 | virtual bool isBatch() 22 | { 23 | return batch; 24 | } 25 | double getWidth() 26 | { 27 | return width; 28 | } 29 | double getHeight() 30 | { 31 | return height; 32 | } 33 | double getX() 34 | { 35 | return x; 36 | } 37 | double getY() 38 | { 39 | return y; 40 | } 41 | std::string contents; 42 | protected: 43 | bool batch; 44 | double width, height, x, y; 45 | }; 46 | 47 | class TextEngine 48 | { 49 | public: 50 | TextEngine(); 51 | ~TextEngine(); 52 | 53 | TextObject* renderText(std::string text); 54 | void setMode(TextMode m); 55 | TextMode getMode() 56 | { 57 | return mode; 58 | } 59 | void beginBatch(); 60 | void endBatch(); 61 | 62 | private: 63 | void latexFailure(std::string); 64 | 65 | TextMode mode; 66 | void flushCache(); 67 | std::vector cache; 68 | bool batch; 69 | std::vector batchlist; 70 | }; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/types.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef TYPES_H_INCLUDED 28 | #define TYPES_H_INCLUDED 29 | #include 30 | typedef float float_type; 31 | typedef uint64_t index_t; 32 | #endif 33 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/ucompiler.h: -------------------------------------------------------------------------------- 1 | #ifndef _UCOMPILER_H_ 2 | #define _UCOMPILER_H_ 3 | #include "circuit.h" 4 | #include "gate.h" 5 | #include "types.h" 6 | #include "subcircuit.h" 7 | #include "mat.h" 8 | #include 9 | #include 10 | #include 11 | #include "hprhelpers.h" 12 | #include "rint.h" 13 | #include 14 | 15 | /* High precision floating-point type. */ 16 | using uc_hpr_complex = hprHelpers::hpr_complex; 17 | 18 | /* Symbolic comp. type. */ 19 | using uc_ring = ring_int; 20 | 21 | /* Gate library interface, templated over field of matrix for gate representation. */ 22 | template 23 | class GateLibrary 24 | { 25 | public: 26 | GateLibrary() {}; 27 | virtual ~GateLibrary() {}; 28 | virtual Matrix getMatrixForGate(std::shared_ptr g) = 0; 29 | }; 30 | 31 | /* Floating point gate library. */ 32 | class CompGateLibrary : public GateLibrary 33 | { 34 | public: 35 | CompGateLibrary(); 36 | virtual ~CompGateLibrary(); 37 | virtual Matrix getMatrixForGate(std::shared_ptr g); 38 | }; 39 | 40 | /* Symbolic gate library. */ 41 | class SymGateLibrary : public GateLibrary 42 | { 43 | public: 44 | SymGateLibrary(); 45 | virtual ~SymGateLibrary(); 46 | virtual Matrix getMatrixForGate(std::shared_ptr g); 47 | }; 48 | 49 | /* Unitary compiler, templated over field of matrix for gate representation. */ 50 | template 51 | class UnitaryCompiler 52 | { 53 | public: 54 | UnitaryCompiler(std::shared_ptr> gl, const T & zero_, const T & one_); 55 | ~UnitaryCompiler(); 56 | Matrix getMatrixForCircuit(std::shared_ptr c); 57 | 58 | private: 59 | std::shared_ptr> lib; 60 | T zero, one; 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/unistd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mingw32 package. 3 | * 4 | * unistd.h maps (roughly) to io.h 5 | */ 6 | 7 | #ifndef __STRICT_ANSI__ 8 | 9 | #include 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/QCViewer/QCLib/utility.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | /*! \file utility.h 28 | \brief Utility functions 29 | 30 | */ 31 | 32 | #ifndef UTILITY_FUNCS 33 | #define UTILITY_FUNCS 34 | 35 | #include 36 | #include 37 | #include "types.h" 38 | 39 | #define BYTETOBINARYPATTERN "%d%d%d%d%d%d%d%d" 40 | #define BYTETOBINARY(byte) \ 41 | (byte & 0x80 ? 1 : 0), \ 42 | (byte & 0x40 ? 1 : 0), \ 43 | (byte & 0x20 ? 1 : 0), \ 44 | (byte & 0x10 ? 1 : 0), \ 45 | (byte & 0x08 ? 1 : 0), \ 46 | (byte & 0x04 ? 1 : 0), \ 47 | (byte & 0x02 ? 1 : 0), \ 48 | (byte & 0x01 ? 1 : 0) 49 | 50 | void printIntBin(index_t); 51 | 52 | /*! 53 | \brief Returns the floored form of the binary logarithm for a 32 bit integer. 54 | 55 | -1 is returned if ''n'' is 0. 56 | */ 57 | unsigned int floorLog2(unsigned int n); 58 | 59 | int ipow(int base, int exp); 60 | std::string intToString(int i); 61 | std::string floatToString(float_type i); 62 | std::string sToUpper(std::string); 63 | 64 | /* Bit set/get functions */ 65 | /*! 66 | \brief Sets the bit at position reg to 1 67 | */ 68 | unsigned int SetRegister (unsigned int bits, unsigned int reg); 69 | /*! 70 | \brief Sets the bit at position reg to 0 71 | */ 72 | unsigned int UnsetRegister (unsigned int bits, unsigned int reg); 73 | /*! 74 | \brief Returns the value of the bit at position reg 75 | */ 76 | index_t GetRegister (index_t bits, index_t reg); 77 | 78 | unsigned int invertBits (unsigned int bits, unsigned int numBits); 79 | 80 | unsigned int bitcount(unsigned int); 81 | index_t ExtractBits (index_t target, index_t bitString); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/QCViewer/TODO: -------------------------------------------------------------------------------- 1 | 2 | 1. Does not display circuits with 1000 or more lines (crashes). 3 | -Seems to run out of memory and display the circuit incorrectly. Athough it did not crash for me. 4 | -fixed another redering things that large is very slow. May need to look into preformace optimizations. 5 | 2. It crashes. Please, make sure this does not happen. You can do that via using the tool to display circuits, and do some operations with it. It was very embarrassing when QCViewer crashed during Martin's presentation to an IARPA guy. 6 | -Fixed a crash with loading circuits containing bad line names. Maybe this was it? 7 | 3. If there is a controlled-box, when you expand the box, the control is getting lost. This is an incorrect behaviour. 8 | -fixed 9 | 4. I wonder what happened with the gate drag and drop. It seems to be dropping the gate to the right of the pointer. This is very counterintiutive. 10 | -fixed somewhat 11 | 5. New distribution needs to include more examples in the Demo folder. Martin wants to see a big random circuit that is not sparce. It is easy to generate one such (it needs not make any useful computation), and add to the Demo folder to highlight the tool's ability to display large circuits. Other demo circuits need to be included, too. E.g., depth-3 Toffoli from Matt. 12 | -added some stuff 13 | 6. Parallel guides feature does not work correctly---see 3qubitECC.qc files, for example. Last two CNOTs cannot be executed in parallel. 14 | -Was not drawing the last line fixed that which fixes the problem for this example at least. 15 | 7. User's guide needs to be made available. In fact, as per my previous emails, it needed to be available *before* QCS workshop started on May 21. This is not the first time user's guide is not available by the deadline set ahead of time. We missed submission to QIP a long time ago. 16 | 8. Gate deletion is not possible within a subroutine. 17 | -fixed 18 | 19 | Here are other changes as requested by the workshop participants. They are all important, and need to be done ASAP. 20 | 1. Mac OS X version should be compiled and made available. 21 | 2. LaTeX should be supported, even if a more involved installation is required. Actually, I do not understand why html is still not working and fractions are not displayed as fractions. We discussed it more than once that fractions in the QFT need to be displayed differently, and this is still not done. 22 | 3. Gate moving by dragging would be highly desirable. The tool should not allow the move when gate cannot be commuted to a location the user wants to move the gate to. 23 | 4. Circuit stats---number of gates, number of qubits, depth, etc, need to be displayed. 24 | 5. Adding gate libraries to the circuit file and being able to browse gates much like you browse subroutines is important. There should be a slightly different interface for those, e.g., a gate that can be implemented in terms of smaller gates could have a small "+" sign on top of it, upon clicking which it is expanded. 25 | 6. More user friendly features in the interface, e.g., "Expand all" and "Contract all" buttons, in the main release, as per group web page. 26 | -done 27 | 7. Measurement needs to be added. 28 | -------------------------------------------------------------------------------- /src/QCViewer/circuitkit/QCParserUtils.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef QC_PARSER_UTILS 28 | #define QC_PARSER_UTILS 29 | #include 30 | #include "circuit.h" 31 | class name_node 32 | { 33 | public: 34 | name_node(std::string n_name, name_node *n_next); 35 | name_node(std::string n_name, name_node *n_next, bool n_neg); 36 | ~name_node(); 37 | std::string name; 38 | bool neg; 39 | name_node *next; 40 | }; 41 | 42 | void add_one_bit_gates (std::shared_ptr circ, std::string qubit, std::string gateStr); 43 | void cleanup_bad_gates(std::shared_ptr c,std::vector& error_log); 44 | void add_lines (std::shared_ptr circ, name_node *names); 45 | void add_inputs (std::shared_ptr circ, name_node *names); 46 | void add_outputs (std::shared_ptr circ, name_node *names); 47 | void add_constants (std::shared_ptr circ, name_node *names); 48 | void add_outlabels (std::shared_ptr circ, name_node *names); 49 | void add_gate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp,std::vector& error_log); 50 | void add_gate (std::shared_ptr circ, std::string gateName, name_node *controls,name_node *targets, unsigned int exp, std::vector& error_log); 51 | void addRGate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp, double rot); 52 | void addFracRGate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp, int num, int denom); 53 | void link_subcircs (std::shared_ptr circ); 54 | void insert_break(std::shared_ptrcirc); 55 | //! Checks to see if lines with these names exist in the circuit 56 | bool check_names (std::shared_ptr circ, name_node *names,std::vector& error_log,std::string id); 57 | #endif 58 | -------------------------------------------------------------------------------- /src/QCViewer/circuitkit/circuit.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #include "circuit.h" 29 | #include "subcircuit.h" 30 | #include "utility.h" 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace std; 36 | 37 | Circuit::Circuit() 38 | { 39 | root = shared_ptr(new Subcircuit()); 40 | root_attr = GateAttributes(); 41 | } 42 | 43 | Circuit::~Circuit () 44 | { } 45 | 46 | string Circuit::getName() const 47 | { 48 | return name; 49 | } 50 | 51 | void Circuit::setName(string n_name) 52 | { 53 | name = n_name; 54 | } 55 | 56 | std::shared_ptr Circuit::getRootSubcircuit() 57 | { 58 | return root; 59 | } 60 | 61 | const GateAttributes & Circuit::getRootSubcircuitAttributes() 62 | { 63 | return root_attr; 64 | } 65 | 66 | void Circuit::clear() 67 | { 68 | root = shared_ptr(new Subcircuit()); 69 | root_attr = GateAttributes(); 70 | subcircuits.clear(); 71 | } 72 | 73 | void Circuit::readQuiglFile(std::string filename) 74 | { 75 | 76 | } 77 | 78 | void Circuit::readQCFile(std::string filename) 79 | { 80 | 81 | } 82 | 83 | void Circuit::readQuiglBuffer(std::string data) 84 | { 85 | 86 | } 87 | 88 | void Circuit::readQCBuffer(std::string data) 89 | { 90 | 91 | } 92 | 93 | void Circuit::writeQuiglFile(std::string filename) const 94 | { 95 | 96 | } 97 | 98 | void Circuit::writeQCFile(std::string filename) const 99 | { 100 | 101 | } 102 | 103 | void Circuit::writeQuiglBuffer(std::string & data) const 104 | { 105 | 106 | } 107 | 108 | void Circuit::writeQCBuffer(std::string & data) const 109 | { 110 | 111 | } 112 | 113 | -------------------------------------------------------------------------------- /src/QCViewer/circuitkit/circuit.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | /*! \file circuit.h 28 | \brief Defines the circuit class and some other related classes 29 | */ 30 | 31 | #ifndef CIRCUIT 32 | #define CIRCUIT 33 | 34 | #include "gate.h" 35 | #include "types.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | /*! 42 | \brief Defines a circuit 43 | */ 44 | class Circuit 45 | { 46 | public: 47 | Circuit (); 48 | ~Circuit (); 49 | 50 | //! Returns the circuit name 51 | std::string getName() const; 52 | 53 | //! Sets the circuit name 54 | void setName(std::string); 55 | 56 | //! Get root subcircuit and attributes 57 | std::shared_ptr getRootSubcircuit(); 58 | const GateAttributes & getRootSubcircuitAttributes() const; 59 | 60 | //! Clear the circuit 61 | void clear(); 62 | 63 | //! Clear and read circuit from a Quigl file 64 | void readQuiglFile(std::string filename); 65 | 66 | //! Clear and read circuit from a .qc file 67 | void readQCFile(std::string filename); 68 | 69 | //! Clear and read circuit from a buffer containing Quigl-formatted data 70 | void readQuiglBuffer(std::string data); 71 | 72 | //! Clear and read circuit from a buffer containing .qc-formatted data 73 | void readQCBuffer(std::string data); 74 | 75 | //! Write circuit to a file as Quigl 76 | void writeQuiglFile(std::string filename) const; 77 | 78 | //! Write circuit to a file as .qc 79 | void writeQCFile(std::string filename) const; 80 | 81 | //! Write circuit to a buffer as Quigl-formatted data 82 | void writeQuiglBuffer(std::string & data) const; 83 | 84 | //! Write circuit to a buffer as .qc-formatted data 85 | void writeQCBuffer(std::string & data) const; 86 | 87 | private: 88 | std::string name; 89 | 90 | //! Root subcircuit and attributes 91 | std::shared_ptr root; 92 | GateAttributes root_attr; 93 | 94 | //! Mapping of names to circuits storing subcircuits that might appear in this circuit 95 | std::map> subcircuits; 96 | }; 97 | 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /src/QCViewer/circuitkit/circuitParser.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #ifndef CIRCUIT_PARSER 29 | #define CIRCUIT_PARSER 30 | #include 31 | #include "circuit.h" 32 | #include "utility.h" 33 | 34 | 35 | std::shared_ptr parseCircuit (std::string file,std::vector& error_log_r); 36 | void saveCircuit(std::shared_ptr circ, std::string filename); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/QCViewer/circuitkit/gate.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #include "gate.h" 29 | #include "utility.h" 30 | 31 | #include 32 | 33 | using namespace std; 34 | 35 | Control::Control(int setWire, bool setPol) : wire(setWire), polarity (setPol) {} 36 | 37 | Gate::Gate() 38 | { 39 | ctrls = false; 40 | } 41 | 42 | Gate::~Gate() {} 43 | 44 | unsigned int Gate::getNumGates() const 45 | { 46 | return 1; 47 | } 48 | 49 | gateMatrix::~gateMatrix() 50 | { 51 | } 52 | 53 | gateMatrix::gateMatrix(int n_dim) 54 | { 55 | data = NULL; 56 | dim = n_dim; 57 | } 58 | 59 | gateMatrix::gateMatrix() 60 | { 61 | data = NULL; 62 | dim = 0; 63 | } 64 | -------------------------------------------------------------------------------- /src/QCViewer/circuitkit/gate.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #ifndef GATE 29 | #define GATE 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | //used to specify a control number and polarity 36 | class Control 37 | { 38 | public: 39 | Control (int,bool); 40 | unsigned int wire; 41 | bool polarity; 42 | }; 43 | 44 | /* 45 | GATE 46 | --------------- 47 | This is the general gate class from which all gates are derived. 48 | Name is kept private since in the case of gates like the arbitray 49 | rotation gate we may want the name to be dependent on the rot amount 50 | */ 51 | 52 | class Gate 53 | { 54 | public: 55 | virtual ~Gate(); 56 | Gate(); 57 | virtual std::shared_ptr clone() const=0; 58 | virtual std::string getName() const=0; 59 | 60 | virtual unsigned int getNumGates() const; 61 | std::vector controls; 62 | std::vector targets; 63 | bool ctrls; 64 | }; 65 | 66 | struct GateAttributes { 67 | GateAttributes(); 68 | int loop_count; 69 | }; 70 | 71 | //A gate matrix struct for UGate 72 | struct gateMatrix { 73 | ~gateMatrix(); 74 | gateMatrix(int); 75 | gateMatrix(); 76 | unsigned int dim; 77 | std::complex * data; 78 | }; 79 | 80 | //A general unitary gate 81 | class UGate : public Gate 82 | { 83 | public: 84 | UGate(std::string); 85 | UGate(std::string,std::string); 86 | std::shared_ptr clone() const; 87 | std::string getName() const; 88 | void setName(std::string); 89 | private: 90 | std::string name; 91 | }; 92 | 93 | //An arbitrary rotation gate 94 | class RGate : public Gate 95 | { 96 | public: 97 | enum Axis { X, Y, Z }; 98 | RGate(float_type, Axis); 99 | RGate(Axis,int,int); 100 | std::shared_ptr clone() const; 101 | std::string getName() const; 102 | float_type get_rotVal () const; // XXX: remove float_type, consildate this stuff!! 103 | void set_rotVal (float_type); 104 | Axis get_axis () const; 105 | void set_axis (Axis); 106 | bool frac; 107 | int numer,denom; 108 | private: 109 | float_type rot; 110 | Axis axis; 111 | }; 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /src/QCViewer/circuitkit/qglcc.rkt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env racket 2 | #lang racket 3 | (require xml 4 | xml/xexpr) 5 | 6 | (define (do-statement s) 7 | (match s 8 | [(list-rest 'assignment '() 9 | (list-no-order 10 | `(variable () ,var) 11 | `(value () ,val))) 12 | (printf "Assigned ~a to ~a~n" var val)] 13 | [(list-rest 'gate '() 14 | (list-no-order 15 | `(name () ,name) 16 | (list-rest 'quantum '() targets) 17 | optionals ...)) 18 | (printf "Applied gate ~a to ~a with optionals ~a~n" 19 | name 20 | targets 21 | optionals)] 22 | [(list-rest (and type 23 | (or 'control 'controlnot)) 24 | '() 25 | (list-no-order 26 | (list-rest 'quantum '() controls) 27 | (list-rest 'block '() block))) 28 | (printf "Control ~a block over ~a containing ~a~n" 29 | type 30 | controls 31 | block)] 32 | [(list-rest 'repeat '() 33 | (list-no-order 34 | `(variable () ,counter) 35 | `(times () ,times) 36 | (list-rest 'block '() block))) 37 | (printf "Repeat [~a][~a] block ~a~n" 38 | counter 39 | times 40 | block)] 41 | [(list-rest 'parallel '() 42 | (list-no-order 43 | `(variable () ,counter) 44 | `(times () ,times) 45 | (list-rest 'block '() block))) 46 | (printf "Parallel [~a][~a] block ~a~n" 47 | counter 48 | times 49 | block)] 50 | [(list-rest 'parallel '() 51 | `(,(list-rest 'block '() blocks) ...)) 52 | (printf "Parallel blocks: ~a~n" 53 | blocks)] 54 | [(list-rest 'with '() 55 | (list-no-order 56 | (list-rest 'block '() with-block) 57 | (list-rest 'do '() do-block))) 58 | (printf "With block ~a do block ~a~n" 59 | with-block 60 | do-block)] 61 | [(list-rest 'call '() 62 | (list-no-order 63 | `(name () ,func) 64 | optionals ...)) 65 | (printf "Called ~a with optionals ~a~n" 66 | func optionals)] 67 | [(list-rest 'procedure '() 68 | (list-no-order 69 | `(name () ,name) 70 | optionals ...)) 71 | (printf "Procedure ~a declared as ~a~n" 72 | name 73 | optionals)] 74 | [else 75 | (error 'statement "Malformed statement: ~a" s)])) 76 | 77 | (define (do-circuit c) 78 | (match c 79 | [(list-rest 'circuit 80 | xmlns 81 | `((statement () ,statements) ...)) 82 | (map do-statement statements)] 83 | [else 84 | (error 'circuit "Unexpected form in circuit body.")])) 85 | 86 | (define (main) 87 | (define (sanitize xexp) 88 | (define (whitespace? xexp) 89 | (define whitespace-chars '(#\newline #\return #\tab #\space)) 90 | (and (string? xexp) 91 | (andmap (lambda(c) (memf (lambda(d) (eq? c d)) whitespace-chars)) 92 | (string->list xexp)))) 93 | (if (list? xexp) 94 | (foldr 95 | (lambda(xexp base) 96 | (cond [(whitespace? xexp) base] 97 | [else (cons (sanitize xexp) base)])) 98 | empty 99 | xexp) 100 | xexp)) 101 | (define quigl (sanitize (xml->xexpr (document-element (read-xml))))) 102 | (pretty-print quigl) 103 | (printf "~n=====================================~n") 104 | (do-circuit quigl)) 105 | 106 | (main) 107 | 108 | -------------------------------------------------------------------------------- /src/QCViewer/info.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #ifndef INFO_INCLUDED 29 | #define INFO_INCLUDED 30 | 31 | //This file contains #defines for general infomation about the program like version numbers 32 | 33 | #define QCV_NAME "QCViewer" 34 | #define QCV_VERSION "1.3" 35 | #define QCV_WEBSITE "https://github.com/aparent/QCViewer" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/QCViewer/options.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | QCViewer is a trademark of the of the The University of Waterloo, 20 | Institute for Quantum Computing, Quantum Circuits Group 21 | 22 | Authors: Alex Parent 23 | ---------------------------------------------------------------------*/ 24 | 25 | #ifndef QCV_OPTIONS_H 26 | #define QCV_OPTIONS_H 27 | 28 | #include"QCLib/circuitImage.h" 29 | class QCVOptions 30 | { 31 | public: 32 | DrawOptions draw; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/QCViewer/qcimage/qcimage.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent 25 | ---------------------------------------------------------------------*/ 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace std; 36 | 37 | extern TextEngine textEngine; 38 | 39 | int main (int argc, char *argv[]) 40 | { 41 | std::shared_ptr c; 42 | UGateSetup(); 43 | FT_Library library; 44 | FT_Face ft_face; 45 | FT_Init_FreeType( &library ); 46 | FT_New_Face( library, "data/fonts/cmbx12.ttf", 0, &ft_face ); 47 | cairo_font_face_t * ft_default = cairo_ft_font_face_create_for_ft_face (ft_face, 0); 48 | CircuitImage drawer; 49 | 50 | if (argc > 0) { 51 | vector error_log; 52 | c = parseCircuit(argv[1],error_log); 53 | if (!c) { 54 | cout << "Parse Error" << endl; 55 | return -1; 56 | } 57 | c->getGreedyParallel(); 58 | c->expandAll(); 59 | ofstream myfile; 60 | string filename = string(argv[1])+".metrics"; 61 | cout << filename << endl; 62 | myfile.open (filename.c_str()); 63 | myfile << "Gates: " << c->totalGates() << endl; 64 | myfile.close(); 65 | } else { 66 | cout << "No circuit file provided" << endl; 67 | return 0; 68 | } 69 | if (argc>4) { 70 | if(string(argv[4]).compare("-latex") == 0) { 71 | textEngine.setMode(TEXT_LATEX); 72 | } 73 | } 74 | if (argc>3) { 75 | if (string(argv[2]).compare("-svg") == 0) { 76 | drawer.savesvg (*c, argv[3],ft_default); 77 | } else if (string(argv[2]).compare("-ps") == 0) { 78 | drawer.saveps (*c, argv[3],ft_default); 79 | } else if (string(argv[2]).compare("-png") == 0) { 80 | drawer.savepng (*c, argv[3],ft_default); 81 | } 82 | } else if (argc > 2) { 83 | drawer.savepng (*c, argv[2],ft_default); 84 | } else { 85 | } 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | CFLAGS=-I. -std=c++11 -Wall -Wextra -g 3 | CIRCUITKIT_OBJS=QCParser.o QCLexer.o circuit.o subcircuit.o gate.o QCParserUtils.o \ 4 | gates/GateParser.o gates/GateLexer.o gates/RGate.o gates/UGate.o \ 5 | gates/UGateLookup.o utility.o qcqg.o 6 | 7 | all: qc2quigl 8 | 9 | %.cpp: %.l 10 | flex $^ 11 | mv `basename $@` `dirname $@` 2>/dev/null || true 12 | 13 | %.cpp: %.y 14 | bison $^ 15 | mv `basename $@` `dirname $@` 2>/dev/null || true 16 | 17 | %.o: %.cpp 18 | $(CXX) $(CFLAGS) -c -o $@ $< 19 | 20 | gates/GateLexer.o: gates/GateParser.cpp 21 | 22 | qc2quigl: $(CIRCUITKIT_OBJS) 23 | $(CXX) $(CFLAGS) -o $@ $^ 24 | 25 | clean: 26 | rm -f *.o gates/*.o QCParser.cpp QCLexer.cpp gates/GateParser.cpp gates/GateLexer.cpp qc2quigl 27 | 28 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/QCLexer.l: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | %option noyywrap 28 | %option nounput 29 | %option never-interactive 30 | %option outfile="QCLexer.cpp" 31 | %option prefix="QC_" 32 | %{ 33 | #include "QCParser.h" 34 | #include "utility.h" 35 | #include 36 | #define SAVE_TOKEN {/*std::cout << yytext << std::endl;*/ QC_lval.string = strdup(yytext);} 37 | #define REMOVE_QUOTES_SAVE_TOKEN {std::string s = yytext; s.erase(s.begin()); s.erase(s.end()-1); QC_lval.string = strdup(s.c_str());} 38 | #define TOKEN(t) (QC_lval.token = t) 39 | #define printok(t) std::cout<. 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef QC_PARSER_UTILS 28 | #define QC_PARSER_UTILS 29 | #include 30 | #include "circuit.h" 31 | class name_node 32 | { 33 | public: 34 | name_node(std::string n_name, name_node *n_next); 35 | name_node(std::string n_name, name_node *n_next, bool n_neg); 36 | ~name_node(); 37 | std::string name; 38 | bool neg; 39 | name_node *next; 40 | }; 41 | 42 | void add_one_bit_gates (std::shared_ptr circ, std::string qubit, std::string gateStr); 43 | void cleanup_bad_gates(std::shared_ptr c,std::vector& error_log); 44 | void add_lines (std::shared_ptr circ, name_node *names); 45 | void add_inputs (std::shared_ptr circ, name_node *names); 46 | void add_outputs (std::shared_ptr circ, name_node *names); 47 | void add_constants (std::shared_ptr circ, name_node *names); 48 | void add_outlabels (std::shared_ptr circ, name_node *names); 49 | void add_gate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp,std::vector& error_log); 50 | void add_gate (std::shared_ptr circ, std::string gateName, name_node *controls,name_node *targets, unsigned int exp, std::vector& error_log); 51 | void addRGate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp, double rot); 52 | void addFracRGate (std::shared_ptr circ, std::string gateName, name_node *names, unsigned int exp, int num, int denom); 53 | void link_subcircs (std::shared_ptr circ); 54 | void insert_break(std::shared_ptrcirc); 55 | //! Checks to see if lines with these names exist in the circuit 56 | bool check_names (std::shared_ptr circ, name_node *names,std::vector& error_log,std::string id); 57 | #endif 58 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/circuitParser.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #ifndef CIRCUIT_PARSER 29 | #define CIRCUIT_PARSER 30 | #include 31 | #include "circuit.h" 32 | #include "utility.h" 33 | 34 | 35 | std::shared_ptr parseCircuit (std::string text,std::vector& error_log_r); 36 | void saveCircuit(std::shared_ptr circ, std::string filename); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/gate.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #include "gate.h" 29 | #include "utility.h" 30 | 31 | #include 32 | 33 | using namespace std; 34 | 35 | Control::Control(int setWire, bool setPol) : wire(setWire), polarity (setPol) {} 36 | 37 | Gate::Gate() 38 | { 39 | breakpoint = false; 40 | colbreak = false; 41 | ctrls = false; 42 | loop_count = 0; 43 | drawType = DEFAULT; 44 | } 45 | 46 | Gate::~Gate() {} 47 | 48 | void Gate::setLoopCount(unsigned int loops) 49 | { 50 | loop_count = loops; 51 | } 52 | 53 | unsigned int Gate::getLoopCount() const 54 | { 55 | return loop_count; 56 | } 57 | 58 | unsigned int Gate::getNumGates() const 59 | { 60 | return 1; 61 | } 62 | 63 | void minmaxWire (const vector &ctrl, const vector &targ, unsigned int &minw, unsigned int &maxw) 64 | { 65 | if (!targ.empty()) { 66 | maxw = minw = targ.at(0); 67 | } else if (!ctrl.empty()) { 68 | maxw = minw = ctrl.at(0).wire; 69 | } else { 70 | maxw = minw = 0; 71 | } 72 | for (unsigned int i = 0; i < targ.size (); i++) { 73 | minw = min (minw, targ[i]); 74 | maxw = max (maxw, targ[i]); 75 | } 76 | for (unsigned int i = 0; i < ctrl.size (); i++) { 77 | minw = min (minw, ctrl[i].wire); 78 | maxw = max (maxw, ctrl[i].wire); 79 | } 80 | } 81 | 82 | gateMatrix::~gateMatrix() 83 | { 84 | } 85 | 86 | gateMatrix::gateMatrix(int n_dim) 87 | { 88 | data = NULL; 89 | dim = n_dim; 90 | } 91 | 92 | gateMatrix::gateMatrix() 93 | { 94 | data = NULL; 95 | dim = 0; 96 | } 97 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/gates/GateLexer.l: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | %option noyywrap 28 | %option nounput 29 | %option never-interactive 30 | %option outfile="GateLexer.cpp" 31 | %option prefix="Gate_" 32 | %{ 33 | #include "GateParser.h" 34 | #include 35 | #include 36 | #define SAVE_TOKEN Gate_lval.string = strdup(yytext); 37 | #define TOKEN(t) (Gate_lval.token = t) 38 | %} 39 | 40 | quote [^\"\n]* 41 | word [[:alnum:]]+\*? 42 | digit [0-9] 43 | int {digit}+ 44 | float {int}\.{int} 45 | num {float}|{int} 46 | whitespace [ \t] 47 | comment #.* 48 | 49 | %x TEXT 50 | %x QUOTE 51 | %% 52 | 53 | 54 | "^" return TOKEN(EXPONENT); 55 | "+" return TOKEN(PLUS); 56 | "-" return TOKEN(MINUS); 57 | "*" return TOKEN(TIMES); 58 | "/" return TOKEN(DIV); 59 | "i" return TOKEN(IMAG); 60 | "(" return TOKEN(LPAREN); 61 | ")" return TOKEN(RPAREN); 62 | "," return TOKEN(COMMA); 63 | "\n" return TOKEN(NEWLINE); 64 | "NAME" BEGIN(TEXT); return TOKEN(NAME); 65 | "DRAWNAME" BEGIN(TEXT); return TOKEN(DRAWNAME); 66 | "LATEXNAME" BEGIN(TEXT); return TOKEN(LATEXNAME); 67 | "SYMBOL" BEGIN(TEXT); return TOKEN(SYMBOL); 68 | "COST" return TOKEN(COST); 69 | {word} BEGIN(INITIAL); SAVE_TOKEN; return WORD; 70 | \" BEGIN(QUOTE); 71 | {quote} SAVE_TOKEN; return WORD; 72 | \" BEGIN(INITIAL); 73 | "sqrt" return TOKEN(SQRT); 74 | {num} SAVE_TOKEN; return NUM; 75 | 76 | 77 | <*>{whitespace} 78 | <*>{comment} 79 | %% 80 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/gates/GateParserUtils.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef GATE_PARSE_UTILS 28 | #define GATE_PARSE_UTILS 29 | #include 30 | #include 31 | struct row_terms { 32 | std::complex *val; 33 | row_terms *next; 34 | row_terms(std::complex *n_val, row_terms *n_next) 35 | { 36 | next = n_next; 37 | val = n_val; 38 | } 39 | row_terms(std::complex *n_val) 40 | { 41 | next = NULL; 42 | val = n_val; 43 | } 44 | ~row_terms() 45 | { 46 | if (next!= NULL) delete next; 47 | if (val != NULL) delete val; 48 | } 49 | }; 50 | 51 | struct matrix_row { 52 | row_terms *terms; 53 | matrix_row *next; 54 | matrix_row(matrix_row *n_next) 55 | { 56 | next = n_next; 57 | terms = NULL; 58 | } 59 | matrix_row(row_terms *n_val, matrix_row *n_next) 60 | { 61 | next = n_next; 62 | terms = n_val; 63 | } 64 | ~matrix_row() 65 | { 66 | if (next!= NULL) delete next; 67 | if (terms != NULL) delete terms; 68 | } 69 | }; 70 | 71 | struct gate_node { 72 | gate_node* next; 73 | std::string name; 74 | std::string drawName; 75 | std::string latexName; 76 | std::string symbol; 77 | matrix_row *row; 78 | gate_node(char* n_name, char* n_dname, char* n_latex_name, char* n_symbol, matrix_row *n_row ) 79 | : name(n_name), drawName(n_dname), latexName(n_latex_name), symbol(n_symbol) 80 | { 81 | next = NULL; 82 | row = n_row; 83 | } 84 | gate_node(char* n_name, char* n_symbol, matrix_row *n_row ) 85 | : name(n_name), drawName(n_symbol), latexName(n_symbol), symbol(n_symbol) 86 | { 87 | next = NULL; 88 | row = n_row; 89 | } 90 | gate_node(char* n_name, char* n_dname, char* n_symbol, matrix_row *n_row ) 91 | : name(n_name), drawName(n_dname), latexName(n_symbol), symbol(n_symbol) 92 | { 93 | next = NULL; 94 | row = n_row; 95 | } 96 | ~gate_node() 97 | { 98 | if (next!= NULL) delete next; 99 | if (row != NULL) delete row; 100 | } 101 | }; 102 | #endif 103 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/gates/UGate.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | //Implimentation code for the UGate 29 | #include "gate.h" 30 | #include "UGateLookup.h" 31 | #include "utility.h" 32 | #include 33 | #include 34 | 35 | 36 | using namespace std; 37 | 38 | UGate::UGate(string n_name) : Gate(), name(n_name) 39 | { 40 | drawType = DEFAULT; 41 | loop_count = 1; 42 | dname_checked = false; 43 | } 44 | 45 | UGate::UGate(string n_name, string n_dname) : Gate(), name(n_name) 46 | { 47 | drawType = DEFAULT; 48 | loop_count = 1; 49 | dname = n_dname; 50 | dname_checked = true; 51 | } 52 | 53 | shared_ptr UGate::clone() const 54 | { 55 | UGate* g = new UGate(name); 56 | g->controls = controls; 57 | g->targets = targets; 58 | g->drawType = drawType; 59 | g->breakpoint = breakpoint; 60 | return shared_ptr(g); 61 | } 62 | 63 | string UGate::getName() const 64 | { 65 | if (drawType == NOT) { 66 | return "tof"; 67 | } else { 68 | return name; 69 | } 70 | } 71 | 72 | string UGate::getDrawName() 73 | { 74 | gateMatrix matrix = UGateLookup(name); 75 | if (matrix.dim == 0) { 76 | cerr << "Game matrix not found for " << name << "!" << endl; 77 | return ""; 78 | } else { 79 | return matrix.drawName; 80 | } 81 | } 82 | 83 | string UGate::getLatexName() 84 | { 85 | gateMatrix matrix = UGateLookup(name); 86 | if (matrix.dim == 0) { 87 | cerr << "Game matrix not found for " << name << "!" << endl; 88 | return ""; 89 | } else { 90 | return matrix.latexName; 91 | } 92 | } 93 | 94 | void UGate::setName(string n_name) 95 | { 96 | name = n_name; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/gates/UGateLookup.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef UGATE_LOOKUP_INC 28 | #define UGATE_LOOKUP_INC 29 | 30 | #include 31 | #include 32 | #include "../gate.h" //for gateMatrix 33 | #include "GateParserUtils.h" 34 | 35 | gate_node *parse_gates(std::string input); 36 | //Function for looking up the matrix of a given ugate Will return null if no matrix is found 37 | gateMatrix UGateLookup(std::string name); 38 | std::vector UGateNames(); 39 | std::vector UGateDNames(); 40 | 41 | //adds a matrix and name 42 | void UGateLoad(std::string name, gateMatrix mat); 43 | 44 | void UGateSetup(); 45 | #endif 46 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/subcircuit.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #include "subcircuit.h" 29 | 30 | using namespace std; 31 | 32 | Subcircuit::Subcircuit(shared_ptr n_circ, const vector & n_linemap, unsigned int loops) : Gate() 33 | { 34 | drawType = DEFAULT; 35 | circ = n_circ; 36 | lineMap = n_linemap; 37 | loop_count = loops; 38 | expand = false; 39 | unroll = false; 40 | ctrls = false; 41 | } 42 | 43 | shared_ptr Subcircuit::clone() const 44 | { 45 | Subcircuit *g = new Subcircuit(circ,lineMap,loop_count); 46 | g->controls = controls; 47 | g->targets = targets; 48 | g->expand = expand; 49 | g->breakpoint = breakpoint; 50 | return shared_ptr(g); 51 | } 52 | 53 | string Subcircuit::getName() const 54 | { 55 | if (circ) return circ->getName(); 56 | return "NULL"; 57 | } 58 | 59 | std::string Subcircuit::getDrawName() 60 | { 61 | return getName(); 62 | } 63 | 64 | std::string Subcircuit::getLatexName() 65 | { 66 | return getName(); 67 | } 68 | 69 | void Subcircuit::setName(string n_name) 70 | { 71 | circ->setName(n_name); 72 | } 73 | 74 | unsigned int Subcircuit::getNumGates() const 75 | { 76 | return circ->totalGates(); 77 | } 78 | 79 | shared_ptr Subcircuit::getGate(int pos) const 80 | { 81 | shared_ptr g = circ->getGate(pos)->clone(); 82 | for (unsigned int i = 0; i < g->targets.size(); i++) { 83 | g->targets.at(i) = lineMap.at(g->targets[i]); 84 | } 85 | for (unsigned int i = 0; i < g->controls.size(); i++) { 86 | g->controls[i].wire = lineMap.at(g->controls[i].wire); 87 | } 88 | shared_ptr s = dynamic_pointer_cast(g); 89 | if (s) { //Combine the maps if it is a subcircuit so we have the correct global map 90 | for (unsigned int i = 0; i < s->lineMap.size(); i++) { 91 | s->lineMap.at(i) = lineMap.at(s->lineMap.at(i)); 92 | } 93 | } 94 | return g; 95 | } 96 | 97 | unsigned int Subcircuit::numGates() const 98 | { 99 | return circ->numGates(); 100 | } 101 | 102 | shared_ptr Subcircuit::getCircuit() 103 | { 104 | return circ; 105 | } 106 | 107 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/subcircuit.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef SUBCIRCUIT_H 28 | #define SUBCIRCUIT_H 29 | 30 | #include "gate.h" 31 | #include "circuit.h" 32 | #include 33 | #include 34 | 35 | //A subcircuit gate contains 36 | class Subcircuit : public Gate 37 | { 38 | public: 39 | Subcircuit(std::shared_ptr, const std::vector&,unsigned int); 40 | std::shared_ptr clone() const; 41 | std::string getName() const; 42 | std::string getDrawName(); 43 | std::string getLatexName(); 44 | void setName(std::string name); 45 | unsigned int getNumGates() const; 46 | unsigned int numGates() const; 47 | 48 | std::shared_ptr getGate(int pos) const; 49 | std::shared_ptr getCircuit(); 50 | 51 | //! Set true is circuit should be draw in expanded mode 52 | bool expand; 53 | //! Set true is circuit should be draw in unrolled mode 54 | bool unroll; 55 | std::shared_ptr circ; 56 | 57 | 58 | protected: 59 | std::vector lineMap; 60 | }; 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/types.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | #ifndef TYPES_H_INCLUDED 28 | #define TYPES_H_INCLUDED 29 | #include 30 | #include 31 | typedef float float_type; 32 | typedef uint64_t index_t; 33 | #endif 34 | -------------------------------------------------------------------------------- /src/QCViewer/qcqg/utility.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker, Marc Burns 25 | ---------------------------------------------------------------------*/ 26 | 27 | /*! \file utility.h 28 | \brief Utility functions 29 | 30 | */ 31 | 32 | #ifndef UTILITY_FUNCS 33 | #define UTILITY_FUNCS 34 | 35 | #include 36 | #include 37 | #include "types.h" 38 | 39 | #define BYTETOBINARYPATTERN "%d%d%d%d%d%d%d%d" 40 | #define BYTETOBINARY(byte) \ 41 | (byte & 0x80 ? 1 : 0), \ 42 | (byte & 0x40 ? 1 : 0), \ 43 | (byte & 0x20 ? 1 : 0), \ 44 | (byte & 0x10 ? 1 : 0), \ 45 | (byte & 0x08 ? 1 : 0), \ 46 | (byte & 0x04 ? 1 : 0), \ 47 | (byte & 0x02 ? 1 : 0), \ 48 | (byte & 0x01 ? 1 : 0) 49 | 50 | void printIntBin(index_t); 51 | 52 | /*! 53 | \brief Returns the floored form of the binary logarithm for a 32 bit integer. 54 | 55 | -1 is returned if ''n'' is 0. 56 | */ 57 | unsigned int floorLog2(unsigned int n); 58 | 59 | int ipow(int base, int exp); 60 | std::string intToString(int i); 61 | std::string floatToString(float_type i); 62 | std::string sToUpper(std::string); 63 | 64 | /* Bit set/get functions */ 65 | /*! 66 | \brief Sets the bit at position reg to 1 67 | */ 68 | unsigned int SetRegister (unsigned int bits, unsigned int reg); 69 | /*! 70 | \brief Sets the bit at position reg to 0 71 | */ 72 | unsigned int UnsetRegister (unsigned int bits, unsigned int reg); 73 | /*! 74 | \brief Returns the value of the bit at position reg 75 | */ 76 | index_t GetRegister (index_t bits, index_t reg); 77 | 78 | unsigned int invertBits (unsigned int bits, unsigned int numBits); 79 | 80 | unsigned int bitcount(unsigned int); 81 | index_t ExtractBits (index_t target, index_t bitString); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/QCViewer/qcviewer/qcviewer.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #include "window.h" 29 | #include "options.h" 30 | #include "QCLib/gates/UGateLookup.h" 31 | #include "info.h" 32 | #include 33 | #include 34 | #include 35 | 36 | QCViewer* window; 37 | 38 | struct Options { 39 | QCVOptions qcvOptions; 40 | bool exit; 41 | std::string circuitFile; 42 | 43 | Options() : exit(false) {} 44 | }; 45 | 46 | Options handleOptions(int,char*[]); 47 | 48 | int main (int ac, char *av[]) 49 | { 50 | srand((unsigned)time(NULL)); 51 | Gtk::Main kit(ac, av); 52 | Options ops = handleOptions(ac, av); 53 | if (ops.exit) 54 | return EXIT_SUCCESS; 55 | UGateSetup(); 56 | window = new QCViewer(ops.qcvOptions); 57 | window->set_default_size (800,600); 58 | if (!ops.circuitFile.empty()) 59 | window->open_circuit(ops.circuitFile); 60 | std::cerr << "Running window\n"; 61 | 62 | Gtk::Main::run(*window); 63 | 64 | return EXIT_SUCCESS; 65 | } 66 | 67 | 68 | Options handleOptions(int ac,char *av[]) 69 | { 70 | namespace po = boost::program_options; 71 | 72 | Options Op; 73 | 74 | //Options parsed from the command line 75 | po::options_description cmd("CmdLine Options"); 76 | cmd.add_options() 77 | ("help", "produce help message") 78 | ("version", "prints out the version") 79 | ; 80 | 81 | //Options parsed from the command line and not shown in help message 82 | po::options_description cmdHidden("Hidden CmdLine Options"); 83 | cmdHidden.add_options() 84 | ("input-file", po::value(), "circuit file to open") 85 | ; 86 | po::positional_options_description p; 87 | p.add("input-file", 1); 88 | 89 | //Options parsed from the config file 90 | po::options_description config("Config"); 91 | config.add_options() 92 | ("draw.dotradius", po::value(&Op.qcvOptions.draw.dotradius)->default_value(10.0), "The Radius of the control dot.") 93 | ; 94 | 95 | po::options_description cmdOptions; 96 | cmdOptions.add(cmd).add(cmdHidden); 97 | 98 | po::variables_map vm; 99 | po::store(po::command_line_parser(ac, av). 100 | options(cmdOptions).positional(p).run(), vm); 101 | po::store(po::parse_config_file("QCV.cfg", config), vm); 102 | po::notify(vm); 103 | 104 | if (vm.count("help")) { 105 | std::cout << cmd << std::endl; 106 | Op.exit = true; 107 | } 108 | if (vm.count("version")) { 109 | std::cout << QCV_NAME << " " << QCV_VERSION << std::endl; 110 | Op.exit = true; 111 | } 112 | if (vm.count("input-file")) { 113 | Op.circuitFile = vm["input-file"].as(); 114 | } 115 | 116 | return Op; 117 | } 118 | -------------------------------------------------------------------------------- /src/QCViewer/stateWidget.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | QCViewer 3 | Copyright (C) 2011 Alex Parent and The University of Waterloo, 4 | Institute for Quantum Computing, Quantum Circuits Group 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | See also 'ADDITIONAL TERMS' at the end of the included LICENSE file. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | QCViewer is a trademark of the of the The University of Waterloo, 22 | Institute for Quantum Computing, Quantum Circuits Group 23 | 24 | Authors: Alex Parent, Jacob Parker 25 | ---------------------------------------------------------------------*/ 26 | 27 | 28 | #ifndef __STATEWIDGET__INCLUDED 29 | #define __STATEWIDGET__INCLUDED 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "QCLib/state.h" 36 | #include 37 | #include 38 | 39 | const unsigned int numBuckets = 512; 40 | 41 | class StateWidget : public Gtk::DrawingArea 42 | { 43 | public: 44 | StateWidget (Gtk::Statusbar*); 45 | void set_state(State *state); 46 | void set_trace(index_t); 47 | void parse_state (); 48 | void parse_state_trace (); 49 | void reset (); 50 | enum DrawMode {EXPECTED,EXPECTED_TRACED, REAL, IMAG } drawmode; 51 | 52 | protected: 53 | virtual bool on_expose_event(GdkEventExpose* event); 54 | virtual bool onMotionEvent (GdkEventMotion* event); 55 | private: 56 | double width, height; 57 | double xborder, yborder; 58 | double tickwidth; 59 | double barWidth, barHeight; 60 | double t_barWidth; 61 | 62 | void force_redraw (); 63 | void drawBar(Cairo::RefPtr cr,int pos, double yPos, double h, int r, int g, int b); 64 | State *state; 65 | Gtk::Statusbar* status; 66 | int mousex, mousey; 67 | bool draw_compressed; 68 | unsigned int num_draw; // number of buckets to draw 69 | index_t bucketID[numBuckets]; // XXX: need to be bitstrings 70 | std::complex bucket[numBuckets]; 71 | 72 | index_t trace; // This is a bit string where 1s indicate parts to be included in the expectation 73 | float_type traced_bucket[numBuckets];// These hold the expectation value of a traced out state 74 | unsigned int num_draw_traced; 75 | }; 76 | 77 | class StateViewWidget : public Gtk::VBox 78 | { 79 | public: 80 | StateViewWidget (Gtk::Statusbar*, Gtk::HBox*, std::vector*, Gtk::VPaned*); 81 | void reset (); 82 | void set_state (State*); 83 | 84 | protected: 85 | void set_style (); 86 | void close (); 87 | 88 | private: 89 | StateWidget sw; 90 | Gtk::HBox buttonbox; 91 | Gtk::VBox layoutbox; 92 | Gtk::RadioButton btn_expected, btn_real, btn_imag; 93 | Gtk::Button btn_close; 94 | Gtk::CheckButton btn_trace; 95 | Gtk::Statusbar* status; 96 | 97 | // These support removing a svw from the main window. It is very ugly to 98 | // have them here. Perhaps something with signals would be a better design? 99 | Gtk::HBox* visbox; 100 | std::vector* svwList; 101 | Gtk::VPaned* vispane; 102 | }; 103 | 104 | std::string draw_state (Cairo::RefPtr cr, State* state, float width ,float height, float mousex, float mousey); 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /src/format: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | astyle -rn --style=k/r "*.h" 3 | astyle -rn --style=k/r "*.cpp" 4 | -------------------------------------------------------------------------------- /testCircuits/errors.qc: -------------------------------------------------------------------------------- 1 | # This is meant to include all errors that we should accept without crashing for testing purposes 2 | .v first,second,third,fourth,fifth 3 | .i first,second,third,fourth,fifth 4 | .o first,second,third,fourth,fifth 5 | BEGIN 6 | t1 first,first #double wire ref 7 | t3 first,second,third,fourth 8 | f first,second,fourth 9 | t1 first,fourth 10 | H second 11 | R(X5.6) s s f 12 | END 13 | -------------------------------------------------------------------------------- /testCircuits/faults/notes: -------------------------------------------------------------------------------- 1 | Place circuits that cause errors here and include a desciption of the error. 2 | -------------------------------------------------------------------------------- /testCircuits/foo.qc: -------------------------------------------------------------------------------- 1 | # asd 2 | .v first,second,third,fourth,fifth 3 | .i first,second,third,fourth,fifth 4 | .o first,second,third,fourth,fifth 5 | BEGIN 6 | H first 7 | H second 8 | H third 9 | H fourth 10 | H fifth 11 | t0 first third 12 | t1 second fifth 13 | h fourth 14 | t0 first 15 | t0 second 16 | t0 third 17 | t0 fourth 18 | t1 first,second 19 | t1 third,fourth 20 | t2 first,second,third 21 | t0 fourth # asd 22 | t3 first,second,third,fourth 23 | t1 first,second 24 | t1 first,third 25 | t1 third,fourth 26 | t1 first,fourth 27 | f first,second,fourth 28 | H second 29 | H third 30 | t0 first 31 | H second 32 | t0 third 33 | H fourth 34 | H first 35 | X first 36 | Y second 37 | Z third 38 | END 39 | -------------------------------------------------------------------------------- /testCircuits/fracRGate.qc: -------------------------------------------------------------------------------- 1 | .v 1 2 3 2 | .i 1 2 3 3 | .o 1 2 3 4 | 5 | BEGIN 6 | RX(0.5) 1 7 | RX(4 pi/3) 2 8 | MEASURE 2 9 | END 10 | -------------------------------------------------------------------------------- /testCircuits/fredtest.qc: -------------------------------------------------------------------------------- 1 | .v a,b,c,d,e 2 | .i a,b,c,d,e 3 | .o a,b,c,d,e 4 | BEGIN 5 | F5 a,d,e,b,c 6 | F4 d,e,a,c 7 | F4 b,e,c,d 8 | F4 c,e,a,d 9 | F3 e,b,d 10 | F3 e,a,b 11 | F5 b,c,d,a,e 12 | F4 c,d,a,b 13 | F3 d,c,e 14 | F3 e,b,d 15 | F4 a,d,b,c 16 | F3 d,b,e 17 | F3 e,c,d 18 | F3 d,a,e 19 | F3 e,b,d 20 | F2 d,e 21 | F4 b,c,a,d 22 | F3 b,c,e 23 | F3 c,a,e 24 | F3 e,b,c 25 | F2 c,d 26 | F3 b,a,d 27 | F2 b,c 28 | F2 a,b 29 | END -------------------------------------------------------------------------------- /testCircuits/fredtest2.qc: -------------------------------------------------------------------------------- 1 | # (c) Copyright 2004-2009 Dmitri Maslov and Igor Markov 2 | # Distributing this file without an express written permission or erasing this note is prohibited. 3 | .v x1,x2,x3,x4,x5,s1,s2,s3 4 | .i x1,x2,x3,x4,x5 5 | .o x1,x2,x3,x4,x5 6 | .c 0,02,03 7 | BEGIN 8 | # Cylcle3_1 application to x1 and s_i 9 | # t4 x1,s1,s2,s3 10 | # t3 x1,s1,s2 11 | t2 x1,s1 12 | # Cylcle3_1 application to x2 and s_i 13 | # t4 x2,s1,s2,s3 14 | t3 x2,s1,s2 15 | t2 x2,s1 16 | # Cylcle3_1 application to x3 and s_i 17 | # t4 x3,s1,s2,s3 18 | t3 x3,s1,s2 19 | t2 x3,s1 20 | # Cylcle3_1 application to x4 and s_i 21 | t4 x4,s1,s2,s3 22 | t3 x4,s1,s2 23 | t2 x4,s1 24 | # Cylcle3_1 application to x5 and s_i 25 | t4 x5,s1,s2,s3 26 | t3 x5,s1,s2 27 | t2 x5,s1 28 | # Fredkins with control=s1 and swapping distance 1 29 | f3 s1,x1,x2 30 | f3 s1,x3,x4 31 | f3 s1,x5,x1 32 | f3 s1,x3,x5 33 | # Fredkins with control=s2 and swapping distance 2 34 | f3 s2,x1,x3 35 | f3 s2,x2,x4 36 | f3 s2,x5,x2 37 | f3 s2,x1,x5 38 | # Fredkins with control=s3 and swapping distance 4 39 | f3 s3,x1,x5 40 | f3 s3,x2,x1 41 | f3 s3,x3,x2 42 | f3 s3,x4,x3 43 | END 44 | -------------------------------------------------------------------------------- /testCircuits/mod5d4.qc: -------------------------------------------------------------------------------- 1 | .v foobar,"this is a really long label",c,test123,e 2 | .i foobar,"this is a really long label",c,test123 3 | .o e 4 | .c 1 5 | BEGIN 6 | t2 foobar,c 7 | t2 "this is a really long label",test123 8 | t3 c,test123,e 9 | t2 c,test123 10 | t2 test123,e 11 | ABCDEF test123 12 | H test123 13 | END 14 | -------------------------------------------------------------------------------- /testCircuits/mod5d4orig.qc: -------------------------------------------------------------------------------- 1 | .v a,b,c,d,e 2 | .i a,b,c,d 3 | .o e 4 | .c 1 5 | BEGIN 6 | t2 a,c 7 | t2 b,d 8 | t3 c,d,e 9 | t2 c,d 10 | t2 d,e 11 | END 12 | -------------------------------------------------------------------------------- /testCircuits/neg.qc: -------------------------------------------------------------------------------- 1 | .v a b 2 | .i a b 3 | .o a b 4 | BEGIN 5 | t1 a' b 6 | END 7 | -------------------------------------------------------------------------------- /testCircuits/not.qc: -------------------------------------------------------------------------------- 1 | .v a 2 | .i a 3 | .o a 4 | BEGIN 5 | t0 a 6 | END 7 | -------------------------------------------------------------------------------- /testCircuits/oneBit/oneBitTest.qc: -------------------------------------------------------------------------------- 1 | .v 1 2 3 2 | .i 1 2 3 3 | .o 1 2 3 4 | 5 | BEGIN 6 | H 3 7 | 1 | H T X H T H Y T H 8 | T 2 9 | TOF 1 2 3 10 | END 11 | -------------------------------------------------------------------------------- /testCircuits/simple.qc: -------------------------------------------------------------------------------- 1 | .v a b c 2 | .i a b c 3 | .o a b c 4 | BEGIN 5 | asdfasdf a 6 | H b 7 | t2 a b c 8 | H a 9 | T* a 10 | T a 11 | P* b 12 | P b 13 | asdfsadf b 14 | END 15 | -------------------------------------------------------------------------------- /testCircuits/test1.qc: -------------------------------------------------------------------------------- 1 | .v 1 a b c d e Workspace test 2 | .i 1 a b c d e Workspace test 3 | .o 1 a b c d e 4 | .c 5 | 6 | BEGIN S1 (1 2 3 4) 7 | Y 2 8 | S2 3 4 9 | RX(0.5) 1 10 | RY(0.5) 1 11 | RZ(0.5) 1 12 | H 2 13 | S2^4 1 3 14 | H 3 15 | S2 1 2 16 | X 4 17 | END S1 18 | 19 | BEGIN S2 (1 2) 20 | X 1 21 | Y 2 22 | T 1 2 23 | END S2 24 | 25 | BEGIN H5(a b c d e) 26 | H a 27 | H b 28 | H c 29 | H d 30 | H e 31 | END H5 32 | 33 | BEGIN GroverIterate (a b c d e Workspace) 34 | H Workspace 35 | T5 a' b' c d e' Workspace 36 | H Workspace 37 | 38 | H5 a b c d e 39 | 40 | X e 41 | Z a' b' c' d' e 42 | X e 43 | 44 | H5 a b c d e 45 | END GroverIterate 46 | 47 | BEGIN 48 | H5 a b c d e 49 | tof a b c d 50 | not b c d e 51 | S1 a b d c 52 | GroverIterate test | a b c d e Workspace 53 | tof a b c d 54 | S1 b c d e 55 | TOF a b c d 56 | NOT b c d e 57 | a : xt*yz 58 | 1 : xtyzh 59 | END 60 | -------------------------------------------------------------------------------- /utils/randCirc/randCirc.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def randCirc(qubits,gates): 4 | s = "" 5 | r = "" 6 | gateset = ["T","T*","H","X","Y","Z","RX(1 pi/8)","RY(1 pi/4)","RZ(1 pi/2)"] 7 | for i in range(qubits): 8 | s += " "+str(i) 9 | r += ".v"+s+"\n" 10 | r += ".i"+s+"\n" 11 | r += ".o"+s+"\n" 12 | r += "BEGIN\n" 13 | for i in range(gates): 14 | r += random.choice(gateset) 15 | loc = random.randint(0,qubits-1) 16 | r+=" " + str(loc) 17 | locs=[]; 18 | for j in range(int(random.triangular(0, 6, 0))): 19 | loc+= random.randint(1,3) 20 | if loc > 0 and loc < qubits-1: 21 | locs.append(loc) 22 | random.shuffle(locs) 23 | for j in locs: 24 | r+=" "+str(j) 25 | r+="\n" 26 | r += "END\n" 27 | f = open('circ.qc', 'w') 28 | f.write(r) 29 | print r 30 | --------------------------------------------------------------------------------