def test_isa_from_graph_order(): # since node 16 appears first, even though we ask for the edge (15,16) the networkx internal # representation will have it as (16,15) fc = nx.from_edgelist([(16, 17), (15, 16)]) isa = isa_from_graph(fc) isad = isa.to_dict() for k in isad['2Q']: q1, q2 = k.split('-') assert q1 < q2
def test_isa_from_graph_cphase(): fc = nx.complete_graph(3) isa = isa_from_graph(fc, twoq_type='CPHASE') isad = isa.to_dict() assert set(isad.keys()) == {'1Q', '2Q'} assert sorted(int(q) for q in isad['1Q'].keys()) == list(range(3)) for v in isad['1Q'].values(): assert v == {} assert sorted(isad['2Q']) == ['0-1', '0-2', '1-2'] for v in isad['2Q'].values(): assert v == {'type': 'CPHASE'}
def test_isa_from_graph_cphase(): fc = nx.complete_graph(3) isa = isa_from_graph(fc, twoq_type="CPHASE") isad = isa.to_dict() assert set(isad.keys()) == {"1Q", "2Q"} assert sorted(int(q) for q in isad["1Q"].keys()) == list(range(3)) for v in isad["1Q"].values(): assert v == {} assert sorted(isad["2Q"]) == ["0-1", "0-2", "1-2"] for v in isad["2Q"].values(): assert v == {"type": "CPHASE"}
def run_quilc_pass(circ: Circuit, backend: str): try: RebaseQuil().apply(circ) p_circ = tk_to_pyquil(circ) if backend == _BACKEND_IBM: devgraph = nx.from_edgelist(ibm_coupling) twoq_type = ['CZ'] twoq_set = {OpType.CZ} elif backend == _BACKEND_RIGETTI: devgraph = nx.from_edgelist(rigetti_coupling) twoq_type = ['CZ', 'XY'] twoq_set = {OpType.CZ, OpType.ISWAP} elif backend == _BACKEND_GOOGLE: devgraph = nx.from_edgelist(google_coupling) twoq_type = ['CZ'] twoq_set = {OpType.CZ} elif backend == _BACKEND_FULL: devgraph = nx.complete_graph(circ.n_qubits) twoq_type = ['CZ', 'XY'] twoq_set = {OpType.CZ, OpType.ISWAP} isa = isa_from_graph(devgraph, twoq_type=twoq_type) device = Device_("dev", {"isa": isa.to_dict()}) device._isa = isa qcompiler = QVMCompiler(PyquilConfig().quilc_url, device, timeout=600) start_time = time.time() compiled_pr = qcompiler.quil_to_native_quil(p_circ) time_elapsed = time.time() - start_time print(time_elapsed) circ2 = pyquil_to_tk(compiled_pr) return [ circ2.n_gates, circ2.depth(), sum(circ2.n_gates_of_type(op) for op in twoq_set), circ2.depth_by_type(twoq_set), time_elapsed ] except Exception as e: print(e) print("quilc error") return [nan, nan, nan, nan, nan]