quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · parthiban loganathan. why quark?...
TRANSCRIPT
![Page 1: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/1.jpg)
QuarkQuark
![Page 2: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/2.jpg)
The TeamThe TeamDaria JungJamis JohnsonLinxi Fan (Jim)Parthiban Loganathan
![Page 3: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/3.jpg)
Why Quark?Why Quark?
Quantum computing has the potential tobecome a reality in the next few decades. We'rethinking ahead of the curve and have developeda language that makes it easy to build quantum
circuits, which consist of quantum gates andquantum registers holding qubits.
![Page 4: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/4.jpg)
Quantum Computing will allow us to:Quantum Computing will allow us to:
Factorize large integers in polynomial time (Shor's algorithm)Search unsorted database in sublinear time (Grover's Search)Build the Infinite Improbability Drive and solve intergalactictravel
![Page 5: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/5.jpg)
What is Quark?What is Quark?"QUantum Analysis and Realization Kit""QUantum Analysis and Realization Kit"
A high-level language for quantum computing that
encapsulates mathematical operations and quantumcomputing specific components like quantum registers.
A futuristic compiler on your laptop.
![Page 6: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/6.jpg)
FeaturesFeaturesEasy-to-use, high-level language influenced by MATLABand PythonUseful built-in data types for fractions and complexnumbersSupport for matrices and matrix operationsQuantum registers and ability to query themBuilt-in quantum gate functionsImportsInformative semantic error messagesCross-platform
![Page 7: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/7.jpg)
How did we do it?How did we do it?
Compiler flow:Compiler flow:
PreprocessorScannerParserASTSemantic CheckerSASTCode GeneratorOS-aware g++ invocationQuantum Simulator (Quark++)
![Page 8: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/8.jpg)
PreprocessorPreprocessorResolves import statements before the scanner andparser stagesRecursively finds all imports and prepends them tothe fileHandles cyclic and repetitive imports
![Page 9: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/9.jpg)
ScannerScannerBased on MicroC
All the usual tokens + specific ones for
fractions : 1$2complex numbers : i(3, 4)
i can still be used as a variable, not a functionmatrix operations : [|1,2; 3,4|], A', A ** Bquantum registers and querying : qreg, <|10,1|>,q ? [1:5], q ?' 3
![Page 10: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/10.jpg)
ParserParserGrammar was developed incrementally
Quantum registers queryMatrix and high dimensional array literalsMembershipFractions, complex numbersPythonic for-loops
Pacman Parsing
![Page 11: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/11.jpg)
Some example rulesSome example rulesexpr: ... /* Query */ | expr ? expr | expr ? [ : expr ] | expr ? [expr : expr ] ... /* Membership testing with keyword 'in' */ | expr in expr ... /* literals */ | expr $ expr | [| matrix_row_list |] | i( expr , expr ) | <| expr , expr |>
iterator: | ident in [range] | datatype ident in [range] | datatype ident in expr
![Page 12: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/12.jpg)
Lexical and syntactical analysisLexical and syntactical analysiscompletecomplete
Now we need semantic checksNow we need semantic checks
Valid syntax doesn't always make sense
The importance of semantic checks in real life
![Page 13: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/13.jpg)
Semantic CheckerSemantic Checker
StrMap hashtablesVariable table
Function table
![Page 14: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/14.jpg)
Semantic CheckerSemantic Checker
Environment struct
![Page 15: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/15.jpg)
Semantic CheckerSemantic Checker
From AST to SAST
![Page 16: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/16.jpg)
Semantic CheckerSemantic Checker
Traverse AST recursively to produce SAST
![Page 17: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/17.jpg)
Semantic CheckerSemantic Checker
Tag the SAST with op_tag constants tofacilitate code generation
![Page 18: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/18.jpg)
Semantic CheckerSemantic CheckerTag the SAST with op_tag constants tofacilitate code generation
![Page 19: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/19.jpg)
Semantic CheckerSemantic CheckerSeparate source file for built-in functions (e.g.quantum gates)Can be overridden by usersprint() and print_noline() support any number of argsof any type
![Page 20: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/20.jpg)
Semantic CheckerSemantic CheckerError messages
"A function is confused with a variable: u""Function foo() is forward declared, but calledwithout definition""If statement predicate must be bool, butfraction provided""Array style for-loop must operate on arraytype, not complex[|]""Matrix element unsupported: string""Incompatible operands for **: string -.-fraction""All rows in a matrix must have the samelength"
![Page 21: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/21.jpg)
Code GenerationCode Generation
![Page 22: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/22.jpg)
Code GenerationCode Generation
Recursively walks the SAST to generate a string ofvalid C++ programThe generated string, concatenated with a headerstring, should compile with the simulator andEigen library
No exception should be thrown at this stage
![Page 23: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/23.jpg)
Code GenerationCode Generation
int → C++ int64_tfloat → C++ primitive floatstring → C++ std::stringcomplex → C++ std::complex<float>arrays → C++ std::vector<>matrices → Eigen::Matrix<float, Dynamic, Dynamic>fraction → Quark++ Frac classqreg → Quark++ Qureg class
Type Mapping
![Page 24: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/24.jpg)
Code GenerationCode GenerationOp Tag
![Page 25: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/25.jpg)
Code GenerationCode GenerationPythonic for-loop
[len(a) : 0 : step(x)] the step size can be negativeWhether step(x) is negative or not can only bedetermined at runtimeWe use system generated temp variables tohandle this.Always prefixed with "_QUARK_" and followed bya string of 10 random chars.
![Page 26: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/26.jpg)
Code GenerationCode GenerationPythonic for-loop
![Page 27: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/27.jpg)
Code GenerationCode GenerationMore examples
![Page 28: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/28.jpg)
Code GenerationCode GenerationMore examples
![Page 29: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/29.jpg)
Simulator: Quark++Simulator: Quark++
![Page 30: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/30.jpg)
Simulator: Quark++Simulator: Quark++
Written over the summer. Built fromscratch except for the Eigen matrix library.Features optimized C++11 code forquantum register manipulation andquantum gates/operations. Can be used as a standalone library for anyquantum computing education or researchprojectMinor modification to accomodate theQuark language.
![Page 31: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/31.jpg)
User InterfaceUser InterfaceCommand line args
-s: source-c: generated.cpp-o: excutable-sc, -sco-static
Precompiled dynamic/static librariesMinimal user effort to install dependenciesOS aware. Supports all major OSes
![Page 32: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/32.jpg)
Let's look at some codeLet's look at some codeA simple Hello World
def int main:{ print("Hello, Ground!");
return 0;}
It was unfortunately avery short hello for our
whale friend
![Page 33: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/33.jpg)
Defining typesDefining types
int i = 4;float f = 2.0;bool b = true;string s = "So Long, and Thanks for All the Fish";string[] arr = ["Ford", "Prefect", "Zaphod", "Beeblebrox"];int[][] arr2 = [[1,2,3],[4,5,6]];
fraction f = 84$2;complex c = i(5.0, 7.0);float[|] = [|1.0, 2.1; 3.2, 46.1|];
qreg q = <| 42, 0 |>;
![Page 34: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/34.jpg)
Special operationsSpecial operations
% FRACTIONSfrac foo = 2$3;~foo; % 3$2int i = 5;i > foo; % true
% COMPLEX NUMBERScomplex cnum = i(3.0, 1);real(cnum); % 3.0imag(cnum); % 1complex cnum2 = i(9) % this gives us i(9, 0)
% MATRICESfloat[|] mat = [| 1.2, 3.4; 5.6, 7.8 |];mat[2, 1];mat'; % transpose matrix
% QUANTUM REGISTERSqreg q = <|10, 3|>;hadamard(q);q ? [2:10]; % measures qubit 2 to 10
![Page 35: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/35.jpg)
Control flowControl flow
if x > 0: print("positive");elif x < 0: print("negative");else: print("zero");
while x > 42: { print(x); x = x - 1;}
int[] arr = [1,2,3];for int i in arr: print i;
int i;for i in [1:10]for int i in [1:10:2]
![Page 36: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/36.jpg)
ImportsImports
import ../lib/mylib1;import ../lib/herlib2;
import imported_file;
def int main:{ return imported_file.function(5);}
So Fancy!
![Page 37: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/37.jpg)
Simple GCDSimple GCD
def int gcd: int x, int y{ while y != 0: { int r = x mod y; x = y; y = r; } return x;}
def int main:{ % prints the greatest common divisor of 10 and 20 print(gcd(10, 20)); return 0;}
![Page 38: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/38.jpg)
Quantum Computing DemoQuantum Computing DemoTimeTime
Hang on to your Towel!
Let's see Shor's algorithm and Grover'sSearch in action! Real quantum computing
programs running on a not-so-real quantumcomputer (our simulator)
![Page 39: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/39.jpg)
What did we learn?What did we learn?
![Page 40: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/40.jpg)
Start early!!!Start early!!!
![Page 41: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/41.jpg)
OCaml:OCaml:[oh-kam-uh l]
Mostly harmless
![Page 42: Quarksedwards/classes/2014/w4115-fall/... · 2014-12-18 · Parthiban Loganathan. Why Quark? Quantum computing has the potential to become a reality in the next few decades. We're](https://reader034.vdocuments.mx/reader034/viewer/2022043005/5f89afe2591cf205041dd399/html5/thumbnails/42.jpg)
Interacting with other homo sapiensInteracting with other homo sapiens
Group projects are painful (more so than Vogon poetry)Allocating work strategically avoids bottlenecks inpipelineBetter communication saves time and headachesDictatorship > Democracy when it comes to software