def test_qgeometry_q_element_get_component(self):
        """Test get_component in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        qgt.clear_all_tables()
        TransmonPocket(design, 'Q1')

        rect = draw.rectangle(500, 300, 0, 0)
        geom = {'my_polygon': rect}
        qgt.add_qgeometry('poly', 'Q1', geom)

        # success results
        actual = qgt.get_component('Q1')
        self.assertEqual(len(actual), 3)
        self.assertTrue(isinstance(actual['path'], GeoDataFrame))
        self.assertTrue(isinstance(actual['poly'], GeoDataFrame))
        self.assertTrue(isinstance(actual['junction'], GeoDataFrame))

        # failure results
        actual = qgt.get_component('not-real')
        self.assertEqual(len(actual), 3)
        self.assertEqual(actual['path'], None)
        self.assertEqual(actual['poly'], None)
        self.assertEqual(actual['junction'], None)
 def test_qgeometry_instantiate_q_geometry_tables(self):
     """Test instantiation of QGeometryTables."""
     try:
         design = designs.DesignPlanar()
         QGeometryTables(design)
     except Exception:
         self.fail("QGeometryTables failed")
    def test_qgeometry_q_element_delete_component_id(self):
        """Test delete_component_id in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        qgt.clear_all_tables()

        transmon_pocket = TransmonPocket(design, 'my_id')
        transmon_pocket.make()
        transmon_pocket.get_template_options(design)
        a_linestring = draw.LineString([[0, 0], [0, 1]])
        a_poly = draw.rectangle(2, 2, 0, 0)
        qgt.add_qgeometry('path',
                          'my_id', {'n_sprial': a_linestring},
                          width=4000)
        qgt.add_qgeometry('poly',
                          'my_id', {'n_spira_etch': a_poly},
                          subtract=True)

        self.assertEqual(len(qgt.tables['path']), 1)
        self.assertEqual(len(qgt.tables['poly']), 1)

        qgt.delete_component_id('my_id')

        self.assertEqual(len(qgt.tables['path']), 0)
        self.assertEqual(len(qgt.tables['poly']), 0)
    def test_qgeometry_q_element_create_tables(self):
        """Test create_tables in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        qgt.create_tables()

        actual = qgt.tables

        self.assertEqual(len(actual), 3)
        self.assertTrue('path' in actual)
        self.assertTrue('poly' in actual)
        self.assertTrue('junction' in actual)

        self.assertEqual(actual['path'].dtypes['component'], object)
        self.assertEqual(actual['path'].dtypes['name'], object)
        self.assertEqual(actual['path'].dtypes['subtract'], bool)
        self.assertEqual(actual['path'].dtypes['helper'], bool)
        self.assertEqual(actual['path'].dtypes['chip'], object)
        self.assertEqual(actual['path'].dtypes['fillet'], object)

        self.assertEqual(actual['poly'].dtypes['component'], object)
        self.assertEqual(actual['poly'].dtypes['name'], object)
        self.assertEqual(actual['poly'].dtypes['subtract'], bool)
        self.assertEqual(actual['poly'].dtypes['helper'], bool)
        self.assertEqual(actual['poly'].dtypes['chip'], object)
        self.assertEqual(actual['poly'].dtypes['fillet'], object)

        self.assertEqual(actual['junction'].dtypes['component'], object)
        self.assertEqual(actual['junction'].dtypes['name'], object)
        self.assertEqual(actual['junction'].dtypes['subtract'], bool)
        self.assertEqual(actual['junction'].dtypes['helper'], bool)
        self.assertEqual(actual['junction'].dtypes['chip'], object)
        self.assertEqual(actual['junction'].dtypes['width'], float)
    def test_qgeometry_q_element_add_renderer_extension(self):
        """Test add_renderer_extension in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        qgt.add_renderer_extension(
            'new_name',
            dict(base=dict(color=str, klayer=int),
                 path=dict(thickness=float),
                 poly=dict(material=str)))

        e_c = qgt.ELEMENT_COLUMNS

        self.assertTrue('color' in e_c['base']['__renderers__']['new_name'])
        self.assertTrue('klayer' in e_c['base']['__renderers__']['new_name'])
        self.assertTrue('thickness' in e_c['path']['__renderers__']['new_name'])
        self.assertTrue('material' in e_c['poly']['__renderers__']['new_name'])

        self.assertEqual(e_c['base']['__renderers__']['new_name']['color'], str)
        self.assertEqual(e_c['base']['__renderers__']['new_name']['klayer'],
                         int)
        self.assertEqual(e_c['path']['__renderers__']['new_name']['thickness'],
                         float)
        self.assertEqual(e_c['poly']['__renderers__']['new_name']['material'],
                         str)
    def test_qgeometry_q_element_get_rname(self):
        """Test get_rname in QGeometryTables class in element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)

        actual = qgt.get_rname('some_name', 'aloha')

        self.assertEqual(actual, 'some_name_aloha')
    def test_qgeometry_q_element_constants(self):
        """Test that constants in QGeometryTables class in element_handler.py
        were not accidentally changed."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)

        self.assertEqual(qgt.__i_am_qgeometry_table__, True)
        self.assertEqual(qgt.name_delimiter, '_')
    def test_qgeometry_q_element_check_element_type(self):
        """Test check_element_type in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        TransmonPocket(design, 'my_id')

        self.assertTrue(qgt.check_element_type('path', log_issue=False))
        self.assertFalse(qgt.check_element_type('not-there', log_issue=False))
    def test_qgeometry_q_element_get_component_bounds(self):
        """Test get_component_bounds in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        qgt.clear_all_tables()
        TransmonPocket(design, 'my_id')

        four_zeros = qgt.get_component_bounds('my_id')
        self.assertEqual(len(four_zeros), 4)
        for i in range(4):
            self.assertEqual(four_zeros[i], 0)
    def test_qgeometry_q_element_get_element_types(self):
        """Test get_element_types in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)

        expected = ['path', 'poly', 'junction']
        actual = qgt.get_element_types()

        self.assertEqual(len(expected), len(actual))
        for i in range(3):
            self.assertEqual(expected[i], actual[i])
    def test_qgeometry_q_element_clear_all_tables(self):
        """Test clear_all_tables in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        qgt.clear_all_tables()

        # add something to the tables to check for after clear
        a_poly = draw.rectangle(2, 2, 0, 0)
        qgt.add_qgeometry('poly', 'my_id', dict(cl_metal=a_poly))

        qgt.clear_all_tables()
        self.assertEqual(len(qgt.tables['poly'].geometry), 0)
    def test_qgeometry_get_all_unique_layers(self):
        """Test get_all_unique_layers functionality in elment_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        qgt.clear_all_tables()

        transmon_pocket = TransmonPocket(design, 'my_id')
        transmon_pocket.make()
        transmon_pocket.get_template_options(design)
        a_linestring = draw.LineString([[0, 0], [0, 1]])
        a_poly = draw.rectangle(2, 2, 0, 0)
        qgt.add_qgeometry('path',
                          'my_id', {'n_sprial': a_linestring},
                          width=4000)
        qgt.add_qgeometry('poly',
                          'my_id', {'n_spira_etch': a_poly},
                          subtract=True)

        self.assertEqual(qgt.get_all_unique_layers('main'), [1])
        self.assertEqual(qgt.get_all_unique_layers('fake'), [])
    def test_qgeometry_q_element_add_qgeometry(self):
        """Test add_qgeometry in QGeometryTables class in
        element_handler.py."""
        design = designs.DesignPlanar()
        qgt = QGeometryTables(design)
        qgt.clear_all_tables()

        a_poly = draw.rectangle(2, 2, 0, 0)
        qgt.add_qgeometry('poly', 'my_id', dict(cl_metal=a_poly))
        table = qgt.tables

        self.assertTrue('poly' in table)
        self.assertEqual(table['poly']['component'][0], 'my_id')
        self.assertEqual(table['poly']['name'][0], 'cl_metal')
        self.assertEqual(table['poly']['geometry'][0], a_poly)
        self.assertEqual(table['poly']['layer'][0], 1)
        self.assertEqual(table['poly']['subtract'][0], False)
        self.assertEqual(table['poly']['helper'][0], False)
        self.assertEqual(table['poly']['chip'][0], 'main')
        self.assertEqual(str(table['poly']['fillet'][0]), str(np.nan))
Beispiel #14
0
    def test_renderer_get_chip_names(self):
        """Test functionality of get_chip_names in gds_renderer.py."""
        design = designs.DesignPlanar()
        renderer = QGDSRenderer(design)

        qgt = QGeometryTables(design)
        qgt.clear_all_tables()

        transmon_pocket_1 = TransmonPocket(design, 'my_id')
        transmon_pocket_1.make()
        transmon_pocket_1.get_template_options(design)

        a_linestring = draw.LineString([[0, 0], [0, 1]])
        a_poly = draw.rectangle(2, 2, 0, 0)
        qgt.add_qgeometry('path',
                          'my_id', {'n_sprial': a_linestring},
                          width=4000)
        qgt.add_qgeometry('poly',
                          'my_id', {'n_spira_etch': a_poly},
                          subtract=True)

        result = renderer._get_chip_names()
        self.assertEqual(result, {'main': {}})
Beispiel #15
0
    def __init__(self,
                 metadata: dict = None,
                 overwrite_enabled: bool = False,
                 enable_renderers: bool = True):
        """Create a new Metal QDesign.

        Arguments:
            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()