0% found this document useful (0 votes)
49 views

Coding - Silq

Silq is a high-level quantum programming language that describes quantum operations at a higher level of abstraction than existing languages that describe quantum circuits directly. Silq aims to reduce and simplify code, enable static safety checks to prevent errors, and provide more intuitive semantics compared to lower-level languages. It allows programmers to write quantum algorithms in a more natural way while still targeting physical quantum devices and downstream applications.

Uploaded by

kurt k
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Coding - Silq

Silq is a high-level quantum programming language that describes quantum operations at a higher level of abstraction than existing languages that describe quantum circuits directly. Silq aims to reduce and simplify code, enable static safety checks to prevent errors, and provide more intuitive semantics compared to lower-level languages. It allows programmers to write quantum algorithms in a more natural way while still targeting physical quantum devices and downstream applications.

Uploaded by

kurt k
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Silq: A High-level Quantum

Programming Language

Benjamin Bichsel Maximilian Baader Timon Gehr Martin Vechev


Quantum Programming Languages
Existing languages: Describe circuits Silq: Describes high-level operations

Qiskit Quipper

Reduce & simplify Static safety /


code Prevent errors
Q# ProjectQ

QWire
Safe automatic More intuitive
uncomputation semantics
LIQ𝑈𝑖|〉 QASM

Forest … Downstream
Physicality applications
Source of icons: https://fontawesome.com
Quantum Programming Languages

Comparison on Microsoft’s Q# coding contests, see https://silq.ethz.ch/comparison


Goals of this Lecture

Learn Silq’s language concepts Discuss & compare languages

Try out Silq Report issues


Source of icons: https://fontawesome.com
Background (minimal)

Concept Explanation
State of quantum bit 𝜑 = 𝛾0 ȁ0ۧ + 𝛾1 ȁ1ۧ for 𝛾0 , 𝛾1 ∈ ℂ
1 1
(Computational) basis states ห0ۧ, ȁ1ۧ, but not ȁ0 ۧ + ȁ1 ۧ
2 2

No-cloning theorem Impossible: φ ⟼ φ ⊗ φ


Basic Features of Silq
if x { // controlled on x,
y:=H(y); // apply H to y
y:=H(x); x:=H(x); }
Grover’s Algorithm - Recap

𝑓: −2𝑛−1 , … , 2𝑛−1 − 1 → 0,1


𝑓 𝑤∗ = 1
𝑓 𝑣 = 0 for all 𝑣 ≠ 𝑤 ∗
Grover’s Algorithm in Silq
Grover’s Algorithm in Silq

Time
Grover’s Algorithm in Silq
Grover’s Algorithm in Silq
Grover’s Algorithm in Silq
Grover’s Algorithm in Silq

Type Classical or Quantum?


B Classical / Quantum
int[n] / uint[n] Classical / Quantum
ℕ, ℤ, ℚ, ℝ Classical
Generic parameters Classical
Grover’s Algorithm in Silq
Grover’s Algorithm in Silq

𝑔 classical bijection

Function Semantics Qfree?


1 1
X ෍ 𝛾𝑣 ȁ𝑣ۧ ↦ ෍ 𝛾𝑣 ȁ1 − 𝑣ۧ Qfree
𝑣=0 𝑣=0

General (non-classical) ෍ 𝛾𝑣 ȁ𝑣Ԧ ۧ ↦ ෍ 𝛾𝑣 ȁ𝑔(𝑣)


Ԧ ۧ Qfree
𝑣 𝑣
1 1
H ෍ 𝛾𝑣 ȁ𝑣ۧ ↦ ෍ 𝛾𝑣 ȁ0ۧ + (−1)𝑣 ȁ1ۧ Not Qfree
𝑣=0 𝑣=0
Grover’s Algorithm in Silq

y:=f(x);

෍ 𝛾𝑣 ȁ𝜑𝑣 ۧȁ𝑣 ۧ𝑥 ⟼ ෍ 𝛾𝑣 ȁ𝜑𝑣 ۧȁ𝑣 ۧ𝑥 ȁ𝑓(𝑣)ۧ𝑦


𝑣 𝑣

qfree with 𝑔 𝑣 = 𝑣, 𝑓(𝑣)


Grover’s Algorithm in Silq
Grover’s Algorithm in Silq
Automatic Uncomputation

if f(cand) {
phase(𝜋); 1 1
} ෍ ȁ𝑣 ۧcand ȁ0ۧtmp − ȁ𝑤 ∗ ۧcand ȁ1ۧtmp
𝑣≠𝑤 ∗
2𝑛 2𝑛

implicit measurement

1 1
෍ ȁ𝑣 ۧcand ȁ0ۧtmp ȁ𝑤 ∗ ۧcand ȁ1ۧtmp
2𝑛 2𝑛
𝑣≠𝑤 ∗
Automatic Uncomputation
const

if f(cand) {
phase(𝜋); 1 1
} ෍ ȁ𝑣 ۧcand ȁ0ۧtmp − ȁ𝑤 ∗ ۧcand ȁ1ۧtmp
𝑣≠𝑤 ∗
2𝑛 2𝑛
qfree
Live Coding
Summary of Type Annotations
Documentation on http://silq.ethz.ch/documentation#/documentation/1_annotations

mfree const

classical qfree
Source of icons: https://fontawesome.com
Downstream Applications

Simulation Compilation

Research Teaching
Source of icons: https://fontawesome.com
Try Silq Yourself!

Install Try examples


Follow instructions on Try to solve tasks / run solutions from
http://www.silq.ethz.ch/install http://www.silq.ethz.ch/examples

Source of icons: https://fontawesome.com


Interested in Silq?

Benjamin Bichsel
Ask & Contact us! Max Baader
Complain! Timon Gehr
Bachelor/Master thesis Prof. Martin Vechev
In person or Research projects (ETH Zürich)
via Slack channel PhD
https://www.sri.inf.ethz.ch/

Source of icons: https://fontawesome.com


Invalid Programs From Live Coding
• The following slides are here for completeness.
Preventing Errors- Use Consumed
def useConsumed(x:𝔹){
y := H(x);
return (x,y); // undefined identifier x
}

def duplicateConst(const x:𝔹){


y := H(x);
return (x,y); // no error
}
Preventing Errors- Implicit Measurements
def implicitMeas[n:!ℕ](x:uint[n]){
y := x % 2;
return y;
} // parameter 'x' is not consumed

def unconsumedConst[n:!ℕ](const x:uint[n]){


y := x % 2;
return y;
} // no error
Preventing Errors- Conditional
Measurements
def condMeas(const c:𝔹,x:𝔹){
if c{
x:= measure(x);
}
return x;
} // cannot call function 'measure[𝔹]' in 'mfree' context
def classCondMeas(const c:!𝔹,x:𝔹){
if c{
x:= measure(x):𝔹;
}
return x;
} // no error
Preventing Errors- Reverse Measurements
def revMeas(){
return reverse(measure);
} // reversed function must be mfree
Preventing Errors- Invalid Uncomputation
def nonConst(y:𝔹){
if X(y) { // X consumes y
phase(π);
}
} // non-'lifted' quantum expression must be consumed

def signFlipOf0(const y:𝔹){


if X(y) { // X consumes a copy of y
phase(π);
}
} // no error
Preventing Errors- Invalid Uncomputation
def nonQfree(const y:𝔹,z:𝔹){
if H(y) {
z := X(z);
}
return z;
} // non-'lifted' quantum expression must be consumed

You might also like