Esempio n. 1
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])
Esempio n. 2
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])
Esempio n. 3
0
    def test_component_instantiate_qcomponent(self):
        """Test the instantiaion of QComponent."""
        design = designs.DesignPlanar()
        try:
            QComponent
        except Exception:
            self.fail("QComponent failed")

        with self.assertRaises(NotImplementedError):
            QComponent(design, "my_name")

        with self.assertRaises(NotImplementedError):
            QComponent(design, "my_name2", options={})

        try:
            QComponent(design, "my_name3", options={}, make=False)
        except Exception:
            self.fail(
                "QComponent(design, \"my_name3\", options={}, make=False)")

        try:
            QComponent(design,
                       "my_name4",
                       options={},
                       make=False,
                       component_template={})
        except Exception:
            msg = "QComponent(design, \"my_name4\", options={}, make=False, component_template={})"
            self.fail(msg)
Esempio n. 4
0
    def test_design_get_new_qcomponent_name_id(self):
        """Test _get_new_qcomponent_name_id in design_base.py."""
        design = DesignPlanar(metadata={})
        QComponent(design, make=False)
        QComponent(design, make=False)

        self.assertEqual(design._get_new_qcomponent_name_id('QComponent'), 3)
        self.assertEqual(design._get_new_qcomponent_name_id('Not-there'), 1)
Esempio n. 5
0
    def test_design_delete_all_components(self):
        """Test deleteing a component in design_base.py."""
        design = DesignPlanar(metadata={})
        QComponent(design, 'my_name-1', make=False)
        QComponent(design, 'my_name-2', make=False)

        design.delete_all_components()
        self.assertEqual('my_name-1' in design.name_to_id, False)
        self.assertEqual('my_name-2' in design.name_to_id, False)
Esempio n. 6
0
    def test_component_get_and_set_qcomponent_name(self):
        """Test the getting and setting of a QComponent name."""
        design = designs.DesignPlanar()
        my_qcomponent_local = None

        my_qcomponent_local = QComponent(design, "my_name", make=False)
        self.assertEqual(my_qcomponent_local.name, "my_name")

        my_qcomponent_local.name = "another-name"
        self.assertEqual(my_qcomponent_local.name, "another-name")
Esempio n. 7
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)
Esempio n. 8
0
    def test_design_rename_component(self):
        """Test renaming component in design_base.py."""
        design = DesignPlanar(metadata={})
        QComponent(design, 'my_name-1', make=False)
        QComponent(design, 'my_name-2', make=False)

        design.rename_component('my_name-1', 'new-name')

        self.assertEqual('new-name' in design.name_to_id, True)
        self.assertEqual('my_name-1' in design.name_to_id, False)
        self.assertEqual('my_name-2' in design.name_to_id, True)
Esempio n. 9
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)
Esempio n. 10
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])
Esempio n. 11
0
    def test_design_planar_get_x_y_for_chip(self):
        """Test get_x_y_for_chip in design_planar.py."""
        design = DesignPlanar(metadata={})
        QComponent(design, make=False)
        QComponent(design, make=False)

        expected = ((-4.5, -3.0, 4.5, 3.0), 0)
        actual = design.get_x_y_for_chip('main')

        self.assertEqual(len(expected), len(actual))
        self.assertEqual(len(expected[0]), len(actual[0]))
        for i in range(4):
            self.assertEqual(expected[0][i], actual[0][i])

        self.assertEqual(expected[1], actual[1])
