Skip to content

Commit

Permalink
Added unit test based off pre-existing one with new Hamiltonian API
Browse files Browse the repository at this point in the history
  • Loading branch information
johnzl-777 committed May 8, 2024
1 parent 3e4ff4b commit 0ea6106
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/bloqade/ir/routine/bloqade.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def python(self):
return BloqadePythonRoutine(self.source, self.circuit, self.params)


def cast_to_float(x):
if isinstance(x, abc.Sequence):
return [float(i) for i in x]
else:
return float(x)


@dataclasses.dataclass(frozen=True)
class TaskData:
"""Data class to hold the program ir and metadata for a given set of parameters"""
Expand All @@ -41,7 +48,7 @@ class TaskData:
@property
def metadata(self) -> NamedTuple:
MetaData = namedtuple("MetaData", self.metadata_dict.keys())
return MetaData(**{k: float(v) for k, v in self.metadata_dict.items()})
return MetaData(**{k: cast_to_float(v) for k, v in self.metadata_dict.items()})


@dataclasses.dataclass(frozen=True)
Expand Down Expand Up @@ -94,7 +101,7 @@ def run_task(self, emulator_ir, metadata_dict):

MetaData = namedtuple("MetaData", metadata_dict.keys())
metadata = MetaData(
**{k: self.cast_to_float(v) for k, v in metadata_dict.items()}
**{k: cast_to_float(v) for k, v in metadata_dict.items()}
)

zero_state = hamiltonian.space.zero_state(np.complex128)
Expand All @@ -107,12 +114,6 @@ def run_task(self, emulator_ir, metadata_dict):
wrapped_register, metadata, hamiltonian, *self.callback_args
)

def cast_to_float(self, x):
if isinstance(x, abc.Sequence):
return [float(i) for i in x]
else:
return float(x)

def _generate_ir(
self, args, blockade_radius, waveform_runtime
) -> Iterator[TaskData]:
Expand Down

0 comments on commit 0ea6106

Please sign in to comment.