A cute robot building itself with artificial intelligence,
pencil
drawing - DALL·E 2
hierq = Qinit(5)
hierq = Qinit(5) + Qcycle(stride=1, step=1, offset=0)
hierq = Qinit(8) + Qcycle(stride=1, step=1, offset=0)
hierq = Qinit(5)
hierq = Qinit(5) + Qcycle(stride=1, step=1, offset=0)
hierq = Qinit(8) + Qcycle(stride=1, step=1, offset=0)
hierq = Qinit(5) + Qcycle(stride=1, step=1, offset=0)
hierq = Qinit(8) + Qcycle(stride=1, step=1, offset=0)
hierq = Qinit(8) + Qcycle(stride=1, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=1, offset=0)
hierq = Qinit(8) + Qcycle(stride=1, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=2, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=2, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=3, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=2, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=3, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=2, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=3, step=1, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=2, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=3, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=2, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=3, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=3, offset=1, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=3, offset=0, boundary="open")
hierq = Qinit(8) + Qcycle(stride=1, step=3, offset=1, boundary="open")
hierq = Qinit(8) + Qcycle(1,1,0, mapping = u2)
hierq = Qinit(8) + Qcycle(1,1,0, mapping = u2)
hierq(backend="qiskit")
hierq(backend="pennylane")
hierq = Qinit(8) + Qcycle(1,1,0, mapping = u2)
hierq(backend="qiskit")
hierq(backend="pennylane")
hierq = Qinit(8) + Qmask("10100000")
hierq = Qinit(8) + Qmask("1*")
hierq = Qinit(8) + Qmask("!00")
hierq = Qinit(8) + Qmask("10100000")
hierq = Qinit(8) + Qmask("1*")
hierq = Qinit(8) + Qmask("!00")
hierq = Qinit(8) + Qmask("1*")
hierq = Qinit(8) + Qmask("!00")
hierq = Qinit(8) + Qmask("!*")
hierq = Qinit(8) + Qmask("!00")
hierq = Qinit(8) + Qmask("!*")
hierq = Qinit(8) + Qcycle(mapping = u2) + Qmask("*!") + Qcycle(mapping = u2)
hierq = Qinit(8) + Qcycle(mapping = u2) + Qmask("*!") + Qcycle(mapping = u2)
cycle = Qcycle(mapping = u2)
hierq = Qinit(8) + cycle + Qmask("*!", mapping=v2) + cycle
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!", mapping=v2)
hierq = Qinit(8) + cycle_mask
hierq = Qinit(8) + cycle_mask * 3
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!", mapping=v2)
hierq = Qinit(8) + cycle_mask
hierq = Qinit(8) + cycle_mask * 3
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("!*", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("!*!", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!*", mapping=v2)
hierq = Qinit(8) + cycle_mask * 3
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("!*", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("!*!", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!*", mapping=v2)
hierq = Qinit(8) + cycle_mask * 3
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("!*", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("!*!", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!*", mapping=v2)
hierq = Qinit(8) + cycle_mask * 3
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("!*", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("!*!", mapping=v2)
cycle_mask = Qcycle(1, 1, 0, mapping=u2) + Qmask("*!*", mapping=v2)
hierq = Qinit(8) + cycle_mask * 3
# Example Search Space
strides = range(1, 8, 1)
steps = range(1, 8, 1)
mappings = [a, b, c, d, e, f, g, h]
boundaries = ["open", "periodic"]
patterns = ["10", "01", "*!", "!*", "!*!", "*!*"]
qcnn = Qinit(8) + (Qcycle(...) + Qmask(...)) * 3
u0 = Qinit(4) + Qpermute(share_weights=False, mapping=Ugm)
u1 = Qcycle(1,3,2, mapping=u0, boundary="open", edge_order=[1,3,2,4])
u2 = sum([Qcycle(1,3,offset, mapping=Ugm, boundary="open") for offset in range(3)])
u3 = Qmask("101",1,3,0, mapping=Vgm, boundary="open")
u4 = Qcycle(1, mapping=Ugm, boundary="open")
motif = Qinit(15) + u1 + u2 + u3 + u4
def or(bits, symbols=None, state=None):
b1, b2 = state[bits[0]], state[bits[1]]
state[bits[0]] = b1 or b2
return state
tensors = [np.array([1, 0])] * 5
hierq = (Qinit(5, tensors=tensors)
+ mask_anc
+ U_psi + grover)
psi = hierq()
# ====== Motifs level 1
carry_motif = (
Qinit(4)
+ Qmotif(E=[(1, 2, 3)], mapping=toffoli)
+ Qmotif(E=[(1, 2)], mapping=cnot)
+ Qmotif(E=[(0, 2, 3)], mapping=toffoli)
)
# Turn carry into a function to be able to reverse it easily
carry = lambda r: carry_motif if r == 1 else carry_motif.reverse()
plot_circuit(carry(1))
plot_circuit(carry(-1))
# ====== Motifs level 1
carry_motif = (
Qinit(4)
+ Qmotif(E=[(1, 2, 3)], mapping=toffoli)
+ Qmotif(E=[(1, 2)], mapping=cnot)
+ Qmotif(E=[(0, 2, 3)], mapping=toffoli)
)
# Turn carry into a function to be able to reverse it easily
carry = lambda r: carry_motif if r == 1 else carry_motif.reverse()
plot_circuit(carry(1))
plot_circuit(carry(-1))
# ====== Motifs level 1
sum = lambda r=1: Qinit(3, name=f"sum") + Qpivot(
"*1", merge_within="01", mapping=cnot, edge_order=[-1 * r]
)
plot_circuit(sum(1))
plot_circuit(sum(-1))
# ====== Motifs level 1
sum = lambda r=1: Qinit(3, name=f"sum") + Qpivot(
"*1", merge_within="01", mapping=cnot, edge_order=[-1 * r]
)
plot_circuit(sum(1))
plot_circuit(sum(-1))
# ====== Motifs level 2
carry_sum_motif = (
lambda r=1: Qinit(4, name=f"crs")
+ Qpivot("1*", merge_within="1111", mapping=carry(-r))
+ Qpivot("1*", merge_within="111", mapping=sum(r))
)
carry_sum = lambda r=1: carry_sum_motif(1) if r == 1 else carry_sum_motif(-1).reverse()
plot_circuit(carry_sum(1))
plot_circuit(carry_sum(-1))
# ====== Motifs level 2
carry_sum_motif = (
lambda r=1: Qinit(4, name=f"crs")
+ Qpivot("1*", merge_within="1111", mapping=carry(-r))
+ Qpivot("1*", merge_within="111", mapping=sum(r))
)
carry_sum = lambda r=1: carry_sum_motif(1) if r == 1 else carry_sum_motif(-1).reverse()
plot_circuit(carry_sum(1))
plot_circuit(carry_sum(-1))
cnot_sum_motif = (
lambda r=1: Qinit(3, name=f"cns")
+ Qpivot("*1", merge_within="11", mapping=cnot)
+ Qpivot("*1", merge_within="111", mapping=sum(r))
)
cnot_sum = lambda r=1: cnot_sum_motif(1) if r == 1 else cnot_sum_motif(-1).reverse()
plot_circuit(cnot_sum(1))
plot_circuit(cnot_sum(-1))
cnot_sum_motif = (
lambda r=1: Qinit(3, name=f"cns")
+ Qpivot("*1", merge_within="11", mapping=cnot)
+ Qpivot("*1", merge_within="111", mapping=sum(r))
)
cnot_sum = lambda r=1: cnot_sum_motif(1) if r == 1 else cnot_sum_motif(-1).reverse()
plot_circuit(cnot_sum(1))
plot_circuit(cnot_sum(-1))
# ====== Motifs level 3
carry_layer = lambda r=1: Qcycle(
1,
3,
0,
mapping=carry(r),
boundary="open",
edge_order=[r],
)
plot_circuit(carry_layer_1)
cnot_sum_pivot = lambda r: Qpivot("*10", merge_within="111", mapping=cnot_sum(r))
plot_circuit(Qinit(6) + cnot_sum_pivot(1))
plot_circuit(Qinit(8) + cnot_sum_pivot(1))
cnot_sum_pivot = lambda r: Qpivot("*10", merge_within="111", mapping=cnot_sum(r))
plot_circuit(Qinit(6) + cnot_sum_pivot(1))
plot_circuit(Qinit(8) + cnot_sum_pivot(1))
carry_sum_layer = lambda r: (
Qmask("*111")
+ Qcycle(1, 3, 0,
boundary="open",
mapping=carry_sum(r),
edge_order=[-r],
)
+ Qunmask("previous")
)
plot_circuit(Qinit(10) + carry_sum_layer(1))
addition = carry_layer(1) + cnot_sum_pivot(1) + carry_sum_layer(1)
subtraction = carry_sum_layer(-1) + cnot_sum_pivot(-1) + carry_layer(-1)
plot_circuit(Qinit(11) + addition)
plot_circuit(Qinit(11) + subtraction)
plot_circuit(Qinit(13) + addition)
plot_circuit(Qinit(13) + subtraction)
addition = carry_layer(1) + cnot_sum_pivot(1) + carry_sum_layer(1)
subtraction = carry_sum_layer(-1) + cnot_sum_pivot(-1) + carry_layer(-1)
plot_circuit(Qinit(11) + addition)
plot_circuit(Qinit(11) + subtraction)
plot_circuit(Qinit(13) + addition)
plot_circuit(Qinit(13) + subtraction)
addition = carry_layer(1) + cnot_sum_pivot(1) + carry_sum_layer(1)
subtraction = carry_sum_layer(-1) + cnot_sum_pivot(-1) + carry_layer(-1)
plot_circuit(Qinit(11) + addition)
plot_circuit(Qinit(11) + subtraction)
plot_circuit(Qinit(13) + addition)
plot_circuit(Qinit(13) + subtraction)
addition = carry_layer(1) + cnot_sum_pivot(1) + carry_sum_layer(1)
subtraction = carry_sum_layer(-1) + cnot_sum_pivot(-1) + carry_layer(-1)
plot_circuit(Qinit(11) + addition)
plot_circuit(Qinit(11) + subtraction)
plot_circuit(Qinit(13) + addition)
plot_circuit(Qinit(13) + subtraction)
exp_mod_n = tuple()
for k in range(n):
exp_mod_n += (
Qpivot(mapping=ctrl_mult(a ** (2**k), N, n, ctrl=k, divide=False))
+ swap_bx
+ Qpivot(mapping=ctrl_mult(a ** (2**k), N, n, ctrl=k, divide=True))
)
hierq = Qinit(nq, tensors=tensors) + exp_mod_n
# QFT circuit
n = 4
qft = (
Qpivot(mapping=Qunitary("h()^0"))
+ Qpivot(
mapping=Qunitary("cp(x)^01"),
share_weights=False,
symbol_fn=lambda x, ns, ne: np.pi * 2 ** (-ne),
)
+ Qmask("1*")
) * n
qft_n = Qinit(n) + qft
circuit_qft = qft_n(backend="qiskit", barriers=False)
circuit_qft.draw("mpl")
def half_adder(bits, symbols=None, state=None):
b1, b2 = state[bits[0]], state[bits[1]]
xor = b1 ^ b2
carry = b1 and b2
state[bits[0]] = carry
state[bits[1]] = xor
return state
def or_top(bits, symbols=None, state=None):
b1, b2 = state[bits[0]], state[bits[1]]
state[bits[0]] = b1 or b2
return state
def half_adder(bits, symbols=None, state=None):
b1, b2 = state[bits[0]], state[bits[1]]
xor = b1 ^ b2
carry = b1 and b2
state[bits[0]] = carry
state[bits[1]] = xor
return state
def or_top(bits, symbols=None, state=None):
b1, b2 = state[bits[0]], state[bits[1]]
state[bits[0]] = b1 or b2
return state
# program
full_adder = (
Qinit(3)
+ Qcycle(mapping=half_adder, boundary="open")
+ Qpivot(global_pattern="1*", merge_within="11"
,mapping=or_top)
)
addition = (
Qinit(n)
+ Qpivot("*1", "11", mapping=half_adder)
+ Qcycle(step=2,
edge_order=[-1],
mapping=full_adder,
boundary="open")
)