def test_rigetti_qcs_aspen_device_family_validation( qcs_aspen8_isa: InstructionSetArchitecture): """test RigettiQCSAspenDevice validates architecture family on initialization""" non_aspen_isa = InstructionSetArchitecture.from_dict( qcs_aspen8_isa.to_dict()) non_aspen_isa.architecture.family = "not-aspen" # type: ignore with pytest.raises(UnsupportedRigettiQCSQuantumProcessor): RigettiQCSAspenDevice(isa=non_aspen_isa)
def test_rigetti_qcs_aspen_device_non_existent_qubit( qcs_aspen8_isa: InstructionSetArchitecture): """test RigettiQCSAspenDevice throws error when qubit does not exist on device""" # test device may only be initialized with Aspen ISA. device_with_limited_nodes = RigettiQCSAspenDevice( isa=InstructionSetArchitecture.from_dict(qcs_aspen8_isa.to_dict())) device_with_limited_nodes.isa.architecture.nodes = [Node(node_id=10)] with pytest.raises(UnsupportedQubit): device_with_limited_nodes.validate_qubit(cirq.GridQubit(0, 0))
def qcs_aspen8_isa() -> InstructionSetArchitecture: """ Read the Aspen-8 QCS InstructionSetArchitecture from file and load it into the ``InstructionSetArchitecture`` QCS API client model. """ with open(os.path.join(TEST_DATA_DIR, "qcs-isa-Aspen-8.json")) as f: return InstructionSetArchitecture.from_dict(json.load(f))
def __init__( self, isa: Union[InstructionSetArchitecture, Dict[str, Any]]) -> None: """Initializes a RigettiQCSAspenDevice with its Rigetti QCS `InstructionSetArchitecture`. Args: isa: The `InstructionSetArchitecture` retrieved from the QCS api. Raises: UnsupportedRigettiQCSQuantumProcessor: If the isa does not define an Aspen device. """ if isinstance(isa, InstructionSetArchitecture): self.isa = isa else: self.isa = InstructionSetArchitecture.from_dict(isa) if self.isa.architecture.family.lower() != 'aspen': raise UnsupportedRigettiQCSQuantumProcessor( 'this integration currently only supports Aspen devices, ' f'but client provided a {self.isa.architecture.family} device') self.quantum_processor = QCSQuantumProcessor( quantum_processor_id=self.isa.name, isa=self.isa)
def _from_json_dict_(cls, isa, **kwargs): return cls(isa=InstructionSetArchitecture.from_dict(isa), )
def qcs_aspen8_isa() -> InstructionSetArchitecture: with open(fixture_path / 'QCS-Aspen-8-ISA.json', 'r') as f: return InstructionSetArchitecture.from_dict(json.load(f))