You can find some example Qwerty programs in the examples/
directory. You can
run any of them like any Python script, as ./dj.py
or python dj.py
. Some
take command-line arguments; you can see a description by passing --help
to
any example. The examples are the following:
-
bell.py
: Prepares a Bell state and prints measurement statistics -
ghz.py
: Prepares a GHZ state and measures it. Takes number of qubits as command-line argument -
ghz_flip.py
: Same asghz.py
except the.flip
primitive is used instead of a basis translation -
deutsch.py
: Deutsch's algorithm from Section 1.4.3 of Nielsen and Chuang -
bv.py
: Bernstein–Vazirani, effectively a quantum "Hello World". Takes the secret bitstring$s$ as a command-line argument -
bv_simple.py
: A trimmed-down version ofbv.py
that fits on a presentation slide or poster -
dj.py
: Deutsch-Jozsa, a more general version of Bernstein-Vazirani (arguably). Based on Section 1.4.4 of Nielsen and Chuang -
grover.py
: Grover's Algorithm, aka unstructured search. The oracle is pretty trivial, currently looking for all 1s. Based on Section 6.1 of Nielsen and Chuang. The (required) command line argument is the number of qubits. -
period.py
: A very fun example of finding the period$r$ of a function$f(x) = f(x+r)$ based on Section 5.4.1 of Nielsen and Chuang. -
simon.py
: Simon's algorithm (1, 2)-
simon_post.py
: Full classical post-processing for Simon's
-
-
qpe.py
: Quantum phase estimation, a technique for estimating the eigenvalues of an operator and a crucial ingredient for order finding (below). Based on Section 5.2 of Nielsen and Chuang. -
order_finding.py
: Order finding, which usesqpe.py
to probabilistically find the multiplicative order$r$ of an integer$x$ mod$N$ . Used in Shor's algorithm (below). Based on Section 5.3.1 of Nielsen and Chuang. -
shors.py
: a pure-Python implementation of Shor's algorithm which usesorder_finding.py
. Currently set up to factor 15, because larger numbers cannot be simulated feasibly. Based on Section 5.3.2 of Nielsen and Chuang -
fix_pt_amp.py
: Fixed-point amplitude amplification due to Yoder, Low, and Chuang-
fix_pt_phases.py
: Classical code to generate QSP/QSVT phases used in the algorithm
-
-
match.py
: Niroula-Nam string matching (usesfix_pt_amp.py
) -
stern_gerlach.py
: The Stern–Gerlach experiment as described by Karam (Fig. 4) -
teleport.py
: Quantum teleportation as described in Section 1.3.7 of Nielsen and Chuang
All examples take a --acc
flag that is useful for testing QIR-EE integration
(see docs/qiree.md
).
There is also a helper script, ./render.sh
, which generates .png
files for
visualizing an AST from .dot
files (which are generated from saying
QWERTY_DEBUG=1 python3 an_example.py
— see docs/debugging.md
for details).