def test_to_json(): q = ThreeDQubit(1.3, 1, 1) d = q._json_dict_() assert d == {'x': 1.3, 'y': 1, 'z': 1} q = TwoDQubit(1.3, 1) d = q._json_dict_() assert d == {'x': 1.3, 'y': 1}
def test_distance_3d(): with pytest.raises(TypeError): _ = ThreeDQubit(0, 0, 0).distance(cirq.GridQubit(0, 0)) for x in np.arange(-2, 3): for y in np.arange(-2, 3): for z in np.arange(-2, 3): assert ThreeDQubit(0, 0, 0).distance(ThreeDQubit( x, y, z)) == np.sqrt(x**2 + y**2 + z**2)
def test_to_json(): q = ThreeDQubit(1.3, 1, 1) d = q._json_dict_() assert d == { 'cirq_type': 'ThreeDQubit', 'x': 1.3, 'y': 1, 'z': 1, } q = TwoDQubit(1.3, 1) d = q._json_dict_() assert d == { 'cirq_type': 'TwoDQubit', 'x': 1.3, 'y': 1, }
def test_qid_pairs(): dev = PasqalVirtualDevice( 1, qubits=[ ThreeDQubit(0, 0, 0), ThreeDQubit(1, 0, 0), ThreeDQubit(0, 1, 0), ThreeDQubit(1, 1, 0), ThreeDQubit(1, 1, 1), ], ) assert len(dev.qid_pairs()) == 5 dev1 = PasqalVirtualDevice( 5, qubits=[ TwoDQubit(0, 0), TwoDQubit(3, 2), TwoDQubit(3, 4), TwoDQubit(3, 6), ], ) assert len(dev1.qid_pairs()) == 5
def test_qid_pairs_deprecated(): dev = PasqalVirtualDevice( 1, qubits=[ ThreeDQubit(0, 0, 0), ThreeDQubit(1, 0, 0), ThreeDQubit(0, 1, 0), ThreeDQubit(1, 1, 0), ThreeDQubit(1, 1, 1), ], ) with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=2): assert len(dev.qid_pairs()) == 5 dev1 = PasqalVirtualDevice( 5, qubits=[ TwoDQubit(0, 0), TwoDQubit(3, 2), TwoDQubit(3, 4), TwoDQubit(3, 6), ], ) assert len(dev1.qid_pairs()) == 5
def _my_manhattan_distance( qubit1: ThreeDQubit, qubit2: ThreeDQubit) -> int: # mirrors ccr._manhattan_distance() return abs(qubit1.distance(qubit2))
def main(): circuit = cirq.Circuit() """ASSUMES AN EXISTING FILE OF THE NAME cirq_test_out.txt !!!!!!""" f = open("cirq_test_out.txt", "a") exTestMultiply(circuit, 11, 12) """choice = int(input("1. Add two numbers\n2. Multiply two numbers\n3. Multiply the first n numbers together")) if(choice == 1): testAdd(circuit) if(choice == 2): testMultiply(circuit) if(choice == 3): exampleMultiply()""" simulator = cirq.Simulator() result = simulator.run(circuit) #print(circuit) #f.write(str(circuit)) #print(result) circdep = 0 for moment in circuit: circdep += 1 #print(circdep) #print("Now running tests: ") if (int(sys.argv[1]) == 3): width = int(sys.argv[2]) height = int(sys.argv[3]) depth = int(sys.argv[4]) p_qubits = [ ThreeDQubit(row, col, lay) for row in range(width) for col in range(height) for lay in range(depth) ] device_graph = nx.Graph( pair for pair in itertools.combinations(p_qubits, 2) if _my_manhattan_distance(*pair) == 1) if (int(sys.argv[1]) == 2): device_graph = ccr.get_grid_device_graph(int(sys.argv[2]), int(sys.argv[3])) sn = ccr.greedy.route_circuit_greedily( circuit, device_graph, max_search_radius=3, random_state=1) # This random seed is the reason for variation #print(str(sn)) swapcount = 0 swapdepth = 0 for moment in sn.circuit: temp = swapcount for op in moment: if len(op.qubits) == 2: #print(op.gate) if op.gate == cirq.contrib.acquaintance.SwapPermutationGate(): swapcount += 1 if temp != swapcount: swapdepth += 1 if (int(sys.argv[1]) == 2): outputdimdata = [sys.argv[2], " by ", sys.argv[3], "\n"] if (int(sys.argv[1]) == 3): outputdimdata = [ sys.argv[2], " by ", sys.argv[3], " by ", sys.argv[4], "\n" ] testoutput = [ "SWAP count: ", str(swapcount), "\nSWAP depth: ", str(swapdepth), "\n" ] f.writelines(outputdimdata) f.writelines(testoutput) """for moment: for gate: is swap?""" f.close()
def test_parallelep_3d(): assert ThreeDQubit.parallelep(1, 2, 2, x0=5, y0=6, z0=7) == [ ThreeDQubit(5, 6, 7), ThreeDQubit(5, 7, 7), ThreeDQubit(5, 6, 8), ThreeDQubit(5, 7, 8), ] assert ThreeDQubit.parallelep(2, 2, 2) == [ ThreeDQubit(0, 0, 0), ThreeDQubit(1, 0, 0), ThreeDQubit(0, 1, 0), ThreeDQubit(1, 1, 0), ThreeDQubit(0, 0, 1), ThreeDQubit(1, 0, 1), ThreeDQubit(0, 1, 1), ThreeDQubit(1, 1, 1), ]
def test_cube_3d(): assert ThreeDQubit.cube(2, x0=1, y0=1, z0=1) == [ ThreeDQubit(1, 1, 1), ThreeDQubit(2, 1, 1), ThreeDQubit(1, 2, 1), ThreeDQubit(2, 2, 1), ThreeDQubit(1, 1, 2), ThreeDQubit(2, 1, 2), ThreeDQubit(1, 2, 2), ThreeDQubit(2, 2, 2), ] assert ThreeDQubit.cube(2) == [ ThreeDQubit(0, 0, 0), ThreeDQubit(1, 0, 0), ThreeDQubit(0, 1, 0), ThreeDQubit(1, 1, 0), ThreeDQubit(0, 0, 1), ThreeDQubit(1, 0, 1), ThreeDQubit(0, 1, 1), ThreeDQubit(1, 1, 1), ]
def test_grid_qubit_eq_3d(): eq = cirq.testing.EqualsTester() eq.make_equality_group(lambda: ThreeDQubit(0, 0, 0)) eq.make_equality_group(lambda: ThreeDQubit(1, 0, 0)) eq.make_equality_group(lambda: ThreeDQubit(0, 1, 0)) eq.make_equality_group(lambda: ThreeDQubit(50, 25, 25))
def test_pasqal_qubit_ordering_3d(): assert ThreeDQubit(0, 0, 1) >= ThreeDQubit(1, 0, 0) assert ThreeDQubit(0, 0, 1) >= ThreeDQubit(0, 1, 0) assert ThreeDQubit(0, 1, 0) >= ThreeDQubit(1, 0, 0) for i in range(8): v = [int(x) for x in bin(i)[2:].zfill(3)] assert ThreeDQubit(0, 0, 0) <= ThreeDQubit(v[0], v[1], v[2]) assert ThreeDQubit(1, 1, 1) >= ThreeDQubit(v[0], v[1], v[2]) if i >= 1: assert ThreeDQubit(0, 0, 0) < ThreeDQubit(v[0], v[1], v[2]) if i < 7: assert ThreeDQubit(1, 1, 1) > ThreeDQubit(v[0], v[1], v[2])
def test_comparison_key_3d(): assert ThreeDQubit(3, 4, 5)._comparison_key() == (5, 4, 3) coords = (np.cos(np.pi / 2), np.sin(np.pi / 2), 0) assert ThreeDQubit(*coords) == ThreeDQubit(0, 1, 0)
def test_pasqal_qubit_init_3d(): q = ThreeDQubit(3, 4, 5) assert q.x == 3 assert q.y == 4 assert q.z == 5
def test_str(): assert str(ThreeDQubit(4, -25, 109)) == '(4, -25, 109)' assert str(TwoDQubit(4, -25)) == '(4, -25)'
def test_repr(): assert repr(ThreeDQubit(4, -25, 109)) == 'pasqal.ThreeDQubit(4, -25, 109)' assert repr(TwoDQubit(4, -25)) == 'pasqal.TwoDQubit(4, -25)'