Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash test #64

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
251cfe7
Added __hash__() method to models.py
SkandanC Mar 15, 2022
5f2e6fc
Add __hash__() function
SkandanC Mar 15, 2022
5788793
Create modelhashtest.py
SkandanC Mar 15, 2022
6769bde
Added hash method to models.py
SkandanC Mar 21, 2022
32d0bb3
Deleted test files
SkandanC Mar 21, 2022
12c2f7d
Add __hash__() methods for siepic models
SkandanC Mar 23, 2022
c7dc8f2
Add __hash__() methods to sipann models
SkandanC Mar 23, 2022
5523b79
Add _hash__() method to models.py
SkandanC Mar 23, 2022
ae857f2
Add hash tests
SkandanC Mar 24, 2022
910f0da
Update __hash__() docstring
SkandanC Mar 24, 2022
11efb64
Add base tests
SkandanC Mar 24, 2022
74d289d
Update siepichashtest.py
SkandanC Mar 28, 2022
1abc4f8
Update hash test files
SkandanC Apr 14, 2022
df5b128
Linting
SkandanC Apr 14, 2022
00ec666
Linting
SkandanC Apr 14, 2022
434ec55
Remove unused import
SkandanC Apr 14, 2022
6186a5e
Add SiPANN to tox deps
SkandanC Apr 14, 2022
ff07d54
Update test_hash.py
SkandanC Apr 14, 2022
721f295
Update assert statements
SkandanC Apr 15, 2022
4446369
Add SiPANN and numpy version to deps
SkandanC Apr 15, 2022
b68326c
Update test_hash.py
SkandanC Apr 15, 2022
db4cd99
Update tox.ini
SkandanC Apr 15, 2022
b3d9000
Add numpy version and remove py37
SkandanC Apr 15, 2022
1728617
Remove python version 3.7
SkandanC Apr 15, 2022
3f1b19c
Remove numpy version requirement
SkandanC Apr 15, 2022
284f228
Update build-and-test.yml
SkandanC Apr 15, 2022
b26f29e
Temporarily disable SiPANN hash tests
SkandanC Apr 19, 2022
3e1c516
Uncomment SiPANN hash tests
SkandanC Apr 26, 2022
799ebe2
Merge branch 'BYUCamachoLab:hash-test' into hash-test
SkandanC Apr 29, 2022
10d252e
Remove unnecessary tests and add tests to test every parameter
SkandanC May 23, 2022
4dcdf4b
Fix linting errors
SkandanC May 23, 2022
4acd986
Merge branch 'master' into hash-test
SkandanC Aug 25, 2022
fdbbbb2
Merge remote-tracking branch 'upstream/master' into hash-test
SkandanC Oct 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions simphony/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class Model:
pins: ClassVar[Optional[Tuple[str, ...]]]
pins: PinList # additional type hint for instance.pins

def __hash__(self) -> int:
"""Gets a hash for the model based on pin count and freq range."""

return hash(hash(self.pin_count) + hash(self.freq_range))

def __getitem__(self, item: Union[int, str]) -> Pin:
return self.pins[item]

Expand Down
212 changes: 212 additions & 0 deletions simphony/tests/test_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# Copyright © Simphony Project Contributors
# Licensed under the terms of the MIT License
# (see simphony/__init__.py for details)

from simphony.libraries import siepic
from simphony.libraries import sipann


class TestSiepicHash:

def test_hash(self):

bdc1 = siepic.BidirectionalCoupler(thickness=2.2e-7, width=5e-7)
bdc2 = siepic.BidirectionalCoupler(thickness=2.2e-7, width=5e-7)
assert bdc1.__hash__() == bdc2.__hash__()

bdc1 = siepic.BidirectionalCoupler(thickness=2.1e-7)
bdc2 = siepic.BidirectionalCoupler(thickness=2.2e-7)
assert bdc1.__hash__() != bdc2.__hash__()

bdc1 = siepic.BidirectionalCoupler(width=5.2e-7)
bdc2 = siepic.BidirectionalCoupler(width=5e-7)
assert bdc1.__hash__() != bdc2.__hash__()

