def qubit_type_to_gates( q: Qubit) -> List[Union[GateInfo, MeasureInfo]]: gates: List[Union[GateInfo, MeasureInfo]] = [ MeasureInfo( operator="MEASURE", qubit=q.id, target="_", fidelity=safely_get("fROs", q.id, DEFAULT_MEASURE_FIDELITY), duration=DEFAULT_MEASURE_DURATION, ), MeasureInfo( operator="MEASURE", qubit=q.id, target=None, fidelity=safely_get("fROs", q.id, DEFAULT_MEASURE_FIDELITY), duration=DEFAULT_MEASURE_DURATION, ), ] if q.type is None or "Xhalves" in q.type: gates += [ GateInfo( operator="RZ", parameters=["_"], arguments=[q.id], duration=PERFECT_DURATION, fidelity=PERFECT_FIDELITY, ), GateInfo( operator="RX", parameters=[0.0], arguments=[q.id], duration=DEFAULT_RX_DURATION, fidelity=PERFECT_FIDELITY, ), ] gates += [ GateInfo( operator="RX", parameters=[param], arguments=[q.id], duration=DEFAULT_RX_DURATION, fidelity=safely_get("f1QRBs", q.id, DEFAULT_RX_FIDELITY), ) for param in [np.pi, -np.pi, np.pi / 2, -np.pi / 2] ] if q.type is not None and "WILDCARD" in q.type: gates += [ GateInfo( operator="_", parameters="_", arguments=[q.id], duration=PERFECT_DURATION, fidelity=PERFECT_FIDELITY, ) ] return gates
def edge_type_to_gates(e): gates = [] if e is None or "CZ" in e.type: gates += [ GateInfo( operator="CZ", parameters=[], arguments=["_", "_"], duration=DEFAULT_CZ_DURATION, fidelity=safely_get("fCZs", tuple(e.targets), DEFAULT_CZ_FIDELITY), ) ] if e is not None and "ISWAP" in e.type: gates += [ GateInfo( operator="ISWAP", parameters=[], arguments=["_", "_"], duration=DEFAULT_ISWAP_DURATION, fidelity=safely_get("fISWAPs", tuple(e.targets), DEFAULT_ISWAP_FIDELITY), ) ] if e is not None and "CPHASE" in e.type: gates += [ GateInfo( operator="CPHASE", parameters=["theta"], arguments=["_", "_"], duration=DEFAULT_CPHASE_DURATION, fidelity=safely_get("fCPHASEs", tuple(e.targets), DEFAULT_CPHASE_FIDELITY), ) ] if e is not None and "XY" in e.type: gates += [ GateInfo( operator="XY", parameters=["theta"], arguments=["_", "_"], duration=DEFAULT_XY_DURATION, fidelity=safely_get("fXYs", tuple(e.targets), DEFAULT_XY_FIDELITY), ) ] if e is not None and "WILDCARD" in e.type: gates += [ GateInfo( operator="_", parameters="_", arguments=["_", "_"], duration=PERFECT_DURATION, fidelity=PERFECT_FIDELITY, ) ] return gates
def edge_type_to_gates(e: Edge) -> List[GateInfo]: gates: List[GateInfo] = [] if (e is None or isinstance(e.type, str) and "CZ" == e.type or isinstance(e.type, list) and "CZ" in e.type): gates += [ GateInfo( operator="CZ", parameters=[], arguments=["_", "_"], duration=DEFAULT_CZ_DURATION, fidelity=safely_get("fCZs", tuple(e.targets), DEFAULT_CZ_FIDELITY), ) ] if (e is None or isinstance(e.type, str) and "ISWAP" == e.type or isinstance(e.type, list) and "ISWAP" in e.type): gates += [ GateInfo( operator="ISWAP", parameters=[], arguments=["_", "_"], duration=DEFAULT_ISWAP_DURATION, fidelity=safely_get("fISWAPs", tuple(e.targets), DEFAULT_ISWAP_FIDELITY), ) ] if (e is None or isinstance(e.type, str) and "CPHASE" == e.type or isinstance(e.type, list) and "CPHASE" in e.type): gates += [ GateInfo( operator="CPHASE", parameters=["theta"], arguments=["_", "_"], duration=DEFAULT_CPHASE_DURATION, fidelity=safely_get("fCPHASEs", tuple(e.targets), DEFAULT_CPHASE_FIDELITY), ) ] if (e is None or isinstance(e.type, str) and "XY" == e.type or isinstance(e.type, list) and "XY" in e.type): gates += [ GateInfo( operator="XY", parameters=["theta"], arguments=["_", "_"], duration=DEFAULT_XY_DURATION, fidelity=safely_get("fXYs", tuple(e.targets), DEFAULT_XY_FIDELITY), ) ] if (e is None or isinstance(e.type, str) and "WILDCARD" == e.type or isinstance(e.type, list) and "WILDCARD" in e.type): gates += [ GateInfo( operator="_", parameters="_", arguments=["_", "_"], duration=PERFECT_DURATION, fidelity=PERFECT_FIDELITY, ) ] return gates
def get_isa(self, oneq_type=None, twoq_type=None) -> ISA: """ Construct an ISA suitable for targeting by compilation. This will raise an exception if the requested ISA is not supported by the device. """ if oneq_type is not None or twoq_type is not None: raise ValueError( "oneq_type and twoq_type are both fatally deprecated. If you want to " "make an ISA with custom gate types, you'll have to do it by hand." ) qubits = [ Qubit(id=q.id, type=None, dead=q.dead, gates=[ MeasureInfo(operator="MEASURE", qubit=q.id, target="_", fidelity=self.specs.fROs()[q.id] or DEFAULT_MEASURE_FIDELITY, duration=DEFAULT_MEASURE_DURATION), MeasureInfo(operator="MEASURE", qubit=q.id, target=None, fidelity=self.specs.fROs()[q.id] or DEFAULT_MEASURE_FIDELITY, duration=DEFAULT_MEASURE_DURATION), GateInfo(operator="RZ", parameters=["_"], arguments=[q.id], duration=PERFECT_DURATION, fidelity=PERFECT_FIDELITY), GateInfo(operator="RX", parameters=[0.0], arguments=[q.id], duration=DEFAULT_RX_DURATION, fidelity=PERFECT_FIDELITY) ] + [ GateInfo(operator="RX", parameters=[param], arguments=[q.id], duration=DEFAULT_RX_DURATION, fidelity=self.specs.f1QRBs()[q.id] or DEFAULT_RX_FIDELITY) for param in [np.pi, -np.pi, np.pi / 2, -np.pi / 2] ]) for q in self._isa.qubits ] edges = [ Edge(targets=e.targets, type=None, dead=e.dead, gates=[ GateInfo(operator="CZ", parameters=[], arguments=["_", "_"], duration=DEFAULT_CZ_DURATION, fidelity=self.specs.fCZs()[tuple(e.targets)] or DEFAULT_CZ_FIDELITY) ]) for e in self._isa.edges ] return ISA(qubits, edges)