Skip to content

Commit

Permalink
🐍 Added test for issue #667
Browse files Browse the repository at this point in the history
  • Loading branch information
wlambooy committed Feb 13, 2025
1 parent e260038 commit bf1c28b
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import os
import unittest

from mnt.pyfiction import (
automatic_base_number_detection,
charge_distribution_surface_100,
charge_distribution_surface_111,
groundstate_from_simulation_result,
offset_coordinate,
quickexact,
quickexact_params,
read_sqd_layout_100,
sidb_100_lattice,
sidb_111_lattice,
sidb_charge_state,
sidb_simulation_parameters,
sidb_technology,
)

dir_path = os.path.dirname(os.path.realpath(__file__))

class TestQuickExact(unittest.TestCase):
def test_three_sidbs(self):
Expand Down Expand Up @@ -75,6 +80,55 @@ def test_perturber_and_sidb_pair_111(self):
self.assertEqual(groundstate[0].get_charge_state((2, 0)), sidb_charge_state.NEUTRAL)
self.assertEqual(groundstate[0].get_charge_state((3, 0)), sidb_charge_state.NEGATIVE)

def test_simulate_all_inputs_of_and_gate(self):
and_gate = read_sqd_layout_100(dir_path + "/../../../resources/and_v0.sqd")
physical_parameters = sidb_simulation_parameters()
physical_parameters.base = 2
physical_parameters.epsilon_r = 5.6
physical_parameters.lambda_tf = 5.0 # (nm)
physical_parameters.mu_minus = -0.25 # (eV) (energy threshold to change the charge state of a negatively charged SiDB to a neutrally charged SiDB)
quickexact_parameter = quickexact_params()
quickexact_parameter.simulation_parameters = physical_parameters

# input 00
and_gate.assign_cell_type(offset_coordinate(2, 2),
sidb_technology.cell_type.EMPTY) # delete one SiDB of the input BDL pair
and_gate.assign_cell_type(offset_coordinate(24, 2),
sidb_technology.cell_type.EMPTY) # delete one SiDB of the input BDL pair

self.assertTrue(len(quickexact(and_gate, quickexact_parameter).charge_distributions) > 0)

and_gate.assign_cell_type(offset_coordinate(2, 2),
sidb_technology.cell_type.INPUT) # add SiDB of the input BDL pair again to have the original layout
and_gate.assign_cell_type(offset_coordinate(24, 2),
sidb_technology.cell_type.INPUT) # add SiDB of the input BDL pair again to have the original layout

# input 01
and_gate.assign_cell_type(offset_coordinate(2, 2), sidb_technology.cell_type.EMPTY)
and_gate.assign_cell_type(offset_coordinate(26, 0), sidb_technology.cell_type.EMPTY)

self.assertTrue(len(quickexact(and_gate, quickexact_parameter).charge_distributions) > 0)

and_gate.assign_cell_type(offset_coordinate(2, 2), sidb_technology.cell_type.INPUT)
and_gate.assign_cell_type(offset_coordinate(26, 0), sidb_technology.cell_type.INPUT)

# input 10
and_gate.assign_cell_type(offset_coordinate(0, 0), sidb_technology.cell_type.EMPTY)
and_gate.assign_cell_type(offset_coordinate(24, 2), sidb_technology.cell_type.EMPTY)

self.assertTrue(len(quickexact(and_gate, quickexact_parameter).charge_distributions) > 0)

and_gate.assign_cell_type(offset_coordinate(0, 0), sidb_technology.cell_type.INPUT)
and_gate.assign_cell_type(offset_coordinate(24, 2), sidb_technology.cell_type.INPUT)

# input 11
and_gate.assign_cell_type(offset_coordinate(0, 0), sidb_technology.cell_type.EMPTY)
and_gate.assign_cell_type(offset_coordinate(26, 0), sidb_technology.cell_type.EMPTY)

self.assertTrue(len(quickexact(and_gate, quickexact_parameter).charge_distributions) > 0)