hr1siepic = siepic.HalfRing(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
hr2siepic = siepic.HalfRing(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
assert hr1siepic.__hash__() == hr2siepic.__hash__()

hr1siepic = siepic.HalfRing(gap=8e-8, radius=1e-5, width=5e-7, thickness=2.1e-7)
hr2siepic = siepic.HalfRing(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
assert hr1siepic.__hash__() != hr2siepic.__hash__()

hr1siepic = siepic.HalfRing(gap=1e-7, radius=5e-6, width=5e-7, thickness=2.2e-7)
hr2siepic = siepic.HalfRing(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For components with multiple parameters, you should probably do multiple tests where each test only has 1 parameter different. That way you can get full coverage.

assert hr1siepic.__hash__() != hr2siepic.__hash__()

dc1 = siepic.DirectionalCoupler()
dc2 = siepic.DirectionalCoupler()
assert dc1.__hash__() == dc2.__hash__()

dc1 = siepic.DirectionalCoupler(Lc=0)
dc2 = siepic.DirectionalCoupler()
assert dc1.__hash__() != dc2.__hash__()

term1 = siepic.Terminator()
term2 = siepic.Terminator()
assert term1.__hash__() == term2.__hash__()

wg1 = siepic.Waveguide(length=150e-6)
wg2 = siepic.Waveguide(length=150e-6)
assert wg1.__hash__() == wg2.__hash__()

wg1 = siepic.Waveguide(length=150e-6)
wg2 = siepic.Waveguide(length=50e-6)
assert wg1.__hash__() != wg2.__hash__()

wg1 = siepic.Waveguide(width=5.2e-7)
wg2 = siepic.Waveguide()
assert wg1.__hash__() != wg2.__hash__()

wg1 = siepic.Waveguide(height=2e-7)
wg2 = siepic.Waveguide()
assert wg1.__hash__() != wg2.__hash__()


class TestSipannHash:

def test_hash(self):

hr1 = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
hr2 = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
assert hr1.__hash__() == hr2.__hash__()

hr1 = sipann.HalfRing(gap=1.5e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
hr2 = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
assert hr1.__hash__() != hr2.__hash__()

hr1 = sipann.HalfRing(gap=2e-7, radius=8e-6, width=5e-7, thickness=2.2e-7)
hr2 = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
assert hr1.__hash__() != hr2.__hash__()

hr1 = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5.2e-7, thickness=2.2e-7)
hr2 = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
assert hr1.__hash__() != hr2.__hash__()

hr1 = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.1e-7)
hr2 = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7)
assert hr1.__hash__() != hr2.__hash__()

hra1 = sipann.HalfRacetrack(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=1e-7)
hra2 = sipann.HalfRacetrack(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=1e-7)
assert hra1.__hash__() == hra2.__hash__()

hra1 = sipann.HalfRacetrack(gap=1.5e-7, radius=10e-6, width=5e-7, thickness=2.2e-7, length=2e-7)
hra2 = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=2e-7)
assert hra1.__hash__() != hra2.__hash__()

hra1 = sipann.HalfRacetrack(gap=2e-7, radius=5e-6, width=5e-7, thickness=2.2e-7, length=2e-7)
hra2 = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=2e-7)
assert hra1.__hash__() != hra2.__hash__()

hra1 = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5.2e-7, thickness=2.2e-7, length=2e-7)
hra2 = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=2e-7)
assert hra1.__hash__() != hra2.__hash__()

hra1 = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.1e-7, length=2e-7)
hra2 = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=2e-7)
assert hra1.__hash__() != hra2.__hash__()

hra1 = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=2.2e-7)
hra2 = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=2e-7)
assert hra1.__hash__() != hra2.__hash__()

sc1 = sipann.StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=1e-7)
sc2 = sipann.StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=1e-7)
assert sc1.__hash__() == sc2.__hash__()

sc1 = sipann.StraightCoupler(width=5.8e-7, thickness=2e-7, gap=2e-7, length=2e-7)
sc2 = sipann.StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=2e-7)
assert sc1.__hash__() != sc2.__hash__()

sc1 = sipann.StraightCoupler(width=5e-7, thickness=2.2e-7, gap=2e-7, length=2e-7)
sc2 = sipann.StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=2e-7)
assert sc1.__hash__() != sc2.__hash__()

sc1 = sipann.StraightCoupler(width=5e-7, thickness=2e-7, gap=2.2e-7, length=2e-7)
sc2 = sipann.StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=2e-7)
assert sc1.__hash__() != sc2.__hash__()

sc1 = sipann.StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=2.2e-7)
sc2 = sipann.StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=2e-7)
assert sc1.__hash__() != sc2.__hash__()

wg1 = sipann.Waveguide(length=150e-6, width=5e-7, thickness=2e-7)
wg2 = sipann.Waveguide(length=150e-6, width=5e-7, thickness=2e-7)
assert wg1.__hash__() == wg2.__hash__()

wg1 = sipann.Waveguide(length=150e-6, width=5e-7, thickness=2e-7)
wg2 = sipann.Waveguide(length=50e-6, width=5e-7, thickness=2e-7)
assert wg1.__hash__() != wg2.__hash__()

