Skip to content

Commit

Permalink
fix: Sort input parameters when doing testing equality of two PulseSe…
Browse files Browse the repository at this point in the history
…quences (#874)

* sort input parameters when doing testing equality of two PulseSequences

* fix docstrings
  • Loading branch information
jcjaskula-aws authored Feb 13, 2024
1 parent d09d3a4 commit 8cc8b3b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/braket/pulse/pulse_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,24 @@ def make_bound_pulse_sequence(self, param_values: dict[str, float]) -> PulseSequ

return new_pulse_sequence

def to_ir(self) -> str:
def to_ir(self, sort_input_parameters: bool = False) -> str:
"""Converts this OpenPulse problem into IR representation.
Args:
sort_input_parameters (bool): whether input parameters should be printed
in a sorted order. Defaults to False.
Returns:
str: a str representing the OpenPulse program encoding the PulseSequence.
"""
program = deepcopy(self._program)
program.autodeclare(encal=False)
for param in self.parameters:
parameters = (
sorted(self.parameters, key=lambda p: p.name, reverse=True)
if sort_input_parameters
else self.parameters
)
for param in parameters:
program.declare(param._to_oqpy_expression(), to_beginning=True)

if self._capture_v0_count:
Expand Down Expand Up @@ -420,10 +429,11 @@ def __call__(self, arg: Any | None = None, **kwargs) -> PulseSequence:
return self.make_bound_pulse_sequence(param_values)

def __eq__(self, other):
sort_input_parameters = True
return (
isinstance(other, PulseSequence)
and self.parameters == other.parameters
and self.to_ir() == other.to_ir()
and self.to_ir(sort_input_parameters) == other.to_ir(sort_input_parameters)
)


Expand Down

0 comments on commit 8cc8b3b

Please sign in to comment.