Skip to content

Commit

Permalink
fix rpcq deprecation version
Browse files Browse the repository at this point in the history
  • Loading branch information
MarquessV committed Feb 21, 2024
1 parent e0788e6 commit f7f5e3e
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions pyquil/external/rpcq.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
from typing import Dict, List, Union, Optional, Any, Literal
from typing import Dict, List, Union, Optional, Literal

from deprecated.sphinx import deprecated
from rpcq.messages import TargetDevice as TargetQuantumProcessor
from dataclasses import dataclass, field

JsonValue = Union[type(None), bool, int, float, str, List["JsonValue"], Dict[str, "JsonValue"]]


@dataclass
class Operator:
operator: Optional[str] = None
Expand All @@ -27,7 +28,7 @@ def _dict(self) -> Dict[str, JsonValue]:
)

@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def dict(self):
Expand All @@ -39,7 +40,7 @@ def _parse_obj(cls, dictionary: Dict):

@classmethod
@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def parse_obj(cls, dictionary: Dict):
Expand Down Expand Up @@ -84,7 +85,7 @@ def _parse_obj(cls, dictionary: Dict) -> "MeasureInfo":

@classmethod
@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def parse_obj(cls, dictionary: Dict):
Expand All @@ -108,7 +109,7 @@ def _dict(self) -> Dict[str, JsonValue]:
)

@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def dict(self):
Expand All @@ -126,7 +127,7 @@ def _parse_obj(cls, dictionary: dict) -> "GateInfo":

@classmethod
@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def parse_obj(cls, dictionary: Dict):
Expand All @@ -149,16 +150,13 @@ class Qubit:
gates: List[Union[GateInfo, MeasureInfo]] = field(default_factory=list)

def _dict(self) -> Dict[str, JsonValue]:
encoding = dict(
id=self.id,
gates=[g._dict() for g in self.gates]
)
encoding = dict(id=self.id, gates=[g._dict() for g in self.gates])
if self.dead:
encoding["dead"] = self.dead
return encoding

@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def dict(self):
Expand All @@ -174,7 +172,7 @@ def _parse_obj(cls, dictionary: Dict) -> "Qubit":

@classmethod
@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def parse_obj(cls, dictionary: Dict):
Expand All @@ -188,16 +186,13 @@ class Edge:
gates: List[GateInfo] = field(default_factory=list)

def _dict(self) -> Dict[str, JsonValue]:
encoding = dict(
ids=self.ids,
gates=[g._dict() for g in self.gates]
)
encoding = dict(ids=self.ids, gates=[g._dict() for g in self.gates])
if self.dead:
encoding["dead"] = self.dead
return encoding

@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def dict(self):
Expand All @@ -208,12 +203,12 @@ def _parse_obj(cls, dictionary: dict) -> "Edge":
return Edge(
ids=dictionary["ids"],
dead=bool(dictionary.get("dead")),
gates=[GateInfo._parse_obj(g) for g in dictionary.get("gates", [])]
gates=[GateInfo._parse_obj(g) for g in dictionary.get("gates", [])],
)

@classmethod
@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def parse_obj(cls, dictionary: Dict):
Expand All @@ -228,11 +223,11 @@ class CompilerISA:
def _dict(self) -> Dict[str, JsonValue]:
return {
"1Q": {k: q._dict() for k, q in self.qubits.items()},
"2Q": {k: e._dict() for k, e in self.edges.items()}
"2Q": {k: e._dict() for k, e in self.edges.items()},
}

@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def dict(self):
Expand All @@ -249,15 +244,15 @@ def _parse_obj(cls, dictionary: Dict):

@classmethod
@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def parse_obj(cls, dictionary: Dict):
return cls._parse_obj(dictionary)

@classmethod
@deprecated(
version="4.7",
version="4.6.2",
reason="No longer requires serialization of RPCQ objects and is dropping Pydantic as a dependency.", # noqa: E501
)
def parse_file(cls, filename: str):
Expand All @@ -266,7 +261,6 @@ def parse_file(cls, filename: str):
return cls._parse_obj(json_dict)



def add_qubit(quantum_processor: CompilerISA, node_id: int) -> Qubit:
if node_id not in quantum_processor.qubits:
quantum_processor.qubits[str(node_id)] = Qubit(id=node_id)
Expand Down

0 comments on commit f7f5e3e

Please sign in to comment.