wg1 = sipann.Waveguide(length=50e-6, width=5.2e-7, thickness=2e-7)
wg2 = sipann.Waveguide(length=50e-6, width=5e-7, thickness=2e-7)
assert wg1.__hash__() != wg2.__hash__()

wg1 = sipann.Waveguide(length=50e-6, width=5e-7, thickness=2.3e-7)
wg2 = sipann.Waveguide(length=50e-6, width=5e-7, thickness=2e-7)
assert wg1.__hash__() != wg2.__hash__()

stcoup1 = sipann.Standard(width=5e-7, thickness=2.3e-7, gap=2e-7, length=10e-6, horizontal=1e-6, vertical=1e-6)
stcoup2 = sipann.Standard(width=5e-7, thickness=2.3e-7, gap=2e-7, length=10e-6, horizontal=1e-6, vertical=1e-6)
assert stcoup1.__hash__() == stcoup2.__hash__()

stcoup1 = sipann.Standard(width=5.8e-7, thickness=2.2e-7, gap=2e-7, length=10e-6, horizontal=2e-6, vertical=2e-6)
stcoup2 = sipann.Standard(width=5e-7, thickness=2.2e-7, gap=2e-7, length=10e-6, horizontal=2e-6, vertical=2e-6)
assert stcoup1.__hash__() != stcoup2.__hash__()

stcoup1 = sipann.Standard(width=5e-7, thickness=2.3e-7, gap=2e-7, length=10e-6, horizontal=2e-6, vertical=2e-6)
stcoup2 = sipann.Standard(width=5e-7, thickness=2.2e-7, gap=2e-7, length=10e-6, horizontal=2e-6, vertical=2e-6)
assert stcoup1.__hash__() != stcoup2.__hash__()

stcoup1 = sipann.Standard(width=5e-7, thickness=2.2e-7, gap=2.3e-7, length=10e-6, horizontal=2e-6, vertical=2e-6)
stcoup2 = sipann.Standard(width=5e-7, thickness=2.2e-7, gap=2e-7, length=10e-6, horizontal=2e-6, vertical=2e-6)
assert stcoup1.__hash__() != stcoup2.__hash__()

stcoup1 = sipann.Standard(width=5e-7, thickness=2.2e-7, gap=2e-7, length=9e-6, horizontal=2e-6, vertical=2e-6)
stcoup2 = sipann.Standard(width=5e-7, thickness=2.2e-7, gap=2e-7, length=10e-6, horizontal=2e-6, vertical=2e-6)
assert stcoup1.__hash__() != stcoup2.__hash__()

dhr1 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, gap=2e-7)
dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, gap=2e-7)
assert dhr1.__hash__() == dhr2.__hash__()

dhr1 = sipann.DoubleHalfRing(width=5.8e-7, thickness=2.2e-7, radius=1e-5, gap=2e-7)
dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, gap=2e-7)
assert dhr1.__hash__() != dhr2.__hash__()

dhr1 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, gap=2e-7)
dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, gap=2e-7)
assert dhr1.__hash__() != dhr2.__hash__()

dhr1 = sipann.DoubleHalfRing(width=5e-7, thickness=2.2e-7, radius=5e-6, gap=2e-7)
dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, gap=2e-7)
assert dhr1.__hash__() != dhr2.__hash__()

dhr1 = sipann.DoubleHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, gap=1e-7)
dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, gap=2e-7)
assert dhr1.__hash__() != dhr2.__hash__()

ahr1 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, theta=45, gap=2e-7)
ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, theta=45, gap=2e-7)
assert ahr1.__hash__() == ahr2.__hash__()

ahr1 = sipann.AngledHalfRing(width=5.8e-7, thickness=2.2e-7, radius=1e-5, theta=45, gap=2e-7)
ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, theta=45, gap=2e-7)
assert ahr1.__hash__() != ahr2.__hash__()

ahr1 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, theta=45, gap=2e-7)
ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, theta=45, gap=2e-7)
assert ahr1.__hash__() != ahr2.__hash__()

ahr1 = sipann.AngledHalfRing(width=5e-7, thickness=2.2e-7, radius=5e-6, theta=45, gap=2e-7)
ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, theta=45, gap=2e-7)
assert ahr1.__hash__() != ahr2.__hash__()

ahr1 = sipann.AngledHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, theta=50, gap=2e-7)
ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, theta=45, gap=2e-7)
assert ahr1.__hash__() != ahr2.__hash__()

ahr1 = sipann.AngledHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, theta=45, gap=1e-7)
ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.2e-7, radius=1e-5, theta=45, gap=2e-7)
assert ahr1.__hash__() != ahr2.__hash__()
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ deps =
numpy
pytest
scipy
SiPANN
commands = pytest -vv