Skip to content

Commit 30fc63a

Browse files
committed
making Routine's pydantic dataclasses.
1 parent d6242b4 commit 30fc63a

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/bloqade/ir/routine/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from bloqade.builder.base import Builder
66
from bloqade.ir.routine.params import Params
77

8-
9-
from dataclasses import dataclass
8+
from pydantic import ConfigDict
9+
from pydantic.dataclasses import dataclass
1010
from typing import TYPE_CHECKING, Union
1111

1212
if TYPE_CHECKING:
@@ -29,7 +29,10 @@ def parse(self: "RoutineBase") -> "Routine":
2929
return self
3030

3131

32-
@dataclass(frozen=True)
32+
__pydantic_dataclass_config__ = ConfigDict(arbitrary_types_allowed=True)
33+
34+
35+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
3336
class RoutineBase(RoutineParse):
3437
source: Builder
3538
circuit: AnalogCircuit
@@ -43,7 +46,7 @@ def __str__(self):
4346
return out
4447

4548

46-
@dataclass(frozen=True)
49+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
4750
class Routine(RoutineBase):
4851
"""Result of parsing a completed Builder string."""
4952

src/bloqade/ir/routine/bloqade.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from collections import OrderedDict
2-
from bloqade.ir.routine.base import RoutineBase
2+
from bloqade.ir.routine.base import RoutineBase, __pydantic_dataclass_config__
33
from bloqade.builder.typing import LiteralType
44
from bloqade.task.batch import LocalBatch
55
from beartype import beartype
66
from beartype.typing import Optional, Tuple
77
from dataclasses import dataclass
88

99

10-
@dataclass(frozen=True)
10+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
1111
class BloqadeServiceOptions(RoutineBase):
1212
def python(self):
1313
return BloqadePythonRoutine(self.source, self.circuit, self.params)
1414

1515

16-
@dataclass(frozen=True)
16+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
1717
class BloqadePythonRoutine(RoutineBase):
1818
def _compile(
1919
self,

src/bloqade/ir/routine/braket.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from beartype.typing import Optional, Tuple
55
from bloqade.builder.typing import LiteralType
66

7-
from bloqade.ir.routine.base import RoutineBase
7+
from bloqade.ir.routine.base import RoutineBase, __pydantic_dataclass_config__
88
from bloqade.submission.braket import BraketBackend
99
from bloqade.task.batch import LocalBatch, RemoteBatch
1010
from bloqade.task.braket_simulator import BraketEmulatorTask
1111
from bloqade.task.braket import BraketTask
1212

1313

14-
@dataclass(frozen=True)
14+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
1515
class BraketServiceOptions(RoutineBase):
1616
def aquila(self) -> "BraketHardwareRoutine":
1717
backend = BraketBackend(
@@ -23,7 +23,7 @@ def local_emulator(self):
2323
return BraketLocalEmulatorRoutine(self.source, self.circuit, self.params)
2424

2525

26-
@dataclass(frozen=True)
26+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
2727
class BraketHardwareRoutine(RoutineBase):
2828
backend: BraketBackend
2929

@@ -163,7 +163,7 @@ def __call__(
163163
return self.run(shots, args, name, shuffle, **kwargs)
164164

165165

166-
@dataclass(frozen=True)
166+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
167167
class BraketLocalEmulatorRoutine(RoutineBase):
168168
def _compile(
169169
self, shots: int, args: Tuple[LiteralType, ...] = (), name: Optional[str] = None

src/bloqade/ir/routine/quera.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44

55
from bloqade.builder.typing import LiteralType
6-
from bloqade.ir.routine.base import RoutineBase
6+
from bloqade.ir.routine.base import RoutineBase, __pydantic_dataclass_config__
77
from bloqade.submission.quera import QuEraBackend
88
from bloqade.submission.mock import MockBackend
99
from bloqade.submission.quera_api_client.load_config import load_config
@@ -14,7 +14,7 @@
1414
from beartype import beartype
1515

1616

17-
@dataclass(frozen=True)
17+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
1818
class QuEraServiceOptions(RoutineBase):
1919
@beartype
2020
def device(self, config_file: Optional[str], **api_config):
@@ -40,7 +40,7 @@ def mock(self, state_file: str = ".mock_state.txt") -> "QuEraHardwareRoutine":
4040
return QuEraHardwareRoutine(self.source, self.circuit, self.params, backend)
4141

4242

43-
@dataclass(frozen=True)
43+
@dataclass(frozen=True, config=__pydantic_dataclass_config__)
4444
class QuEraHardwareRoutine(RoutineBase):
4545
backend: Union[QuEraBackend, MockBackend]
4646

0 commit comments

Comments
 (0)