Compiler#

[1]:
from quantpiler.compiler import assemble

Basics#

[2]:
def assigment_func(a, b, c):
    a = False
    b = True


qc = assemble(assigment_func, 0)
qc.draw(output="mpl")
[2]:
../_images/examples_compiler_3_0.png
[3]:
def new_var_func(a, b):
    a = True
    # Yes, we can create local variables
    c = a | b


qc = assemble(new_var_func, 0)
qc.draw(output="mpl")
[3]:
../_images/examples_compiler_4_0.png
[4]:
def and_func(a, b, c):
    c = a & b


qc = assemble(and_func, 0)
qc.draw(output="mpl")
[4]:
../_images/examples_compiler_5_0.png
[5]:
def or_func(a, b, c):
    c = a | b


qc = assemble(or_func, 0)
qc.draw(output="mpl")
[5]:
../_images/examples_compiler_6_0.png
[6]:
def xor_func(a, b, c):
    c = a != b


qc = assemble(xor_func, 0)
qc.draw(output="mpl")
[6]:
../_images/examples_compiler_7_0.png
[7]:
def equals_func(a, b, c):
    c = a == b


# For this operation we need 1 ancilla
qc = assemble(equals_func, 1)
qc.draw(output="mpl")
[7]:
../_images/examples_compiler_8_0.png

Complex function#

[8]:
def example_func(a, b):
    a = True
    a_or_b = a | b
    tmp = a & a_or_b
    b = tmp != False


qc = assemble(example_func, 1)
qc.draw(output="mpl")
[8]:
../_images/examples_compiler_10_0.png

Very complex function#

[9]:
def complex_func(a, b, c, d):
    a = True
    not_a = not a
    b = not not_a
    a_or_d = a | d
    c = b & (a_or_d | (d == a))
    d = (c != False) & b == True
    b = a | d


qc = assemble(complex_func, 4)
qc.draw(output="mpl")
[9]:
../_images/examples_compiler_12_0.png