def test_grover(): qc = mat_quantum_circuit([4, 2], divisions=[1, 1], name='Test grover', show_amp=True) # qc.special_encoding( {0:'(FF)', 1:'(FT)', 2:'(TF)', 3:'(TT)'}, 0) had4 = ops.gates('hadamard', 4) qc.add_instruct(had4, [0]) AND = ops.AND() AND.change_dims([4, 2]) qc.add_instruct(AND) # directions = { (1,): ops.gates('flip') } cond_flip = ops.gates('flip') qc.add_instruct(cond_flip, [1]) qc.add_instruct(AND) # qc.add_instruct(ops.one_shot_grover(),[0]) # qc.add_instruct(ops.one_shot_grover(),[0]) add4 = ops.arith([4], 0, 0) qc.add_instruct(add4, [0]) qc.run()
def test_idea2(): qc = quantum_circuit([3, 3, 2, 2, 2, 2], [2, 2, 2], 'Test idea 2', True) qc.special_encoding('null', 0, 1) qc.special_encoding('TF', 2, 3) #1 qc.instruct_notes('branch @ 0') qc.add_instruct(ops.branch(3), [0]) #2 qc.instruct_notes('|null> - |T> swap @ 1') swap = ops.swap(3, 0, 2) qc.add_instruct(swap, [1]) #3 qc.instruct_notes('Copy node info to ancillary memory') c32 = ops.copy32() apply_to = (0, 2), (1, 3) qc.add_instruct(ops.copy32(), *apply_to) #4 qc.instruct_notes('evaluate node @ val') qc.add_instruct(ops.SAME(), [2, 3, 4]) #5 qc.instruct_notes('copy val to continue') qc.add_instruct(ops.gates('cnot'), [4, 5]) #6 qc.instruct_notes('CONTINUE CONTROL: load other node') # double_swap = ops.gate_concat(ops.swap(3, 2, 1), ops.gates('not')) dirs5 = {(0, ): ops.gates('not')} ctrl5 = ops.create_control([2, 2], 0, 1, dirs5) qc.add_instruct(ctrl5, [5, 3]) #7 qc.instruct_notes('CONTINUE CONTROL: evaluate node') dirs6 = {(0, ): ops.SAME()} ctrl6 = ops.create_control([2, 2, 2, 2], 0, [1, 2, 3], dirs6) qc.add_instruct(ctrl6, [5, 2, 3, 4]) #8 qc.instruct_notes('Uncopy continue control') qc.add_instruct(ops.gates('cnot'), [4, 5]) #9 qc.instruct_notes('PREPARE MERGE: unevaluate') qc.add_instruct(ops.SAME(), [2, 3, 4]) # qc.instruct_notes('Move amplitudes up one node on the tree') # qc.add_instruct( swap, [1] ) # #9 # qc.instruct_notes('Unbranch @ 0') # qc.add_instruct( ops.branch(3), [0] ) qc.run() qc.index_aide()
def test_goto(): qc = mat_quantum_circuit([3, 3, 2, 2], [2, 2], 'Test goto', True) qc.special_encoding('null', 0, 1) qc.write_state('1100', '1200', '2100', '2210') direct1 = {(2, ): ops.gates('not')} tx = ops.create_control([3, 2], 0, 1, direct1) direct2 = {(1, ): tx} info_transfer = ops.create_control([3, 2, 2], 1, [0, 2], direct2) # qc.add_instruct(tx, [0,3]) qc.add_instruct(info_transfer, [1, 2, 3]) qc.run()
def test_control_ops(): qc = mat_quantum_circuit([2, 2], name='Test control operations', show_amp=True) qc.write_state('00', '10') # go1 = ops.goto_state(3, send=1) # go2 = ops.goto_state(3, send=2) # directions = { (0,) : go1, (1,) : go2 } # directions = { (1,1,1) : go1 } # ctl_go = ops.create_control([2,3], 0, 1, directions) # qc.add_instruct(ctl_go, [0,2]) qc.add_instruct(ops.gates('not'), [1]) directions = { (0, ): ops.gates('hadamard'), (1, ): ops.gates('hadamard', reverse=True) } ctrl = ops.create_control([2, 2], 1, 0, directions) qc.add_instruct(ctrl) qc.run()
def test_idea(): qc = quantum_circuit([3, 3, 2, 2, 2, 2, 2, 2], divisions=[2, 3, 3], name='Test idea', show_amp=False) qc.special_encoding('null', 0, 1) qc.special_encoding('TF', 2, 3, 4) b = ops.branch(3) qc.add_instruct(b, [0]) qc.add_instruct(b, [1]) c32 = ops.copy32(0, 1) n32 = ops.not32(0, 1) qc.add_instruct(c32, [0, 2]) qc.add_instruct(c32, [1, 4]) qc.add_instruct(n32, [0, 3]) fan = ops.fan_out(2, 0, 1) OR = ops.OR([0, 1], 2) AND = ops.AND([0, 1], 2) qc.add_instruct(fan, [2, 5]) qc.add_instruct(OR, [3, 4, 6]) qc.add_instruct(AND, [5, 6, 7]) # now everything is evaluated # reset q5 and q6, use as goto control qc.add_instruct(fan, [2, 5]) qc.add_instruct(OR, [3, 4, 6]) # target |.F> directions = {(1, ): ops.gates('not')} ctrl = ops.create_control([2, 3], [1], 0, directions) flip_branch = qc.add_instruct(ctrl, [1, 5, 7]) qc.run() qc.index_aide()