11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
- from typing import List , cast , Optional , Union , Dict , Any
14
+ from typing import List , Optional , Union , Dict , Any
15
15
import functools
16
16
from math import sqrt
17
- import httpx
17
+ import json
18
18
import numpy as np
19
19
import networkx as nx
20
20
import cirq
21
21
from pyquil .quantum_processor import QCSQuantumProcessor
22
- from qcs_api_client .models import InstructionSetArchitecture
23
- from qcs_api_client .operations .sync import get_instruction_set_architecture
24
- from cirq_rigetti ._qcs_api_client_decorator import _provide_default_client
22
+ from qcs_sdk .client import QCSClient
23
+ from qcs_sdk .qpu .isa import get_instruction_set_architecture , InstructionSetArchitecture , Family
25
24
26
25
27
26
class UnsupportedQubit (ValueError ):
@@ -50,6 +49,8 @@ class UnsupportedRigettiQCSQuantumProcessor(ValueError):
50
49
class RigettiQCSAspenDevice (cirq .devices .Device ):
51
50
"""A cirq.Qid supporting Rigetti QCS Aspen device topology."""
52
51
52
+ isa : InstructionSetArchitecture
53
+
53
54
def __init__ (self , isa : Union [InstructionSetArchitecture , Dict [str , Any ]]) -> None :
54
55
"""Initializes a RigettiQCSAspenDevice with its Rigetti QCS `InstructionSetArchitecture`.
55
56
@@ -63,9 +64,9 @@ def __init__(self, isa: Union[InstructionSetArchitecture, Dict[str, Any]]) -> No
63
64
if isinstance (isa , InstructionSetArchitecture ):
64
65
self .isa = isa
65
66
else :
66
- self .isa = InstructionSetArchitecture .from_dict ( isa )
67
+ self .isa = InstructionSetArchitecture .from_raw ( json . dumps ( isa ) )
67
68
68
- if self .isa .architecture .family . lower () != 'aspen' :
69
+ if self .isa .architecture .family != Family . Aspen :
69
70
raise UnsupportedRigettiQCSQuantumProcessor (
70
71
'this integration currently only supports Aspen devices, '
71
72
f'but client provided a { self .isa .architecture .family } device'
@@ -224,23 +225,22 @@ def __repr__(self):
224
225
return f'cirq_rigetti.RigettiQCSAspenDevice(isa={ self .isa !r} )'
225
226
226
227
def _json_dict_ (self ):
227
- return {'isa' : self .isa .to_dict ( )}
228
+ return {'isa' : json . loads ( self .isa .json () )}
228
229
229
230
@classmethod
230
231
def _from_json_dict_ (cls , isa , ** kwargs ):
231
- return cls (isa = InstructionSetArchitecture .from_dict ( isa ))
232
+ return cls (isa = InstructionSetArchitecture .from_raw ( json . dumps ( isa ) ))
232
233
233
234
234
- @_provide_default_client # pragma: no cover
235
235
def get_rigetti_qcs_aspen_device (
236
- quantum_processor_id : str , client : Optional [httpx . Client ]
236
+ quantum_processor_id : str , client : Optional [QCSClient ] = None
237
237
) -> RigettiQCSAspenDevice :
238
238
"""Retrieves a `qcs_api_client.models.InstructionSetArchitecture` from the Rigetti
239
239
QCS API and uses it to initialize a RigettiQCSAspenDevice.
240
240
241
241
Args:
242
242
quantum_processor_id: The identifier of the Rigetti QCS quantum processor.
243
- client: Optional; A `httpx.Client ` initialized with Rigetti QCS credentials
243
+ client: Optional; A `QCSClient ` initialized with Rigetti QCS credentials
244
244
and configuration. If not provided, `qcs_api_client` will initialize a
245
245
configured client based on configured values in the current user's
246
246
`~/.qcs` directory or default values.
@@ -250,12 +250,7 @@ def get_rigetti_qcs_aspen_device(
250
250
set and architecture.
251
251
252
252
"""
253
- isa = cast (
254
- InstructionSetArchitecture ,
255
- get_instruction_set_architecture (
256
- client = client , quantum_processor_id = quantum_processor_id
257
- ).parsed ,
258
- )
253
+ isa = get_instruction_set_architecture (client = client , quantum_processor_id = quantum_processor_id )
259
254
return RigettiQCSAspenDevice (isa = isa )
260
255
261
256
0 commit comments