예제 #1
0
    def test_design_interface_components_find_id(self):
        """Test finding the id from the name in interface_components.py."""
        design = DesignPlanar(metadata={})
        QComponent(design, 'my_name-1', make=False)
        QComponent(design, 'my_name-2', make=False)
        components = Components(design)

        self.assertEqual(components.find_id('my_name-1'), 1)
        self.assertEqual(components.find_id('my_name-2'), 2)
        self.assertEqual(components.find_id('my_name-3'), 0)
예제 #2
0
    def test_design_interface_components_get_list_ints(self):
        """Test geting the list ints in interface_components.py."""
        design = DesignPlanar(metadata={})
        QComponent(design, 'my_name-1', make=False)
        QComponent(design, 'my_name-2', make=False)
        components = Components(design)

        self.assertListEqual(components.get_list_ints(['my_name-1']), [1])
        self.assertListEqual(
            components.get_list_ints(['my_name-1', 'my_name-2']), [1, 2])
        self.assertListEqual(
            components.get_list_ints(['my_name-1', 'my_name-2', 'nope']),
            [1, 2, 0])
예제 #3
0
 def test_design_instantiate_design_components(self):
     """Test the instantiation of Components."""
     design = QDesign()
     try:
         Components(design)
     except Exception:
         self.fail("Components(design) failed")
예제 #4
0
    def test_design_qnet_delete_all_pins_for_component_id(self):
        """Test delete all pins for a given component id in net_info.py."""
        design = DesignPlanar(metadata={})
        QComponent(design, 'my_name-1', make=False)
        QComponent(design, 'my_name-2', make=False)
        QComponent(design, 'my_name-3', make=False)
        QComponent(design, 'my_name-4', make=False)
        Components(design)
        qnet = QNet()

        qnet.add_pins_to_table(1, 'my_name-1', 2, 'my_name-2')
        qnet.add_pins_to_table(3, 'my_name-3', 4, 'my_name-4')
        qnet.delete_all_pins_for_component(2)
        df = qnet.net_info

        data = {
            'net_id': [2, 2],
            'component_id': [3, 4],
            'pin_name': ['my_name-3', 'my_name-4']
        }
        df_expected = pd.DataFrame(data, index=[2, 3])

        self.assertEqual(len(df), len(df_expected))
        for i in [2, 3]:
            for j in ['net_id', 'component_id', 'pin_name']:
                self.assertEqual(df_expected[j][i], df[j][i])
예제 #5
0
    def test_design_qnet_add_pins_to_table(self):
        """
        Test add_pins_to_table in net_info.py.
        """
        design = DesignPlanar(metadata={})
        QComponent(design, 'my_name-1', make=False)
        QComponent(design, 'my_name-2', make=False)
        Components(design)
        qnet = QNet()

        qnet.add_pins_to_table(1, 'my_name-1', 2, 'my_name-2')
        df = qnet.net_info

        data = {
            'net_id': [1, 1],
            'component_id': [1, 2],
            'pin_name': ['my_name-1', 'my_name-2']
        }
        df_expected = pd.DataFrame(data, index=[0, 1])

        self.assertEqual(len(df), len(df_expected))
        data_points = df_expected['net_id'].size
        for i in range(data_points):
            for j in ['net_id', 'component_id', 'pin_name']:
                self.assertEqual(df_expected[j][i], df[j][i])
예제 #6
0
    def test_design_qnet_delete_net_id(self):
        """Test delete a given net id in net_info.py."""
        design = DesignPlanar(metadata={})
        QComponent(design, 'my_name-1', make=False)
        QComponent(design, 'my_name-2', make=False)
        Components(design)
        qnet = QNet()

        net_id = qnet.add_pins_to_table(1, 'my_name-1', 2, 'my_name-2')
        qnet.delete_net_id(net_id)
        df = qnet.net_info
        self.assertEqual(df.empty, True)
