Skip to content

Commit

Permalink
Merge pull request #1101 from qiboteam/envelope_hash
Browse files Browse the repository at this point in the history
Adding hash to Custom
  • Loading branch information
andrea-pasquale authored Nov 15, 2024
2 parents ed8b3cc + 5550a10 commit 5836076
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/qibolab/_core/pulses/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ def __eq__(self, other) -> bool:
"""
return eq(self, other)

def __hash__(self):
return hash(np.concatenate([self.i_, self.q_]).tobytes())


Envelope = Annotated[
Union[
Expand Down
11 changes: 11 additions & 0 deletions tests/pulses/test_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

from qibolab._core.pulses import (
Custom,
Drag,
ECap,
Gaussian,
Expand Down Expand Up @@ -216,3 +217,13 @@ def test_eq():
shape3 = ECap(alpha=5)
assert shape1 == shape2
assert not shape1 == shape3


def test_hash_custom():
"""Testing __hash__ for Custom."""

shape1 = Custom(i_=np.ones(10), q_=np.ones(10))
shape2 = Custom(i_=np.ones(10), q_=np.ones(10))
shape3 = Custom(i_=np.ones(10), q_=np.zeros(10))
assert hash(shape1) == hash(shape2)
assert hash(shape1) != hash(shape3)

0 comments on commit 5836076

Please sign in to comment.