and_gate.assign_cell_type(offset_coordinate(0, 0), sidb_technology.cell_type.INPUT)
and_gate.assign_cell_type(offset_coordinate(26, 0), sidb_technology.cell_type.INPUT)

if __name__ == "__main__":
unittest.main()
164 changes: 164 additions & 0 deletions bindings/mnt/pyfiction/test/resources/and_v0.sqd
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<siqad>
<!--Program Flags-->
<program>
<file_purpose>save</file_purpose>
<version>0.3.3</version>
<date>2023-12-05 12:31:27</date>
</program>
<!--GUI Flags-->
<gui>
<zoom>0.0304945</zoom>
<displayed_region x1="-171.506" y1="-49.1892" x2="297.431" y2="147.896"/>
<scroll x="-138" y="-511"/>
</gui>
<!--Layer Properties-->
<!--Layer ID is intrinsic to the layer order-->
<layers>
<layer_prop>
<name>Lattice</name>
<type>Lattice</type>
<role>Design</role>
<zoffset>0</zoffset>
<zheight>0</zheight>
<visible>1</visible>
<active>0</active>
<lat_vec>
<a1 x="3.84" y="0"/>
<a2 x="0" y="7.68"/>
<N>2</N>
<b1 x="0" y="0"/>
<b2 x="0" y="2.25"/>
</lat_vec>
</layer_prop>
<layer_prop>
<name>Screenshot Overlay</name>
<type>Misc</type>
<role>Overlay</role>
<zoffset>0</zoffset>
<zheight>0</zheight>
<visible>1</visible>
<active>0</active>
</layer_prop>
<layer_prop>
<name>Surface</name>
<type>DB</type>
<role>Design</role>
<zoffset>0</zoffset>
<zheight>0</zheight>
<visible>1</visible>
<active>0</active>
</layer_prop>
<layer_prop>
<name>Metal</name>
<type>Electrode</type>
<role>Design</role>
<zoffset>1000</zoffset>
<zheight>100</zheight>
<visible>1</visible>
<active>0</active>
</layer_prop>
</layers>
<!--Item Hierarchy-->
<design>
<!--Lattice-->
<layer type="Lattice"/>
<!--Screenshot Overlay-->
<layer type="Misc"/>
<!--Surface-->
<layer type="DB">
<dbdot>
<layer_id>2</layer_id>
<latcoord n="26" m="0" l="0"/>
<type>input</type>
<physloc x="99.84" y="0"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="0" m="0" l="0"/>
<type>input</type>
<physloc x="0" y="0"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="2" m="1" l="0"/>
<type>input</type>
<physloc x="7.68" y="7.68"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="24" m="1" l="0"/>
<type>input</type>
<physloc x="92.16" y="7.68"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="20" m="14" l="0"/>
<type>output</type>
<physloc x="76.8" y="107.52"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="15" m="11" l="0"/>
<physloc x="57.6" y="84.48"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="9" m="7" l="0"/>
<physloc x="34.56" y="53.76"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="20" m="2" l="0"/>
<physloc x="76.8" y="15.36"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="13" m="9" l="0"/>
<physloc x="49.92" y="69.12"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="18" m="13" l="0"/>
<type>output</type>
<physloc x="69.12" y="99.84"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="24" m="15" l="0"/>
<physloc x="92.16" y="115.2"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="18" m="3" l="0"/>
<physloc x="69.12" y="23.04"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="6" m="2" l="0"/>
<physloc x="23.04" y="15.36"/>
<color>#ffc8c8c8</color>
</dbdot>
<dbdot>
<layer_id>2</layer_id>
<latcoord n="8" m="3" l="0"/>
<physloc x="30.72" y="23.04"/>
<color>#ffc8c8c8</color>
</dbdot>
</layer>
<!--Metal-->
<layer type="Electrode"/>
</design>
</siqad>

0 comments on commit bf1c28b

Please sign in to comment.