예제 #7
0
    def test_design_qnet_get_components_and_pins_for_netid(self):
        """
        Test get_components_Sand_pins_for_netid in net_info.py.
        """
        design = DesignPlanar(metadata={})
        QComponent(design, 'my_name-1', make=False)
        QComponent(design, 'my_name-2', make=False)
        QComponent(design, 'my_name-3', make=False)
        QComponent(design, 'my_name-4', make=False)
        Components(design)
        qnet = QNet()

        net_id_1 = qnet.add_pins_to_table(1, 'my_name-1', 2, 'my_name-2')
        net_id_2 = qnet.add_pins_to_table(3, 'my_name-3', 4, 'my_name-4')

        data = {
            'net_id': [1, 1],
            'component_id': [1, 2],
            'pin_name': ['my_name-1', 'my_name-2']
        }
        df_expected_1 = pd.DataFrame(data, index=[0, 1])

        data = {
            'net_id': [2, 2],
            'component_id': [3, 4],
            'pin_name': ['my_name-3', 'my_name-4']
        }
        df_expected_2 = pd.DataFrame(data, index=[2, 3])

        df = qnet.get_components_and_pins_for_netid(net_id_1)
        self.assertEqual(len(df), len(df_expected_1))
        data_points = df_expected_1['net_id'].size
        for i in range(data_points):
            for j in ['net_id', 'component_id', 'pin_name']:
                self.assertEqual(df_expected_1[j][i], df[j][i])

        df = qnet.get_components_and_pins_for_netid(net_id_2)
        self.assertEqual(len(df), len(df_expected_2))
        for i in [2, 3]:
            for j in ['net_id', 'component_id', 'pin_name']:
                self.assertEqual(df_expected_2[j][i], df[j][i])
예제 #8
0
    def __init__(self,
                 metadata: dict = None,
                 overwrite_enabled: bool = False,
                 enable_renderers: bool = True):
        """Create a new Metal QDesign.

        Args:
            metadata (Dict): Dictionary of metadata.  Defaults to None.

            overwrite_enabled (bool): When True - If the string name, used for component, already
                            exists in the design, the existing component will be
                            deleted from design, and new component will be generated
                            with the same name and newly generated component_id,
                            and then added to design.
                        When False - If the string name, used for component, already
                            exists in the design, the existing component will be
                            kept in the design, and current component will not be generated,
                            nor will be added to the design. The 'NameInUse' will be returned
                            during component generation.
                        Either True or False - If string name, used for component, is NOT
                            being used in the design, a component will be generated and
                            added to design using the name.

            enable_renderers: Enable the renderers during the init() of design.
                        The list in config.renderers_to_load() to determine
                        which renderers to enable.
        """

        # _qcomponent_latest_assigned_id -- Used to keep a tally and ID of all components within an
        # instantiation of a design.
        # A qcomponent is added to a design by base._add_to_design with init of a qcomponent.
        # During init of component, design class provides an unique id for each instance of
        # component being added to design.  Note, if a component is removed from the design,
        # the ID of removed component should not be used again.  However, if a component is
        # renamed with an unique name, then the ID should continute to be used.
        self._qcomponent_latest_assigned_id = 0

        # Dictionary that keeps the latest ID for each unique type of component
        self._qcomponent_latest_name_id = Dict()

        # Key attributes related to physical content of the design. These will be saved

        # Where components are actually stored.
        # i.e.  key=id and part of value (_components[id].name)
        self._components = Dict()

        # User-facing interface for user to view components by using name (str) for key access to
        # QComponents, instead of id (int).
        self.components = Components(self)

        self.overwrite_enabled = overwrite_enabled

        # Cache for component ids.  Hold the reverse of _components dict,
        self.name_to_id = Dict()

        self._variables = Dict()
        self._chips = Dict()

        self._metadata = self._init_metadata()
        if metadata:
            self.update_metadata(metadata)

        self.save_path = None  # type: str

        self.logger = logger  # type: logging.Logger
        self.build_logs = LogStore("Build Logs", 30)

        self._qgeometry = QGeometryTables(self)

        # Used for QComponents, and QRenderers
        self._template_options = DefaultMetalOptions()

        self.variables.update(self.template_options.qdesign.variables)

        # Can't really use this until DefaultOptionsRenderer.default_draw_substrate.color_plane
        # is resolved.
        # Presently, self._template_options holds the templates_options for each renderers.
        # key is the unique name of renderer.
        # Also, renderer_base.options holds the latest options for each instance
        # of renderer.
        self._template_renderer_options = DefaultOptionsRenderer(
        )  # use for renderer

        self._qnet = QNet()

        # Dict used to populate the columns of QGeometry table i.e. path,
        # junction, poly etc.
        self.renderer_defaults_by_table = Dict()

        # Instantiate and register renderers to Qdesign.renderers
        self._renderers = Dict()
        if enable_renderers:
            self._start_renderers()

        # Take out of the QGeometryTables init().
        # Add add_renderer_extension() during renderer's init().
        # Need to add columns to Junction tables before create_tables().
        self._qgeometry.create_tables()

        # Assign unique name to this design
        self.name = self._assign_name_design()