From 251cfe70d84ebd961542904991e404004d99bc3d Mon Sep 17 00:00:00 2001 From: Water drinker Date: Tue, 15 Mar 2022 09:58:47 -0400 Subject: [PATCH 01/30] Added __hash__() method to models.py --- simphony/models.py | 10 ++++++++++ simphony/tests/modelhashtest copy.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 simphony/tests/modelhashtest copy.py diff --git a/simphony/models.py b/simphony/models.py index 3dfce47e..a576e1ed 100644 --- a/simphony/models.py +++ b/simphony/models.py @@ -53,6 +53,16 @@ class Model: pins: ClassVar[Optional[Tuple[str, ...]]] pins: PinList # additional type hint for instance.pins + def __hash__(self) -> int: + """Gets a hash for the circuit based on connections.""" + + connections = 0 + for pin in self.pins: + if pin._isconnected(include_simulators=False): + connections += hash(hash(pin) + hash(pin._connection)) + + return hash(connections) + def __getitem__(self, item: Union[int, str]) -> Pin: return self.pins[item] diff --git a/simphony/tests/modelhashtest copy.py b/simphony/tests/modelhashtest copy.py new file mode 100644 index 00000000..c471d48f --- /dev/null +++ b/simphony/tests/modelhashtest copy.py @@ -0,0 +1,17 @@ +from simphony.libraries import siepic +from models import Model + +wg1 = siepic.Waveguide() +wg2 = siepic.Waveguide() +Model.pin_count = 1 +model1 = Model() +model2 = Model() + +print(f'model1.__hash__() before connection = {model1.__hash__()}\n') +print(f'model2.__hash__() before connection = {model2.__hash__()}\n') + +model1.connect(wg1) +model2.connect(wg2) + +print(f'model1.__hash__() after connection = {model1.__hash__()}\n') +print(f'model2.__hash__() after connection = {model2.__hash__()}\n') \ No newline at end of file From 5f2e6fcf3db4b3bc3f54754b55eabce9d33869b6 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Tue, 15 Mar 2022 11:48:16 -0400 Subject: [PATCH 02/30] Add __hash__() function --- simphony/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simphony/models.py b/simphony/models.py index a576e1ed..3dca5ce3 100644 --- a/simphony/models.py +++ b/simphony/models.py @@ -54,7 +54,7 @@ class Model: pins: PinList # additional type hint for instance.pins def __hash__(self) -> int: - """Gets a hash for the circuit based on connections.""" + """Gets a hash for the model based on connections. models.py""" connections = 0 for pin in self.pins: From 5788793517f4c070ac09563c0eaf949bbe604f30 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Tue, 15 Mar 2022 11:49:03 -0400 Subject: [PATCH 03/30] Create modelhashtest.py --- simphony/tests/modelhashtest.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 simphony/tests/modelhashtest.py diff --git a/simphony/tests/modelhashtest.py b/simphony/tests/modelhashtest.py new file mode 100644 index 00000000..be541316 --- /dev/null +++ b/simphony/tests/modelhashtest.py @@ -0,0 +1,23 @@ +import sys +from simphony.layout import Circuit + +sys.path.append("C:\\Users\\12269\\Documents\\GitHub\\simphony\\simphony") + +from simphony.libraries import siepic +from models import Model +from simphony.simulators import Simulator + +wg1 = siepic.Waveguide() +wg2 = siepic.Waveguide() +Model.pin_count = 1 +model1 = Model() +model2 = Model() + +print(f'model1.__hash__() before connection = {model1.__hash__()}\n') +print(f'model2.__hash__() before connection = {model2.__hash__()}\n') + +model1.connect(wg1) +model2.connect(wg2) + +print(f'model1.__hash__() after connection = {model1.__hash__()}\n') +print(f'model2.__hash__() after connection = {model2.__hash__()}\n') From 6769bde3facdef727af2417621b81643343acd1d Mon Sep 17 00:00:00 2001 From: Water drinker Date: Mon, 21 Mar 2022 09:13:15 -0400 Subject: [PATCH 04/30] Added hash method to models.py --- simphony/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simphony/models.py b/simphony/models.py index 3dca5ce3..79bb2003 100644 --- a/simphony/models.py +++ b/simphony/models.py @@ -54,7 +54,7 @@ class Model: pins: PinList # additional type hint for instance.pins def __hash__(self) -> int: - """Gets a hash for the model based on connections. models.py""" + """Gets a hash for the model based on connections.""" connections = 0 for pin in self.pins: From 32d0bb33eef6c7117d78c9f9a8af58880e8d53f3 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Mon, 21 Mar 2022 09:19:32 -0400 Subject: [PATCH 05/30] Deleted test files --- simphony/tests/modelhashtest copy.py | 17 ----------------- simphony/tests/modelhashtest.py | 23 ----------------------- 2 files changed, 40 deletions(-) delete mode 100644 simphony/tests/modelhashtest copy.py delete mode 100644 simphony/tests/modelhashtest.py diff --git a/simphony/tests/modelhashtest copy.py b/simphony/tests/modelhashtest copy.py deleted file mode 100644 index c471d48f..00000000 --- a/simphony/tests/modelhashtest copy.py +++ /dev/null @@ -1,17 +0,0 @@ -from simphony.libraries import siepic -from models import Model - -wg1 = siepic.Waveguide() -wg2 = siepic.Waveguide() -Model.pin_count = 1 -model1 = Model() -model2 = Model() - -print(f'model1.__hash__() before connection = {model1.__hash__()}\n') -print(f'model2.__hash__() before connection = {model2.__hash__()}\n') - -model1.connect(wg1) -model2.connect(wg2) - -print(f'model1.__hash__() after connection = {model1.__hash__()}\n') -print(f'model2.__hash__() after connection = {model2.__hash__()}\n') \ No newline at end of file diff --git a/simphony/tests/modelhashtest.py b/simphony/tests/modelhashtest.py deleted file mode 100644 index be541316..00000000 --- a/simphony/tests/modelhashtest.py +++ /dev/null @@ -1,23 +0,0 @@ -import sys -from simphony.layout import Circuit - -sys.path.append("C:\\Users\\12269\\Documents\\GitHub\\simphony\\simphony") - -from simphony.libraries import siepic -from models import Model -from simphony.simulators import Simulator - -wg1 = siepic.Waveguide() -wg2 = siepic.Waveguide() -Model.pin_count = 1 -model1 = Model() -model2 = Model() - -print(f'model1.__hash__() before connection = {model1.__hash__()}\n') -print(f'model2.__hash__() before connection = {model2.__hash__()}\n') - -model1.connect(wg1) -model2.connect(wg2) - -print(f'model1.__hash__() after connection = {model1.__hash__()}\n') -print(f'model2.__hash__() after connection = {model2.__hash__()}\n') From 12c2f7dbbeee46d4c386a15e79f4b0f1535480fa Mon Sep 17 00:00:00 2001 From: Water drinker Date: Wed, 23 Mar 2022 11:37:33 -0400 Subject: [PATCH 06/30] Add __hash__() methods for siepic models --- simphony/libraries/siepic/__init__.py | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/simphony/libraries/siepic/__init__.py b/simphony/libraries/siepic/__init__.py index 4649492e..a69fd4af 100644 --- a/simphony/libraries/siepic/__init__.py +++ b/simphony/libraries/siepic/__init__.py @@ -512,6 +512,12 @@ class BidirectionalCoupler(SiEPIC_PDK_Base): r"(?:\.sparam)" ) + def __hash__(self) -> int: + + """Gets a hash for the BidirectionalCoupler component based on component type, and component parameters""" + + return hash(hash(type(self)) + hash(self.thickness) + hash(self.width)) + def __init__(self, thickness=220e-9, width=500e-9, **kwargs): super().__init__(**kwargs, thickness=thickness, width=width) @@ -584,6 +590,12 @@ class HalfRing(SiEPIC_PDK_Base): r"(?:m\.dat)" ) + def __hash__(self) -> int: + + """Gets a hash for the HalfRing component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.gap) + hash(self.radius) + hash(self.thickness) + hash(self.width) + hash(self.couple_length)) + def __init__( self, gap=30e-9, @@ -660,6 +672,12 @@ class DirectionalCoupler(SiEPIC_PDK_Base): r"(?:m\.sparam)" ) + def __hash__(self) -> int: + + """Gets a hash for the DirectionalCoupler component based on component type, gap, and length of coupler.""" + + return hash(hash(type(self)) + hash(self.gap) + hash(self.Lc)) + def __init__(self, gap=200e-9, Lc=10e-6, **kwargs): super().__init__(**kwargs, gap=gap, Lc=Lc) @@ -723,6 +741,12 @@ class Terminator(SiEPIC_PDK_Base): r"(?:_TE.sparam)" ) + def __hash__(self) -> int: + + """Gets a hash for the Terminator component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.w1) + hash(self.w2) + hash(self.L)) + def __init__(self, w1=500e-9, w2=60e-9, L=10e-6, **kwargs): super().__init__(**kwargs, w1=w1, w2=w2, L=L) @@ -793,6 +817,12 @@ class GratingCoupler(SiEPIC_PDK_Base): r"(?:\.txt)" ) + def __hash__(self) -> int: + + """Gets a hash for the GratingCoupler component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.polarization) + hash(self.thickness) + hash(self.deltaw)) + def __init__(self, thickness=220e-9, deltaw=0, polarization="TE", **kwargs): super().__init__( **kwargs, thickness=thickness, deltaw=deltaw, polarization=polarization @@ -892,6 +922,12 @@ class Waveguide(SiEPIC_PDK_Base): r"(?:\.txt)" ) + def __hash__(self) -> int: + + """Gets a hash for the Waveguide component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.length) + hash(self.width) + hash(self.height) + hash(self.polarization) + hash(self.sigma_ne) + hash(self.sigma_ng) + hash(self.sigma_nd)) + def __init__( self, length=0.0, @@ -1055,6 +1091,12 @@ class YBranch(SiEPIC_PDK_Base): r"(?:\.sparam)" ) + def __hash__(self) -> int: + + """Gets a hash for the YBranch component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.thickness) + hash(self.width) + hash(type(self.polarization))) + def __init__(self, thickness=220e-9, width=500e-9, polarization="TE", **kwargs): if polarization not in ["TE", "TM"]: raise ValueError( From c7dc8f20ebbe531365a80f03139f93557db55c9e Mon Sep 17 00:00:00 2001 From: Water drinker Date: Wed, 23 Mar 2022 11:37:48 -0400 Subject: [PATCH 07/30] Add __hash__() methods to sipann models --- simphony/libraries/sipann.py | 61 +++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/simphony/libraries/sipann.py b/simphony/libraries/sipann.py index 8c679d9a..4bc1fe1b 100644 --- a/simphony/libraries/sipann.py +++ b/simphony/libraries/sipann.py @@ -182,7 +182,7 @@ class GapFuncSymmetric(SipannWrapper): """ pin_count = 4 - + def __init__( self, width: Union[float, np.array], @@ -343,6 +343,13 @@ class HalfRing(SipannWrapper): pin_count = 4 + def __hash__(self) -> int: + + """Gets a hash for the HalfRing component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.sw_angle)) + + def __init__( self, width: Union[float, np.array], @@ -407,6 +414,13 @@ class HalfRacetrack(SipannWrapper): pin_count = 4 + def __hash__(self) -> int: + + """Gets a hash for the HalfRacetrack component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) + + def __init__( self, width: Union[float, np.array], @@ -470,6 +484,12 @@ class StraightCoupler(SipannWrapper): pin_count = 4 + def __hash__(self) -> int: + + """Gets a hash for the StraightCoupler component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) + def __init__( self, width: Union[float, np.array], @@ -539,6 +559,13 @@ class Standard(SipannWrapper): pin_count = 4 + def __hash__(self) -> int: + + """Gets a hash for the standard-shaped directional coupler component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) + + def __init__( self, width: Union[float, np.array], @@ -609,6 +636,12 @@ class DoubleHalfRing(SipannWrapper): pin_count = 4 + def __hash__(self) -> int: + + """Gets a hash for the DoubleHalfRing component based on component type, gap, radius, thickness, couple length, and width.""" + + return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.sw_angle)) + def __init__( self, width: Union[float, np.array], @@ -677,6 +710,13 @@ class AngledHalfRing(SipannWrapper): pin_count = 4 + def __hash__(self) -> int: + + """Gets a hash for the AngledHalfRing component based on component type, gap, radius, thickness, couple length, and width.""" + + return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.theta) + hash(self.model.sw_angle)) + + def __init__( self, width: Union[float, np.array], @@ -729,6 +769,7 @@ class Waveguide(SipannWrapper): pin_count = 2 + def __init__( self, width: Union[float, np.array], @@ -743,6 +784,11 @@ def __init__( sigmas, **kwargs ) + def __hash__(self) -> int: + + """Gets a hash for the staright waveguide component based on component type, gap, radius, thickness, couple length, and width.""" + + return hash(hash(type(self)) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) class Racetrack(SipannWrapper): @@ -789,6 +835,13 @@ class Racetrack(SipannWrapper): pin_count = 2 + def __hash__(self) -> int: + + """Gets a hash for the Racetrack component based on component type, gap, radius, thickness, couple length, and width.""" + + return hash(hash(type(self)) + hash(self.gap) + hash(self.radius) + hash(self.thickness) + hash(self.width) + + hash(self.length) + hash(self.sw_angle) + hash(self.sigmas)) + + def __init__( self, width: Union[float, np.array], @@ -831,6 +884,12 @@ class PremadeCoupler(SipannWrapper): pin_count = 4 + def __hash__(self) -> int: + + """Gets a hash value for the premade coupler component based on type, and 'split' parameter value.""" + + return hash(hash(type(self)) + hash(self.split)) + def __init__(self, split: int, sigmas: Dict[str, float] = dict(), **kwargs) -> None: """Loads the premade coupler based on the given split value. From 5523b790591034088cab615e5ac63fc88b6d5aea Mon Sep 17 00:00:00 2001 From: Water drinker Date: Wed, 23 Mar 2022 11:38:05 -0400 Subject: [PATCH 08/30] Add _hash__() method to models.py --- simphony/models.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/simphony/models.py b/simphony/models.py index 79bb2003..532150a7 100644 --- a/simphony/models.py +++ b/simphony/models.py @@ -52,17 +52,12 @@ class Model: pin_count: ClassVar[Optional[int]] 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 connections.""" - connections = 0 - for pin in self.pins: - if pin._isconnected(include_simulators=False): - connections += hash(hash(pin) + hash(pin._connection)) - - return hash(connections) - + return hash(hash(self.pin_count) + hash(self.freq_range)) + def __getitem__(self, item: Union[int, str]) -> Pin: return self.pins[item] @@ -74,7 +69,7 @@ def __init__( pins: Optional[List[Pin]] = None, ) -> None: """Initializes an instance of the model. - + Parameters ---------- name : From ae857f24f053000202479acd8dc3a41e5774e3de Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 24 Mar 2022 17:47:55 -0400 Subject: [PATCH 09/30] Add hash tests --- simphony/tests/siepichashtest.py | 48 +++++++++++++++++++++++ simphony/tests/sipannhashtest.py | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 simphony/tests/siepichashtest.py create mode 100644 simphony/tests/sipannhashtest.py diff --git a/simphony/tests/siepichashtest.py b/simphony/tests/siepichashtest.py new file mode 100644 index 00000000..02955d69 --- /dev/null +++ b/simphony/tests/siepichashtest.py @@ -0,0 +1,48 @@ +from simphony.libraries.siepic import * + + +bdc1 = BidirectionalCoupler() +bdc2 = BidirectionalCoupler() +print(f'\nIdentical Bidirectional couplers:{bdc1.__hash__()}, {bdc2.__hash__()}\n') + +bdc1 = BidirectionalCoupler(2.1e-7) +bdc2 = BidirectionalCoupler(2.3e-7) +print(f'Non-identical Bidirectional couplers:{bdc1.__hash__()}, {bdc2.__hash__()}\n') + +# FIXME +hr1siepic = HalfRing(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) +hr2siepic = HalfRing(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) +print(f'Identical halfrings:{hr1siepic.__hash__()}, {hr2siepic.__hash__()}\n') + +hr1siepic = HalfRing(gap=8e-8,radius=10e-6,width=5.2e-7,thickness=2.1e-7) +hr2siepic = HalfRing(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7,couple_length=0) +print(f'Non-identical halfrings:{hr1siepic.__hash__()}, {hr2siepic.__hash__()}\n') + + +dc1 = DirectionalCoupler() +dc2 = DirectionalCoupler() +print(f'Identical Directional couplers:{dc1.__hash__()}, {dc2.__hash__()}') + +dc1 = DirectionalCoupler(gap=2e-7, Lc=10e-6) # this autocorrects to default attribute values everytime +dc2 = DirectionalCoupler() +print(f'Non-identical Directional couplers:{dc1.__hash__()}, {dc2.__hash__()}') + + +term1 = Terminator() +term2 = Terminator() +print(f'Identical terminators:{term1.__hash__()}, {term2.__hash__()}') + +term1 = Terminator(w1=5e-7) # this autocorrects to default attribute values everytime +term2 = Terminator() +print(f'Non-identical terminators:{term1.__hash__()}, {term2.__hash__()}') + + +# wg1 and wg2 hash should be different +wg1 = Waveguide(length=150e-6) +wg2 = Waveguide(length=50e-6) +print(f'Non-identical waveguides:{wg1.__hash__()},{wg2.__hash__()}') + +# wg1 and wg2 hash should be the same +wg1 = Waveguide(length=150e-6) +wg2 = Waveguide(length=150e-6) +print(f'Identical waveguides:{wg1.__hash__()},{wg2.__hash__()}') diff --git a/simphony/tests/sipannhashtest.py b/simphony/tests/sipannhashtest.py new file mode 100644 index 00000000..f788ba20 --- /dev/null +++ b/simphony/tests/sipannhashtest.py @@ -0,0 +1,65 @@ +from simphony.libraries.sipann import * + +hr1siepic = HalfRing(gap=2e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) +hr2siepic = HalfRing(gap=2e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) +print(f'Identical halfrings:{hr1siepic.__hash__()}, {hr2siepic.__hash__()}\n') + +hr1siepic = HalfRing(gap=1.5e-7,radius=10e-6,width=5.2e-7,thickness=2.1e-7) +hr2siepic = HalfRing(gap=2e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) +print(f'Non-identical halfrings:{hr1siepic.__hash__()}, {hr2siepic.__hash__()}\n') + + +hra1siepic = HalfRacetrack(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7,length=1e-7) +hra2siepic = HalfRacetrack(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7,length=1e-7) +print(f'Identical halfracetracks:{hra1siepic.__hash__()}, {hra2siepic.__hash__()}\n') + +hra1siepic = HalfRacetrack(gap=1.5e-7,radius=10e-6,width=5.2e-7,thickness=2.1e-7,length=1e-7) +hra2siepic = HalfRacetrack(gap=2e-7,radius=1e-5,width=5e-7,thickness=2.2e-7,length=2e-7) +print(f'Non-identical halfracetracks:{hra1siepic.__hash__()}, {hra2siepic.__hash__()}\n') + + +sc1 = StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=1e-7) +sc2 = StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=1e-7) +print(f'Identical straight coupler:{sc1.__hash__()}, {sc2.__hash__()}\n') + +sc1 = StraightCoupler(width=5.8e-7, thickness=2e-7, gap=3e-7, length=2e-7) +sc2 = StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-7) +print(f'Non-identical straight coupler:{sc1.__hash__()}, {sc2.__hash__()}\n') + + +# wg1 and wg2 hash should be different +wg1 = Waveguide(length=150e-6,width=5e-7,thickness=2e-7) +wg2 = Waveguide(length=50e-6,width=6e-7,thickness=2.3e-7) +print(f'Non-identical waveguides:{wg1.__hash__()},{wg2.__hash__()}\n') + +# wg1 and wg2 hash should be the same +wg1 = Waveguide(length=150e-6,width=5e-7,thickness=2e-7) +wg2 = Waveguide(length=150e-6,width=5e-7,thickness=2e-7) +print(f'Identical waveguides:{wg1.__hash__()},{wg2.__hash__()}\n') + + + +stcoup1 = Standard(width=5e-7,thickness=2.3e-7,gap=2e-7,length=10e-6,horizontal=1e-6,vertical=1e-6) +stcoup2 = Standard(width=5e-7,thickness=2.3e-7,gap=2e-7,length=10e-6,horizontal=1e-6,vertical=1e-6) +print(f'Identical standard couplers:{stcoup1.__hash__()},{stcoup2.__hash__()}\n') + +stcoup1 = Standard(width=5.8e-7,thickness=2.2e-7,gap=3e-7,length=9e-6,horizontal=2e-6,vertical=2e-6) +stcoup2 = Standard(width=5e-7,thickness=2.3e-7,gap=2e-7,length=10e-6,horizontal=1e-6,vertical=1e-6) +print(f'Non-identical standard couplers:{stcoup1.__hash__()},{stcoup2.__hash__()}\n') + +dhr1 = DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,gap=2e-7) +dhr2 = DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,gap=2e-7) +print(f'Identical double half ring:{dhr1.__hash__()},{dhr2.__hash__()}\n') + +dhr1 = DoubleHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6,gap=3e-7) +dhr2 = DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,gap=2e-7) +print(f'Non-identical double half ring:{dhr1.__hash__()},{dhr2.__hash__()}\n') + + +ahr1 = AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,theta=45,gap=2e-7) +ahr2 = AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,theta=45,gap=2e-7) +print(f'Identical angled half ring:{ahr1.__hash__()},{ahr2.__hash__()}\n') + +ahr1 = AngledHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6,theta=50,gap=3e-7) +ahr2 = AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,theta=45,gap=2e-7) +print(f'Non-identical angled half ring:{ahr1.__hash__()},{ahr2.__hash__()}\n') From 910f0da6a224ae75d4bb7959036680e1f8dbfc20 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 24 Mar 2022 18:33:54 -0400 Subject: [PATCH 10/30] Update __hash__() docstring --- simphony/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simphony/models.py b/simphony/models.py index 532150a7..0c20d66c 100644 --- a/simphony/models.py +++ b/simphony/models.py @@ -54,7 +54,7 @@ class Model: pins: PinList # additional type hint for instance.pins def __hash__(self) -> int: - """Gets a hash for the model based on connections.""" + """Gets a hash for the model based on pin count and freq range.""" return hash(hash(self.pin_count) + hash(self.freq_range)) From 11efb641b7a27a8d84485027645676704fc809bc Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 24 Mar 2022 18:34:05 -0400 Subject: [PATCH 11/30] Add base tests --- simphony/tests/test_models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simphony/tests/test_models.py b/simphony/tests/test_models.py index 01cdd5b8..3bfee303 100644 --- a/simphony/tests/test_models.py +++ b/simphony/tests/test_models.py @@ -2,6 +2,7 @@ # Licensed under the terms of the MIT License # (see simphony/__init__.py for details) +from cmath import inf import pytest from simphony.libraries import siepic @@ -88,11 +89,16 @@ def s_parameters(self, freqs): return self.y1.s_parameters(freqs) brancher = YBranch() + brancher2 = YBranch() + brancher3 = YBranch() + brancher3.pin_count = 2 brancher.multiconnect(wg1, wg2, wg3) assert brancher.circuit == wg1.circuit assert wg1.circuit == wg2.circuit assert wg2.circuit == wg3.circuit + assert brancher.__hash__() == brancher2.__hash__() + assert brancher.__hash__() != brancher3.__hash__() class TestSubcircuitExtension: From 74d289da76c139ade73d1c4cc360696149b63548 Mon Sep 17 00:00:00 2001 From: Skandan Chandrasekar <100642027+SkandanC@users.noreply.github.com> Date: Mon, 28 Mar 2022 10:45:33 -0400 Subject: [PATCH 12/30] Update siepichashtest.py --- simphony/tests/siepichashtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simphony/tests/siepichashtest.py b/simphony/tests/siepichashtest.py index 02955d69..0e02d24c 100644 --- a/simphony/tests/siepichashtest.py +++ b/simphony/tests/siepichashtest.py @@ -23,7 +23,7 @@ dc2 = DirectionalCoupler() print(f'Identical Directional couplers:{dc1.__hash__()}, {dc2.__hash__()}') -dc1 = DirectionalCoupler(gap=2e-7, Lc=10e-6) # this autocorrects to default attribute values everytime +dc1 = DirectionalCoupler(gap=2e-7, Lc=10e-6) # this autocorrects to default attribute values everytime, not sure why dc2 = DirectionalCoupler() print(f'Non-identical Directional couplers:{dc1.__hash__()}, {dc2.__hash__()}') From 1abc4f8e4d472d6c11c893f4588d1bb8f9249ab7 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 17:01:46 -0400 Subject: [PATCH 13/30] Update hash test files Delete one of the hash test files and put tests into a class method under one file. Change print statements to assert statements. --- simphony/libraries/siepic/__init__.py | 34 ++++---- simphony/tests/siepichashtest.py | 48 ----------- simphony/tests/sipannhashtest.py | 65 --------------- simphony/tests/test_hash.py | 115 ++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 130 deletions(-) delete mode 100644 simphony/tests/siepichashtest.py delete mode 100644 simphony/tests/sipannhashtest.py create mode 100644 simphony/tests/test_hash.py diff --git a/simphony/libraries/siepic/__init__.py b/simphony/libraries/siepic/__init__.py index a69fd4af..16c6f68a 100644 --- a/simphony/libraries/siepic/__init__.py +++ b/simphony/libraries/siepic/__init__.py @@ -513,10 +513,10 @@ class BidirectionalCoupler(SiEPIC_PDK_Base): ) def __hash__(self) -> int: - - """Gets a hash for the BidirectionalCoupler component based on component type, and component parameters""" - return hash(hash(type(self)) + hash(self.thickness) + hash(self.width)) + """Gets a hash for the BidirectionalCoupler component based on component type, and component parameters""" + + return hash(hash(type(self)) + hash(self.thickness) + hash(self.width)) def __init__(self, thickness=220e-9, width=500e-9, **kwargs): super().__init__(**kwargs, thickness=thickness, width=width) @@ -591,7 +591,7 @@ class HalfRing(SiEPIC_PDK_Base): ) def __hash__(self) -> int: - + """Gets a hash for the HalfRing component based on component type, and component parameters.""" return hash(hash(type(self)) + hash(self.gap) + hash(self.radius) + hash(self.thickness) + hash(self.width) + hash(self.couple_length)) @@ -673,10 +673,10 @@ class DirectionalCoupler(SiEPIC_PDK_Base): ) def __hash__(self) -> int: - - """Gets a hash for the DirectionalCoupler component based on component type, gap, and length of coupler.""" + + """Gets a hash for the DirectionalCoupler component based on component type, gap, and length of coupler.""" - return hash(hash(type(self)) + hash(self.gap) + hash(self.Lc)) + return hash(hash(type(self)) + hash(self.gap) + hash(self.Lc)) def __init__(self, gap=200e-9, Lc=10e-6, **kwargs): super().__init__(**kwargs, gap=gap, Lc=Lc) @@ -742,10 +742,10 @@ class Terminator(SiEPIC_PDK_Base): ) def __hash__(self) -> int: - - """Gets a hash for the Terminator component based on component type, and component parameters.""" - return hash(hash(type(self)) + hash(self.w1) + hash(self.w2) + hash(self.L)) + """Gets a hash for the Terminator component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.w1) + hash(self.w2) + hash(self.L)) def __init__(self, w1=500e-9, w2=60e-9, L=10e-6, **kwargs): super().__init__(**kwargs, w1=w1, w2=w2, L=L) @@ -818,10 +818,10 @@ class GratingCoupler(SiEPIC_PDK_Base): ) def __hash__(self) -> int: - - """Gets a hash for the GratingCoupler component based on component type, and component parameters.""" - return hash(hash(type(self)) + hash(self.polarization) + hash(self.thickness) + hash(self.deltaw)) + """Gets a hash for the GratingCoupler component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.polarization) + hash(self.thickness) + hash(self.deltaw)) def __init__(self, thickness=220e-9, deltaw=0, polarization="TE", **kwargs): super().__init__( @@ -923,7 +923,7 @@ class Waveguide(SiEPIC_PDK_Base): ) def __hash__(self) -> int: - + """Gets a hash for the Waveguide component based on component type, and component parameters.""" return hash(hash(type(self)) + hash(self.length) + hash(self.width) + hash(self.height) + hash(self.polarization) + hash(self.sigma_ne) + hash(self.sigma_ng) + hash(self.sigma_nd)) @@ -1092,10 +1092,10 @@ class YBranch(SiEPIC_PDK_Base): ) def __hash__(self) -> int: - - """Gets a hash for the YBranch component based on component type, and component parameters.""" - return hash(hash(type(self)) + hash(self.thickness) + hash(self.width) + hash(type(self.polarization))) + """Gets a hash for the YBranch component based on component type, and component parameters.""" + + return hash(hash(type(self)) + hash(self.thickness) + hash(self.width) + hash(type(self.polarization))) def __init__(self, thickness=220e-9, width=500e-9, polarization="TE", **kwargs): if polarization not in ["TE", "TM"]: diff --git a/simphony/tests/siepichashtest.py b/simphony/tests/siepichashtest.py deleted file mode 100644 index 0e02d24c..00000000 --- a/simphony/tests/siepichashtest.py +++ /dev/null @@ -1,48 +0,0 @@ -from simphony.libraries.siepic import * - - -bdc1 = BidirectionalCoupler() -bdc2 = BidirectionalCoupler() -print(f'\nIdentical Bidirectional couplers:{bdc1.__hash__()}, {bdc2.__hash__()}\n') - -bdc1 = BidirectionalCoupler(2.1e-7) -bdc2 = BidirectionalCoupler(2.3e-7) -print(f'Non-identical Bidirectional couplers:{bdc1.__hash__()}, {bdc2.__hash__()}\n') - -# FIXME -hr1siepic = HalfRing(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) -hr2siepic = HalfRing(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) -print(f'Identical halfrings:{hr1siepic.__hash__()}, {hr2siepic.__hash__()}\n') - -hr1siepic = HalfRing(gap=8e-8,radius=10e-6,width=5.2e-7,thickness=2.1e-7) -hr2siepic = HalfRing(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7,couple_length=0) -print(f'Non-identical halfrings:{hr1siepic.__hash__()}, {hr2siepic.__hash__()}\n') - - -dc1 = DirectionalCoupler() -dc2 = DirectionalCoupler() -print(f'Identical Directional couplers:{dc1.__hash__()}, {dc2.__hash__()}') - -dc1 = DirectionalCoupler(gap=2e-7, Lc=10e-6) # this autocorrects to default attribute values everytime, not sure why -dc2 = DirectionalCoupler() -print(f'Non-identical Directional couplers:{dc1.__hash__()}, {dc2.__hash__()}') - - -term1 = Terminator() -term2 = Terminator() -print(f'Identical terminators:{term1.__hash__()}, {term2.__hash__()}') - -term1 = Terminator(w1=5e-7) # this autocorrects to default attribute values everytime -term2 = Terminator() -print(f'Non-identical terminators:{term1.__hash__()}, {term2.__hash__()}') - - -# wg1 and wg2 hash should be different -wg1 = Waveguide(length=150e-6) -wg2 = Waveguide(length=50e-6) -print(f'Non-identical waveguides:{wg1.__hash__()},{wg2.__hash__()}') - -# wg1 and wg2 hash should be the same -wg1 = Waveguide(length=150e-6) -wg2 = Waveguide(length=150e-6) -print(f'Identical waveguides:{wg1.__hash__()},{wg2.__hash__()}') diff --git a/simphony/tests/sipannhashtest.py b/simphony/tests/sipannhashtest.py deleted file mode 100644 index f788ba20..00000000 --- a/simphony/tests/sipannhashtest.py +++ /dev/null @@ -1,65 +0,0 @@ -from simphony.libraries.sipann import * - -hr1siepic = HalfRing(gap=2e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) -hr2siepic = HalfRing(gap=2e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) -print(f'Identical halfrings:{hr1siepic.__hash__()}, {hr2siepic.__hash__()}\n') - -hr1siepic = HalfRing(gap=1.5e-7,radius=10e-6,width=5.2e-7,thickness=2.1e-7) -hr2siepic = HalfRing(gap=2e-7,radius=1e-5,width=5e-7,thickness=2.2e-7) -print(f'Non-identical halfrings:{hr1siepic.__hash__()}, {hr2siepic.__hash__()}\n') - - -hra1siepic = HalfRacetrack(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7,length=1e-7) -hra2siepic = HalfRacetrack(gap=1e-7,radius=1e-5,width=5e-7,thickness=2.2e-7,length=1e-7) -print(f'Identical halfracetracks:{hra1siepic.__hash__()}, {hra2siepic.__hash__()}\n') - -hra1siepic = HalfRacetrack(gap=1.5e-7,radius=10e-6,width=5.2e-7,thickness=2.1e-7,length=1e-7) -hra2siepic = HalfRacetrack(gap=2e-7,radius=1e-5,width=5e-7,thickness=2.2e-7,length=2e-7) -print(f'Non-identical halfracetracks:{hra1siepic.__hash__()}, {hra2siepic.__hash__()}\n') - - -sc1 = StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=1e-7) -sc2 = StraightCoupler(width=5e-7, thickness=2e-7, gap=2e-7, length=1e-7) -print(f'Identical straight coupler:{sc1.__hash__()}, {sc2.__hash__()}\n') - -sc1 = StraightCoupler(width=5.8e-7, thickness=2e-7, gap=3e-7, length=2e-7) -sc2 = StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-7) -print(f'Non-identical straight coupler:{sc1.__hash__()}, {sc2.__hash__()}\n') - - -# wg1 and wg2 hash should be different -wg1 = Waveguide(length=150e-6,width=5e-7,thickness=2e-7) -wg2 = Waveguide(length=50e-6,width=6e-7,thickness=2.3e-7) -print(f'Non-identical waveguides:{wg1.__hash__()},{wg2.__hash__()}\n') - -# wg1 and wg2 hash should be the same -wg1 = Waveguide(length=150e-6,width=5e-7,thickness=2e-7) -wg2 = Waveguide(length=150e-6,width=5e-7,thickness=2e-7) -print(f'Identical waveguides:{wg1.__hash__()},{wg2.__hash__()}\n') - - - -stcoup1 = Standard(width=5e-7,thickness=2.3e-7,gap=2e-7,length=10e-6,horizontal=1e-6,vertical=1e-6) -stcoup2 = Standard(width=5e-7,thickness=2.3e-7,gap=2e-7,length=10e-6,horizontal=1e-6,vertical=1e-6) -print(f'Identical standard couplers:{stcoup1.__hash__()},{stcoup2.__hash__()}\n') - -stcoup1 = Standard(width=5.8e-7,thickness=2.2e-7,gap=3e-7,length=9e-6,horizontal=2e-6,vertical=2e-6) -stcoup2 = Standard(width=5e-7,thickness=2.3e-7,gap=2e-7,length=10e-6,horizontal=1e-6,vertical=1e-6) -print(f'Non-identical standard couplers:{stcoup1.__hash__()},{stcoup2.__hash__()}\n') - -dhr1 = DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,gap=2e-7) -dhr2 = DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,gap=2e-7) -print(f'Identical double half ring:{dhr1.__hash__()},{dhr2.__hash__()}\n') - -dhr1 = DoubleHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6,gap=3e-7) -dhr2 = DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,gap=2e-7) -print(f'Non-identical double half ring:{dhr1.__hash__()},{dhr2.__hash__()}\n') - - -ahr1 = AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,theta=45,gap=2e-7) -ahr2 = AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,theta=45,gap=2e-7) -print(f'Identical angled half ring:{ahr1.__hash__()},{ahr2.__hash__()}\n') - -ahr1 = AngledHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6,theta=50,gap=3e-7) -ahr2 = AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,theta=45,gap=2e-7) -print(f'Non-identical angled half ring:{ahr1.__hash__()},{ahr2.__hash__()}\n') diff --git a/simphony/tests/test_hash.py b/simphony/tests/test_hash.py new file mode 100644 index 00000000..50cf84ce --- /dev/null +++ b/simphony/tests/test_hash.py @@ -0,0 +1,115 @@ +# Copyright © Simphony Project Contributors +# Licensed under the terms of the MIT License +# (see simphony/__init__.py for details) + +import numpy as np + +from simphony.libraries import siepic +from simphony.libraries import sipann + + +class TestSiepicHash: + + def test_hash(): + + bdc1 = siepic.BidirectionalCoupler() + bdc2 = siepic.BidirectionalCoupler() + assert np.allclose(bdc1.__hash__(), bdc2.__hash__()) + + bdc1 = siepic.BidirectionalCoupler(2.1e-7) + bdc2 = siepic.BidirectionalCoupler(2.3e-7) + assert not np.allclose(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 np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) + + hr1siepic = siepic.HalfRing(gap=8e-8, radius=10e-6, width=5.2e-7, thickness=2.1e-7) + hr2siepic = siepic.HalfRing(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) + assert not np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) + + dc1 = siepic.DirectionalCoupler() + dc2 = siepic.DirectionalCoupler() + assert np.allclose(dc1.__hash__(), dc2.__hash__()) + + dc1 = siepic.DirectionalCoupler(gap=2e-7, Lc=10e-6) + dc2 = siepic.DirectionalCoupler() + assert not np.allclose(dc1.__hash__(), dc2.__hash__()) + + term1 = siepic.Terminator() + term2 = siepic.Terminator() + assert np.allclose(term1.__hash__(), term2.__hash__()) + + term1 = siepic.Terminator(w1=5e-7) # this autocorrects to default attribute values everytime + term2 = siepic.Terminator() + assert not np.allclose(term1.__hash__(), term2.__hash__()) + + # wg1 and wg2 hash should be the same + wg1 = siepic.Waveguide(length=150e-6) + wg2 = siepic.Waveguide(length=150e-6) + assert np.allclose(wg1.__hash__(), wg2.__hash__()) + + wg1 = siepic.Waveguide(length=150e-6) + wg2 = siepic.Waveguide(length=50e-6) + assert not np.allclose(wg1.__hash__(), wg2.__hash__()) + + +class TestSipannHash: + + def test_hash(): + + hr1siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) + hr2siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) + assert np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) + + hr1siepic = sipann.HalfRing(gap=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7) + hr2siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) + assert not np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) + + hra1siepic = sipann.HalfRacetrack(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=1e-7) + hra2siepic = sipann.HalfRacetrack(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=1e-7) + assert np.allclose(hra1siepic.__hash__(), hra2siepic.__hash__()) + + hra1siepic = sipann.HalfRacetrack(gap=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7, length=1e-7) + hra2siepic = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=2e-7) + assert not np.allclose(hra1siepic.__hash__(), hra2siepic.__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 np.allclose(sc1.__hash__(), sc2.__hash__()) + + sc1 = sipann.StraightCoupler(width=5.8e-7, thickness=2e-7, gap=3e-7, length=2e-7) + sc2 = sipann.StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-7) + assert not np.allclose(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 np.allclose(wg1.__hash__(), wg2.__hash__()) + + wg1 = sipann.Waveguide(length=150e-6, width=5e-7, thickness=2e-7) + wg2 = sipann.Waveguide(length=50e-6, width=6e-7, thickness=2.3e-7) + assert not np.allclose(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 np.allclose(stcoup1.__hash__(), stcoup2.__hash__()) + + stcoup1 = sipann.Standard(width=5.8e-7, thickness=2.2e-7, gap=3e-7, length=9e-6, horizontal=2e-6, vertical=2e-6) + stcoup2 = sipann.Standard(width=5e-7, thickness=2.3e-7, gap=2e-7, length=10e-6, horizontal=1e-6, vertical=1e-6) + assert not np.allclose(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 np.allclose(dhr1.__hash__(), dhr2.__hash__()) + + dhr1 = sipann.DoubleHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6,gap=3e-7) + dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,gap=2e-7) + assert not np.allclose(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 np.allclose(ahr1.__hash__(), ahr2.__hash__()) + + ahr1 = sipann.AngledHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6,theta=50,gap=3e-7) + ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,theta=45,gap=2e-7) + assert not np.allclose(ahr1.__hash__(), ahr2.__hash__()) From df5b128eec2d54c5f61a703ab3baaf81cc94ef6e Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 17:01:56 -0400 Subject: [PATCH 14/30] Linting --- simphony/libraries/sipann.py | 27 +++++++++++---------------- simphony/models.py | 6 +++--- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/simphony/libraries/sipann.py b/simphony/libraries/sipann.py index 4bc1fe1b..0169579e 100644 --- a/simphony/libraries/sipann.py +++ b/simphony/libraries/sipann.py @@ -182,7 +182,7 @@ class GapFuncSymmetric(SipannWrapper): """ pin_count = 4 - + def __init__( self, width: Union[float, np.array], @@ -344,12 +344,11 @@ class HalfRing(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash for the HalfRing component based on component type, and component parameters.""" return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.sw_angle)) - def __init__( self, width: Union[float, np.array], @@ -415,12 +414,11 @@ class HalfRacetrack(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash for the HalfRacetrack component based on component type, and component parameters.""" return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) - def __init__( self, width: Union[float, np.array], @@ -485,7 +483,7 @@ class StraightCoupler(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash for the StraightCoupler component based on component type, and component parameters.""" return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) @@ -560,12 +558,11 @@ class Standard(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash for the standard-shaped directional coupler component based on component type, and component parameters.""" return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) - def __init__( self, width: Union[float, np.array], @@ -637,7 +634,7 @@ class DoubleHalfRing(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash for the DoubleHalfRing component based on component type, gap, radius, thickness, couple length, and width.""" return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.sw_angle)) @@ -711,12 +708,11 @@ class AngledHalfRing(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash for the AngledHalfRing component based on component type, gap, radius, thickness, couple length, and width.""" return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.theta) + hash(self.model.sw_angle)) - def __init__( self, width: Union[float, np.array], @@ -769,7 +765,6 @@ class Waveguide(SipannWrapper): pin_count = 2 - def __init__( self, width: Union[float, np.array], @@ -784,8 +779,9 @@ def __init__( sigmas, **kwargs ) + def __hash__(self) -> int: - + """Gets a hash for the staright waveguide component based on component type, gap, radius, thickness, couple length, and width.""" return hash(hash(type(self)) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) @@ -836,12 +832,11 @@ class Racetrack(SipannWrapper): pin_count = 2 def __hash__(self) -> int: - + """Gets a hash for the Racetrack component based on component type, gap, radius, thickness, couple length, and width.""" return hash(hash(type(self)) + hash(self.gap) + hash(self.radius) + hash(self.thickness) + hash(self.width) + + hash(self.length) + hash(self.sw_angle) + hash(self.sigmas)) - def __init__( self, width: Union[float, np.array], @@ -885,7 +880,7 @@ class PremadeCoupler(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash value for the premade coupler component based on type, and 'split' parameter value.""" return hash(hash(type(self)) + hash(self.split)) diff --git a/simphony/models.py b/simphony/models.py index 0c20d66c..c19afa75 100644 --- a/simphony/models.py +++ b/simphony/models.py @@ -52,12 +52,12 @@ class Model: pin_count: ClassVar[Optional[int]] 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] @@ -69,7 +69,7 @@ def __init__( pins: Optional[List[Pin]] = None, ) -> None: """Initializes an instance of the model. - + Parameters ---------- name : From 00ec666e7960c97de42663da89166457cd888155 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 17:43:55 -0400 Subject: [PATCH 15/30] Linting --- simphony/libraries/siepic/__init__.py | 2 +- simphony/libraries/sipann.py | 12 ++++++------ simphony/tests/test_hash.py | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/simphony/libraries/siepic/__init__.py b/simphony/libraries/siepic/__init__.py index 16c6f68a..66d50272 100644 --- a/simphony/libraries/siepic/__init__.py +++ b/simphony/libraries/siepic/__init__.py @@ -673,7 +673,7 @@ class DirectionalCoupler(SiEPIC_PDK_Base): ) def __hash__(self) -> int: - + """Gets a hash for the DirectionalCoupler component based on component type, gap, and length of coupler.""" return hash(hash(type(self)) + hash(self.gap) + hash(self.Lc)) diff --git a/simphony/libraries/sipann.py b/simphony/libraries/sipann.py index 0169579e..04648ec9 100644 --- a/simphony/libraries/sipann.py +++ b/simphony/libraries/sipann.py @@ -344,7 +344,7 @@ class HalfRing(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash for the HalfRing component based on component type, and component parameters.""" return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.radius) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.sw_angle)) @@ -483,7 +483,7 @@ class StraightCoupler(SipannWrapper): pin_count = 4 def __hash__(self) -> int: - + """Gets a hash for the StraightCoupler component based on component type, and component parameters.""" return hash(hash(type(self)) + hash(self.model.gap) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) @@ -781,10 +781,10 @@ def __init__( ) def __hash__(self) -> int: - - """Gets a hash for the staright waveguide component based on component type, gap, radius, thickness, couple length, and width.""" - return hash(hash(type(self)) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) + """Gets a hash for the staright waveguide component based on component type, gap, radius, thickness, couple length, and width.""" + + return hash(hash(type(self)) + hash(self.model.thickness) + hash(self.model.width) + hash(self.model.length) + hash(self.model.sw_angle)) class Racetrack(SipannWrapper): @@ -832,7 +832,7 @@ class Racetrack(SipannWrapper): pin_count = 2 def __hash__(self) -> int: - + """Gets a hash for the Racetrack component based on component type, gap, radius, thickness, couple length, and width.""" return hash(hash(type(self)) + hash(self.gap) + hash(self.radius) + hash(self.thickness) + hash(self.width) + + hash(self.length) + hash(self.sw_angle) + hash(self.sigmas)) diff --git a/simphony/tests/test_hash.py b/simphony/tests/test_hash.py index 50cf84ce..71e03abe 100644 --- a/simphony/tests/test_hash.py +++ b/simphony/tests/test_hash.py @@ -57,7 +57,7 @@ def test_hash(): class TestSipannHash: def test_hash(): - + hr1siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) hr2siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) assert np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) @@ -85,7 +85,7 @@ def test_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 np.allclose(wg1.__hash__(), wg2.__hash__()) - + wg1 = sipann.Waveguide(length=150e-6, width=5e-7, thickness=2e-7) wg2 = sipann.Waveguide(length=50e-6, width=6e-7, thickness=2.3e-7) assert not np.allclose(wg1.__hash__(), wg2.__hash__()) @@ -98,18 +98,18 @@ def test_hash(): stcoup2 = sipann.Standard(width=5e-7, thickness=2.3e-7, gap=2e-7, length=10e-6, horizontal=1e-6, vertical=1e-6) assert not np.allclose(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) + 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 np.allclose(dhr1.__hash__(), dhr2.__hash__()) - dhr1 = sipann.DoubleHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6,gap=3e-7) - dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,gap=2e-7) + dhr1 = sipann.DoubleHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6, gap=3e-7) + dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, gap=2e-7) assert not np.allclose(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) + 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 np.allclose(ahr1.__hash__(), ahr2.__hash__()) - ahr1 = sipann.AngledHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6,theta=50,gap=3e-7) - ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5,theta=45,gap=2e-7) + ahr1 = sipann.AngledHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6, theta=50, gap=3e-7) + ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, theta=45, gap=2e-7) assert not np.allclose(ahr1.__hash__(), ahr2.__hash__()) From 434ec5564b09d444de6ae6cfaeb42ff0489cfef6 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 17:46:50 -0400 Subject: [PATCH 16/30] Remove unused import --- simphony/tests/test_models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/simphony/tests/test_models.py b/simphony/tests/test_models.py index 3bfee303..e25fec06 100644 --- a/simphony/tests/test_models.py +++ b/simphony/tests/test_models.py @@ -2,7 +2,6 @@ # Licensed under the terms of the MIT License # (see simphony/__init__.py for details) -from cmath import inf import pytest from simphony.libraries import siepic From 6186a5e81a5e65e00cf898c02af0fe1790d226da Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 17:54:02 -0400 Subject: [PATCH 17/30] Add SiPANN to tox deps SiPANN is needed in the `py` virtual environment. --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index be8f9450..903cca3b 100644 --- a/tox.ini +++ b/tox.ini @@ -6,4 +6,5 @@ deps = numpy pytest scipy + SiPANN commands = pytest -vv From ff07d54aa54feecfc62806076cbc702c897b2bb6 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 18:11:08 -0400 Subject: [PATCH 18/30] Update test_hash.py --- simphony/tests/test_hash.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simphony/tests/test_hash.py b/simphony/tests/test_hash.py index 71e03abe..e745239d 100644 --- a/simphony/tests/test_hash.py +++ b/simphony/tests/test_hash.py @@ -10,7 +10,7 @@ class TestSiepicHash: - def test_hash(): + def test_hash(self): bdc1 = siepic.BidirectionalCoupler() bdc2 = siepic.BidirectionalCoupler() @@ -56,7 +56,7 @@ def test_hash(): class TestSipannHash: - def test_hash(): + def test_hash(self): hr1siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) hr2siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) From 721f295f079107fec2a5eeeed98adfe280b94c70 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 21:54:25 -0400 Subject: [PATCH 19/30] Update assert statements --- simphony/tests/test_hash.py | 76 +++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/simphony/tests/test_hash.py b/simphony/tests/test_hash.py index e745239d..f2015d9f 100644 --- a/simphony/tests/test_hash.py +++ b/simphony/tests/test_hash.py @@ -2,114 +2,106 @@ # Licensed under the terms of the MIT License # (see simphony/__init__.py for details) -import numpy as np - from simphony.libraries import siepic from simphony.libraries import sipann - class TestSiepicHash: def test_hash(self): - bdc1 = siepic.BidirectionalCoupler() - bdc2 = siepic.BidirectionalCoupler() - assert np.allclose(bdc1.__hash__(), bdc2.__hash__()) + 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(2.1e-7) bdc2 = siepic.BidirectionalCoupler(2.3e-7) - assert not np.allclose(bdc1.__hash__(), bdc2.__hash__()) + 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 np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) + assert (hr1siepic.__hash__() == hr2siepic.__hash__()) hr1siepic = siepic.HalfRing(gap=8e-8, radius=10e-6, width=5.2e-7, thickness=2.1e-7) hr2siepic = siepic.HalfRing(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) - assert not np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) + assert (hr1siepic.__hash__() != hr2siepic.__hash__()) dc1 = siepic.DirectionalCoupler() dc2 = siepic.DirectionalCoupler() - assert np.allclose(dc1.__hash__(), dc2.__hash__()) + assert (dc1.__hash__() == dc2.__hash__()) - dc1 = siepic.DirectionalCoupler(gap=2e-7, Lc=10e-6) + dc1 = siepic.DirectionalCoupler(gap=2.2e-7, Lc=0) dc2 = siepic.DirectionalCoupler() - assert not np.allclose(dc1.__hash__(), dc2.__hash__()) + assert (dc1.__hash__() != dc2.__hash__()) term1 = siepic.Terminator() term2 = siepic.Terminator() - assert np.allclose(term1.__hash__(), term2.__hash__()) - - term1 = siepic.Terminator(w1=5e-7) # this autocorrects to default attribute values everytime - term2 = siepic.Terminator() - assert not np.allclose(term1.__hash__(), term2.__hash__()) + assert (term1.__hash__() == term2.__hash__()) - # wg1 and wg2 hash should be the same wg1 = siepic.Waveguide(length=150e-6) wg2 = siepic.Waveguide(length=150e-6) - assert np.allclose(wg1.__hash__(), wg2.__hash__()) + assert (wg1.__hash__() == wg2.__hash__()) wg1 = siepic.Waveguide(length=150e-6) wg2 = siepic.Waveguide(length=50e-6) - assert not np.allclose(wg1.__hash__(), wg2.__hash__()) + assert (wg1.__hash__() != wg2.__hash__()) class TestSipannHash: def test_hash(self): - hr1siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) - hr2siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) - assert np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) + 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__()) - hr1siepic = sipann.HalfRing(gap=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7) - hr2siepic = sipann.HalfRing(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7) - assert not np.allclose(hr1siepic.__hash__(), hr2siepic.__hash__()) + hr1 = sipann.HalfRing(gap=1.5e-7, radius=10e-6, width=5.2e-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__()) - hra1siepic = sipann.HalfRacetrack(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=1e-7) - hra2siepic = sipann.HalfRacetrack(gap=1e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=1e-7) - assert np.allclose(hra1siepic.__hash__(), hra2siepic.__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__()) - hra1siepic = sipann.HalfRacetrack(gap=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7, length=1e-7) - hra2siepic = sipann.HalfRacetrack(gap=2e-7, radius=1e-5, width=5e-7, thickness=2.2e-7, length=2e-7) - assert not np.allclose(hra1siepic.__hash__(), hra2siepic.__hash__()) + hra1 = sipann.HalfRacetrack(gap=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7, length=1e-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 np.allclose(sc1.__hash__(), sc2.__hash__()) + assert (sc1.__hash__() == sc2.__hash__()) sc1 = sipann.StraightCoupler(width=5.8e-7, thickness=2e-7, gap=3e-7, length=2e-7) sc2 = sipann.StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-7) - assert not np.allclose(sc1.__hash__(), sc2.__hash__()) + 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 np.allclose(wg1.__hash__(), wg2.__hash__()) + assert (wg1.__hash__() == wg2.__hash__()) wg1 = sipann.Waveguide(length=150e-6, width=5e-7, thickness=2e-7) wg2 = sipann.Waveguide(length=50e-6, width=6e-7, thickness=2.3e-7) - assert not np.allclose(wg1.__hash__(), wg2.__hash__()) + 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 np.allclose(stcoup1.__hash__(), stcoup2.__hash__()) + assert (stcoup1.__hash__() == stcoup2.__hash__()) stcoup1 = sipann.Standard(width=5.8e-7, thickness=2.2e-7, gap=3e-7, length=9e-6, horizontal=2e-6, vertical=2e-6) stcoup2 = sipann.Standard(width=5e-7, thickness=2.3e-7, gap=2e-7, length=10e-6, horizontal=1e-6, vertical=1e-6) - assert not np.allclose(stcoup1.__hash__(), stcoup2.__hash__()) + 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 np.allclose(dhr1.__hash__(), dhr2.__hash__()) + assert (dhr1.__hash__() == dhr2.__hash__()) dhr1 = sipann.DoubleHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6, gap=3e-7) dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, gap=2e-7) - assert not np.allclose(dhr1.__hash__(), dhr2.__hash__()) + 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 np.allclose(ahr1.__hash__(), ahr2.__hash__()) + assert (ahr1.__hash__() == ahr2.__hash__()) ahr1 = sipann.AngledHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6, theta=50, gap=3e-7) ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, theta=45, gap=2e-7) - assert not np.allclose(ahr1.__hash__(), ahr2.__hash__()) + assert (ahr1.__hash__() != ahr2.__hash__()) From 4446369098db4193c617bcd1dcea4afac9b7db1a Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 22:06:09 -0400 Subject: [PATCH 20/30] Add SiPANN and numpy version to deps SiPANN needed for SiPANN hash tests. numpy version of at least 1.22 needed to avoid nlopt import issues (See here: https://githubhot.com/repo/stevengj/nlopt/issues/447) --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 903cca3b..c9486939 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = py37, py38, py39, py310 [testenv] deps = - numpy + numpy>=1.22 pytest scipy SiPANN From b68326c36c05f1f3ceb22d3262536434c1374c16 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 22:09:26 -0400 Subject: [PATCH 21/30] Update test_hash.py --- simphony/tests/test_hash.py | 1 + 1 file changed, 1 insertion(+) diff --git a/simphony/tests/test_hash.py b/simphony/tests/test_hash.py index f2015d9f..f0fc8dbd 100644 --- a/simphony/tests/test_hash.py +++ b/simphony/tests/test_hash.py @@ -5,6 +5,7 @@ from simphony.libraries import siepic from simphony.libraries import sipann + class TestSiepicHash: def test_hash(self): From db4cd993ac9cab73c850087032dae1ddcc36ba48 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Thu, 14 Apr 2022 22:12:11 -0400 Subject: [PATCH 22/30] Update tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index c9486939..903cca3b 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = py37, py38, py39, py310 [testenv] deps = - numpy>=1.22 + numpy pytest scipy SiPANN From b3d9000d6d22f86fb8d8bc8933cbdfa37f965939 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Fri, 15 Apr 2022 03:08:44 -0400 Subject: [PATCH 23/30] Add numpy version and remove py37 Python 3,8 is required to install numpy>=1.22.0, which is needed yo avoid nlopt import errors while attempting to import sipann. --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 903cca3b..b2759657 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [tox] -envlist = py37, py38, py39, py310 +envlist = py38, py39, py310 [testenv] deps = - numpy + numpy>=1.22 pytest scipy SiPANN From 1728617c8a0d082becca4a607d3e2d7bec41cc35 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Fri, 15 Apr 2022 03:09:25 -0400 Subject: [PATCH 24/30] Remove python version 3.7 Python 3.8+ is needed to install numpy>=1.22.0 --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index c9dc1db2..43e7f2b9 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.8', '3.9', '3.10'] name: build and test on: pull_request: From 3f1b19c00a25b1f8ba5e79c72fa16f531e5d6b1b Mon Sep 17 00:00:00 2001 From: Water drinker Date: Fri, 15 Apr 2022 15:46:59 -0400 Subject: [PATCH 25/30] Remove numpy version requirement --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index b2759657..903cca3b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [tox] -envlist = py38, py39, py310 +envlist = py37, py38, py39, py310 [testenv] deps = - numpy>=1.22 + numpy pytest scipy SiPANN From 284f228e2c876ab54bcc4bc63516c79ed1e0c95e Mon Sep 17 00:00:00 2001 From: Water drinker Date: Fri, 15 Apr 2022 15:47:04 -0400 Subject: [PATCH 26/30] Update build-and-test.yml --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 43e7f2b9..c9dc1db2 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ['3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10'] name: build and test on: pull_request: From b26f29e23629b09048cf9b75edc5e06dd6130795 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Tue, 19 Apr 2022 08:57:57 -0400 Subject: [PATCH 27/30] Temporarily disable SiPANN hash tests --- simphony/tests/test_hash.py | 90 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/simphony/tests/test_hash.py b/simphony/tests/test_hash.py index f0fc8dbd..a83bdea6 100644 --- a/simphony/tests/test_hash.py +++ b/simphony/tests/test_hash.py @@ -3,7 +3,7 @@ # (see simphony/__init__.py for details) from simphony.libraries import siepic -from simphony.libraries import sipann +# from simphony.libraries import sipann class TestSiepicHash: @@ -47,62 +47,62 @@ def test_hash(self): assert (wg1.__hash__() != wg2.__hash__()) -class TestSipannHash: +# class TestSipannHash: - def test_hash(self): +# 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=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=10e-6, width=5.2e-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__()) +# hr1 = sipann.HalfRing(gap=1.5e-7, radius=10e-6, width=5.2e-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=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=5.2e-7, thickness=2.1e-7, length=1e-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=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7, length=1e-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=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=3e-7, length=2e-7) - sc2 = sipann.StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-7) - assert (sc1.__hash__() != sc2.__hash__()) +# sc1 = sipann.StraightCoupler(width=5.8e-7, thickness=2e-7, gap=3e-7, length=2e-7) +# sc2 = sipann.StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-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=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=6e-7, thickness=2.3e-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=6e-7, thickness=2.3e-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=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=3e-7, length=9e-6, horizontal=2e-6, vertical=2e-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=3e-7, length=9e-6, horizontal=2e-6, vertical=2e-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__()) - 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=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=9e-6, gap=3e-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=9e-6, gap=3e-7) +# dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-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=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=9e-6, theta=50, gap=3e-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=9e-6, theta=50, gap=3e-7) +# ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, theta=45, gap=2e-7) +# assert (ahr1.__hash__() != ahr2.__hash__()) From 3e1c51661e6d1fb1ac67be2f3509e28f3c333caf Mon Sep 17 00:00:00 2001 From: Water drinker Date: Tue, 26 Apr 2022 01:24:27 -0400 Subject: [PATCH 28/30] Uncomment SiPANN hash tests --- simphony/tests/test_hash.py | 90 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/simphony/tests/test_hash.py b/simphony/tests/test_hash.py index a83bdea6..f0fc8dbd 100644 --- a/simphony/tests/test_hash.py +++ b/simphony/tests/test_hash.py @@ -3,7 +3,7 @@ # (see simphony/__init__.py for details) from simphony.libraries import siepic -# from simphony.libraries import sipann +from simphony.libraries import sipann class TestSiepicHash: @@ -47,62 +47,62 @@ def test_hash(self): assert (wg1.__hash__() != wg2.__hash__()) -# class TestSipannHash: +class TestSipannHash: -# def test_hash(self): + 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=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=10e-6, width=5.2e-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__()) + hr1 = sipann.HalfRing(gap=1.5e-7, radius=10e-6, width=5.2e-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=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=5.2e-7, thickness=2.1e-7, length=1e-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=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7, length=1e-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=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=3e-7, length=2e-7) -# sc2 = sipann.StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-7) -# assert (sc1.__hash__() != sc2.__hash__()) + sc1 = sipann.StraightCoupler(width=5.8e-7, thickness=2e-7, gap=3e-7, length=2e-7) + sc2 = sipann.StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-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=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=6e-7, thickness=2.3e-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=6e-7, thickness=2.3e-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=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=3e-7, length=9e-6, horizontal=2e-6, vertical=2e-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=3e-7, length=9e-6, horizontal=2e-6, vertical=2e-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__()) -# 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=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=9e-6, gap=3e-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=9e-6, gap=3e-7) + dhr2 = sipann.DoubleHalfRing(width=5e-7, thickness=2.3e-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=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=9e-6, theta=50, gap=3e-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=9e-6, theta=50, gap=3e-7) + ahr2 = sipann.AngledHalfRing(width=5e-7, thickness=2.3e-7, radius=1e-5, theta=45, gap=2e-7) + assert (ahr1.__hash__() != ahr2.__hash__()) From 10d252ec5fb722b0e0faa0290adf5e0a92b310e7 Mon Sep 17 00:00:00 2001 From: Water drinker Date: Sun, 22 May 2022 21:01:08 -0400 Subject: [PATCH 29/30] Remove unnecessary tests and add tests to test every parameter --- simphony/tests/test_hash.py | 180 +++++++++++++++++++++++++++------- simphony/tests/test_models.py | 6 -- 2 files changed, 142 insertions(+), 44 deletions(-) diff --git a/simphony/tests/test_hash.py b/simphony/tests/test_hash.py index f0fc8dbd..ffb167af 100644 --- a/simphony/tests/test_hash.py +++ b/simphony/tests/test_hash.py @@ -12,39 +12,55 @@ 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__()) + assert bdc1.__hash__() == bdc2.__hash__() - bdc1 = siepic.BidirectionalCoupler(2.1e-7) - bdc2 = siepic.BidirectionalCoupler(2.3e-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__()) + 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=8e-8, radius=10e-6, width=5.2e-7, thickness=2.1e-7) + 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) - assert (hr1siepic.__hash__() != hr2siepic.__hash__()) + assert hr1siepic.__hash__() != hr2siepic.__hash__() dc1 = siepic.DirectionalCoupler() dc2 = siepic.DirectionalCoupler() - assert (dc1.__hash__() == dc2.__hash__()) + assert dc1.__hash__() == dc2.__hash__() - dc1 = siepic.DirectionalCoupler(gap=2.2e-7, Lc=0) + dc1 = siepic.DirectionalCoupler(Lc=0) dc2 = siepic.DirectionalCoupler() - assert (dc1.__hash__() != dc2.__hash__()) + assert dc1.__hash__() != dc2.__hash__() term1 = siepic.Terminator() term2 = siepic.Terminator() - assert (term1.__hash__() == term2.__hash__()) + assert term1.__hash__() == term2.__hash__() wg1 = siepic.Waveguide(length=150e-6) wg2 = siepic.Waveguide(length=150e-6) - assert (wg1.__hash__() == wg2.__hash__()) + assert wg1.__hash__() == wg2.__hash__() wg1 = siepic.Waveguide(length=150e-6) wg2 = siepic.Waveguide(length=50e-6) - assert (wg1.__hash__() != wg2.__hash__()) + 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: @@ -53,56 +69,144 @@ 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__()) + 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=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7) + 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__()) + 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__()) + 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=1.5e-7, radius=10e-6, width=5.2e-7, thickness=2.1e-7, length=1e-7) + 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__()) + 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__()) + 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=5.8e-7, thickness=2e-7, gap=3e-7, length=2e-7) - sc2 = sipann.StraightCoupler(width=5e-7, thickness=2.3e-7, gap=2e-7, length=1e-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__()) + assert wg1.__hash__() == wg2.__hash__() wg1 = sipann.Waveguide(length=150e-6, width=5e-7, thickness=2e-7) - wg2 = sipann.Waveguide(length=50e-6, width=6e-7, thickness=2.3e-7) - assert (wg1.__hash__() != wg2.__hash__()) + 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__()) + assert stcoup1.__hash__() == stcoup2.__hash__() - stcoup1 = sipann.Standard(width=5.8e-7, thickness=2.2e-7, gap=3e-7, length=9e-6, horizontal=2e-6, vertical=2e-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__()) + assert dhr1.__hash__() == dhr2.__hash__() - dhr1 = sipann.DoubleHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6, gap=3e-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__()) + assert ahr1.__hash__() == ahr2.__hash__() - ahr1 = sipann.AngledHalfRing(width=5.8e-7, thickness=2.2e-7, radius=9e-6, theta=50, gap=3e-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__() diff --git a/simphony/tests/test_models.py b/simphony/tests/test_models.py index e25fec06..de9a0952 100644 --- a/simphony/tests/test_models.py +++ b/simphony/tests/test_models.py @@ -88,17 +88,11 @@ def s_parameters(self, freqs): return self.y1.s_parameters(freqs) brancher = YBranch() - brancher2 = YBranch() - brancher3 = YBranch() - brancher3.pin_count = 2 brancher.multiconnect(wg1, wg2, wg3) assert brancher.circuit == wg1.circuit assert wg1.circuit == wg2.circuit assert wg2.circuit == wg3.circuit - assert brancher.__hash__() == brancher2.__hash__() - assert brancher.__hash__() != brancher3.__hash__() - class TestSubcircuitExtension: def test_subcircuit_factory(self, y1, wg1, wg2, wg3): From 4dcdf4b65f0d8f5703dacffc49d861950b3e1b1e Mon Sep 17 00:00:00 2001 From: Water drinker Date: Sun, 22 May 2022 21:06:37 -0400 Subject: [PATCH 30/30] Fix linting errors --- simphony/tests/test_models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/simphony/tests/test_models.py b/simphony/tests/test_models.py index de9a0952..01cdd5b8 100644 --- a/simphony/tests/test_models.py +++ b/simphony/tests/test_models.py @@ -94,6 +94,7 @@ def s_parameters(self, freqs): assert wg1.circuit == wg2.circuit assert wg2.circuit == wg3.circuit + class TestSubcircuitExtension: def test_subcircuit_factory(self, y1, wg1, wg2, wg3): def create_brancher(y1, wg1, wg2):