Esempio n. 12
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])
Esempio n. 13
0
    def test_component_base_get_template_options(self):
        """Test get_template_options in base.py."""
        design = designs.DesignPlanar()

        self.assertEqual(QComponent.get_template_options(design), {})

        expected = {
            'pos_x': '0um',
            'pos_y': '0um',
            'connection_pads': {},
            '_default_connection_pads': {}
        }
        self.assertEqual(BaseQubit.get_template_options(design), expected)
    def test_component_qcomponent_add_and_get_pin(self):
        """
        Test getting a pin by name.
        """
        design = designs.DesignPlanar()
        my_q_component = QComponent(design, "my_name-get-pin", make=False)

        spiral_list_0 = self.generate_spiral_list(0, 0)
        spiral_list_1 = self.generate_spiral_list(1, 2)

        my_q_component.add_pin('pin1-name',
                               np.array(spiral_list_0.coords)[-2:], 0.1)
        my_q_component.add_pin('pin2-name',
                               np.array(spiral_list_1.coords)[-2:], 0.1)

        my_pin = my_q_component.get_pin('pin2-name')
        self.assertEqual(len(my_pin), 10)
        self.assertEqual(len(my_pin['points']), 2)
        self.assertEqual(len(my_pin['points'][0]), 2)
        self.assertEqual(len(my_pin['points'][1]), 2)
        self.assertEqual(my_pin['points'][0][0], -34.)
        self.assertEqual(my_pin['points'][0][1], 32.)
        self.assertEqual(my_pin['points'][1][0], -34.)
        self.assertEqual(my_pin['points'][1][1], -33.)
        self.assertEqual(len(my_pin['middle']), 2)
        self.assertEqual(my_pin['middle'][0], -34.)
        self.assertEqual(my_pin['middle'][1], -0.5)
        self.assertEqual(len(my_pin['normal']), 2)
        self.assertEqual(my_pin['normal'][0], 1.)
        self.assertEqual(my_pin['normal'][1], -0.)
        self.assertEqual(len(my_pin['tangent']), 2)
        self.assertEqual(my_pin['tangent'][0], 0.)
        self.assertEqual(my_pin['tangent'][1], -1.)
        self.assertEqual(my_pin['width'], 65.0)
        self.assertEqual(my_pin['gap'], 0.06)
        self.assertEqual(my_pin['chip'], 'main')
        self.assertEqual(my_pin['parent_name'], 1)
        self.assertEqual(my_pin['net_id'], 0)
        self.assertEqual(my_pin['length'], 0)
        my_q_component.delete()
Esempio n. 15
0
    def test_component_qcomponent_get_pin_names(self):
        """Test getting all the pin names."""
        design = designs.DesignPlanar()
        my_q_component = QComponent(design,
                                    "my_name-get-pin-names",
                                    make=False)

        spiral_list_0 = self.generate_spiral_list(0, 0)
        spiral_list_1 = self.generate_spiral_list(1, 2)

        my_q_component.add_pin('pin1-name',
                               np.array(spiral_list_0.coords)[-2:], 0.1)
        my_q_component.add_pin('pin2-name',
                               np.array(spiral_list_1.coords)[-2:], 0.1)

        my_pin_names = list(my_q_component.pin_names)
        my_pin_names.sort()
        self.assertEqual(len(my_pin_names), 2)
        self.assertEqual(my_pin_names[0], 'pin1-name')
        self.assertEqual(my_pin_names[1], 'pin2-name')
        my_q_component.delete()
Esempio n. 16
0
    def test_design_default_component_name(self):
        """Test automatic naming of components."""
        design = DesignPlanar(metadata={})

        ResonatorRectangleSpiral(design, make=False)
        self.assertEqual('res_1' in design.components, True)
        ResonatorRectangleSpiral(design, make=False)
        self.assertEqual('res_2' in design.components, True)

        # Manually add the next automatic name to check it doesn't get repeated
        ResonatorRectangleSpiral(design, 'res_3', make=False)
        ResonatorRectangleSpiral(design, make=False)
        self.assertEqual('res_3' in design.components, True)
        self.assertEqual('res_4' in design.components, True)

        # Add a different component
        TransmonPocket(design, make=False)
        self.assertEqual('Q_1' in design.components, False)

        # Add a component with no predefined prefix
        QComponent(design, make=False)
        self.assertEqual('QComponent_1' in design.components, True)