def test_obstruction(self) -> None: d = { "type": "obstruction", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "width": Decimal(10), "height": Decimal(20), "orientation": "mx" } with self.assertRaises(ValueError): # This should assert because we are missing obs_types tc = PlacementConstraint.from_dict(d) d.update({"obs_types": ["place"]}) tc = PlacementConstraint.from_dict(d) self.assertEqual(tc.type, PlacementConstraintType.Obstruction) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(10)) self.assertEqual(tc.height, Decimal(20)) self.assertEqual(tc.orientation, "mx") with self.assertRaises(ValueError): m = {"margins": Margins.empty().to_dict()} # This should assert because margins are not allowed tc = PlacementConstraint.from_dict(add_dicts(d, m))
def test_obstruction(self) -> None: d = {"type": "obstruction", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "width": Decimal(10), "height": Decimal(20), "orientation": "mx"} with self.assertRaises(ValueError): # This should assert because we are missing obs_types tc = PlacementConstraint.from_dict(d) d.update({"obs_types": ["place"]}) tc = PlacementConstraint.from_dict(d) self.assertEqual(tc.type, PlacementConstraintType.Obstruction) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(10)) self.assertEqual(tc.height, Decimal(20)) self.assertEqual(tc.orientation, "mx") with self.assertRaises(ValueError): m = {"margins": Margins.empty().to_dict()} # This should assert because margins are not allowed tc = PlacementConstraint.from_dict(add_dicts(d, m))
def test_hierarchical(self) -> None: d = { "type": "hierarchical", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "master": "foo", "orientation": "mx" } with self.assertRaises(ValueError): # This should assert because width and height are missing tc = PlacementConstraint.from_dict(d) d.update({"width": Decimal(10), "height": Decimal(20)}) tc = PlacementConstraint.from_dict(d) self.assertEqual(tc.type, PlacementConstraintType.Hierarchical) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(10)) self.assertEqual(tc.height, Decimal(20)) self.assertEqual(tc.master, "foo") self.assertEqual(tc.orientation, "mx") with self.assertRaises(ValueError): m = {"margins": Margins.empty().to_dict()} # This should assert because margins are not allowed tc = PlacementConstraint.from_dict(add_dicts(d, m))
def test_master_hierarchical(self) -> None: d = {"type": "hierarchical", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "master": "bar", "orientation": "mx"} masters = [MacroSize.from_setting(x) for x in [ {"name": "foo", "library": "none", "width": "1234", "height": "2345"}, {"name": "bar", "library": "none", "width": "2222", "height": "4444"} ]] with self.assertRaises(ValueError): # This should assert because width and height are missing tc = PlacementConstraint.from_dict(d) tc = PlacementConstraint.from_masters_and_dict(masters, d) self.assertEqual(tc.type, PlacementConstraintType.Hierarchical) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(2222)) self.assertEqual(tc.height, Decimal(4444)) self.assertEqual(tc.orientation, "mx") self.assertEqual(tc.master, "bar")
def test_master_hierarchical(self) -> None: d = {"type": "hierarchical", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "master": "bar", "orientation": "mx"} masters = [MacroSize.from_setting(x) for x in [ {"name": "foo", "library": "none", "width": "1234", "height": "2345"}, {"name": "bar", "library": "none", "width": "2222", "height": "4444"} ]] with self.assertRaises(ValueError): # This should assert because width and height are missing tc = PlacementConstraint.from_dict(d) tc = PlacementConstraint.from_masters_and_dict(masters, d) self.assertEqual(tc.type, PlacementConstraintType.Hierarchical) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(2222)) self.assertEqual(tc.height, Decimal(4444)) self.assertEqual(tc.orientation, "mx") self.assertEqual(tc.master, "bar")
def test_hierarchical(self) -> None: d = {"type": "hierarchical", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "master": "foo", "orientation": "mx"} with self.assertRaises(ValueError): # This should assert because width and height are missing tc = PlacementConstraint.from_dict(d) d.update({ "width": Decimal(10), "height": Decimal(20)}) tc = PlacementConstraint.from_dict(d) self.assertEqual(tc.type, PlacementConstraintType.Hierarchical) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(10)) self.assertEqual(tc.height, Decimal(20)) self.assertEqual(tc.master, "foo") self.assertEqual(tc.orientation, "mx") with self.assertRaises(ValueError): m = {"margins": Margins.empty().to_dict()} # This should assert because margins are not allowed tc = PlacementConstraint.from_dict(add_dicts(d, m))
def test_master_hardmacro(self) -> None: d = { "type": "hardmacro", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "master": "foo", "orientation": "mx" } masters = [ MacroSize.from_setting(x) for x in [{ "name": "foo", "library": "none", "width": "1234", "height": "2345" }, { "name": "bar", "library": "none", "width": "2222", "height": "4444" }] ] tc = PlacementConstraint.from_masters_and_dict(masters, d) self.assertEqual(tc.type, PlacementConstraintType.HardMacro) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(1234)) self.assertEqual(tc.height, Decimal(2345)) self.assertEqual(tc.orientation, "mx") self.assertEqual(tc.master, "foo")
def test_invalid(self) -> None: d = {"type": "foobar", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "width": Decimal(10), "height": Decimal(20), "orientation": "mx"} with self.assertRaises(ValueError): tc = PlacementConstraint.from_dict(d)
def test_invalid(self) -> None: d = {"type": "foobar", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "width": Decimal(10), "height": Decimal(20), "orientation": "mx"} with self.assertRaises(ValueError): tc = PlacementConstraint.from_dict(d)
def test_hardmacro(self) -> None: d = {"type": "hardmacro", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "width": Decimal(10), "height": Decimal(20), "orientation": "mx"} tc = PlacementConstraint.from_dict(d) self.assertEqual(tc.type, PlacementConstraintType.HardMacro) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(10)) self.assertEqual(tc.height, Decimal(20)) self.assertEqual(tc.orientation, "mx") with self.assertRaises(ValueError): m = {"margins": Margins.empty().to_dict()} # This should assert because margins are not allowed tc = PlacementConstraint.from_dict(add_dicts(d, m))
def test_toplevel(self) -> None: d = {"type": "toplevel", "path": "path/to/placement", "x": Decimal(0), "y": Decimal(0), "width": Decimal(1000), "height": Decimal(2000)} with self.assertRaises(ValueError): # This should assert because margins are required tc = PlacementConstraint.from_dict(d) # Add margins m = {"margins": Margins.empty().to_dict()} tc = PlacementConstraint.from_dict(add_dicts(d, m)) self.assertEqual(tc.type, PlacementConstraintType.TopLevel) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(0)) self.assertEqual(tc.y, Decimal(0)) self.assertEqual(tc.width, Decimal(1000)) self.assertEqual(tc.height, Decimal(2000))
def test_hardmacro(self) -> None: d = {"type": "hardmacro", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "width": Decimal(10), "height": Decimal(20), "orientation": "mx"} tc = PlacementConstraint.from_dict(d) self.assertEqual(tc.type, PlacementConstraintType.HardMacro) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(10)) self.assertEqual(tc.height, Decimal(20)) self.assertEqual(tc.orientation, "mx") with self.assertRaises(ValueError): m = {"margins": Margins.empty().to_dict()} # This should assert because margins are not allowed tc = PlacementConstraint.from_dict(add_dicts(d, m))
def test_toplevel(self) -> None: d = {"type": "toplevel", "path": "path/to/placement", "x": Decimal(0), "y": Decimal(0), "width": Decimal(1000), "height": Decimal(2000)} with self.assertRaises(ValueError): # This should assert because margins are required tc = PlacementConstraint.from_dict(d) # Add margins m = {"margins": Margins.empty().to_dict()} tc = PlacementConstraint.from_dict(add_dicts(d, m)) self.assertEqual(tc.type, PlacementConstraintType.TopLevel) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(0)) self.assertEqual(tc.y, Decimal(0)) self.assertEqual(tc.width, Decimal(1000)) self.assertEqual(tc.height, Decimal(2000))
def add_hier(d: Dict[str, Any]) -> Dict[str, Any]: output = deepdict(d) dummy_placement = PlacementConstraint( path="dummy", type=PlacementConstraintType.Dummy, x=Decimal("0"), y=Decimal("0"), width=Decimal("10"), height=Decimal("10"), master=None, create_physical=None, orientation=None, margins=None, top_layer=None, layers=None, obs_types=None).to_dict() output["vlsi.inputs.default_output_load"] = 1 output["vlsi.inputs.hierarchical.top_module"] = top_module output["vlsi.inputs.hierarchical.flat"] = "hierarchical" output["vlsi.inputs.hierarchical.config_source"] = "manual" output["vlsi.inputs.hierarchical.manual_modules"] = [{ "mod1": ["m1s1", "m1s2"], "mod2": ["m2s1"], top_module: ["mod1", "mod2"] }] manual_constraints = [{ "mod1": [dummy_placement] }, { "mod2": [dummy_placement] }, { "m1s1": [dummy_placement] }, { "m1s2": [dummy_placement] }, { "m2s1": [dummy_placement] }, { top_module: [dummy_placement] }] output[ "vlsi.inputs.hierarchical.manual_placement_constraints"] = manual_constraints output["vlsi.inputs.hierarchical.constraints"] = [{ "mod1": [{ "vlsi.inputs.default_output_load": 2 }] }, { "m2s1": [{ "vlsi.inputs.default_output_load": 3 }] }] return output
def test_master_hardmacro(self) -> None: d = {"type": "hardmacro", "path": "path/to/placement", "x": Decimal(4), "y": Decimal(6), "master": "foo", "orientation": "mx"} masters = [MacroSize.from_setting(x) for x in [ {"name": "foo", "library": "none", "width": "1234", "height": "2345"}, {"name": "bar", "library": "none", "width": "2222", "height": "4444"} ]] tc = PlacementConstraint.from_masters_and_dict(masters, d) self.assertEqual(tc.type, PlacementConstraintType.HardMacro) self.assertEqual(tc.path, "path/to/placement") self.assertEqual(tc.x, Decimal(4)) self.assertEqual(tc.y, Decimal(6)) self.assertEqual(tc.width, Decimal(1234)) self.assertEqual(tc.height, Decimal(2345)) self.assertEqual(tc.orientation, "mx") self.assertEqual(tc.master, "foo")