Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mode enum #407

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Mode enum #407

wants to merge 9 commits into from

Conversation

Jingyi99
Copy link
Contributor

@Jingyi99 Jingyi99 commented May 22, 2019

Issue: #400
I was not entirely sure where to put the mode enum class so I put it in hammer_tool.py. I can move it if there is a better place.
I will modify the string comparisons and open another PR if this enum class looks good.

@Jingyi99 Jingyi99 requested a review from edwardcwang May 22, 2019 18:06
@Jingyi99 Jingyi99 added very low priority No workaround needed, not urgent, no timeline needed enhancement labels May 22, 2019
Copy link
Member

@edwardcwang edwardcwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I left a comment below about this enum.

Empty = 2
Manual = 3
Generate = 4
Generated = 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I'm aware, the modes we use are:

    Auto = 1
    Empty = 2
    Manual = 3
    Generated = 4

append, prepend are part of another part of Hammer and not part of this mode enum.

Also, if we are going to create this enum, I think it may be good to also use them in some of the settings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change power straps to generated from generate if we're going to use generate. I personally like generate better, but generated does keep all of the modes as adjectives, which also makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe we can do that as a separate issue then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just tack it on to #397 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Edward, thanks for your comment! I checked defaults.yml and it seems that pin place mode uses generated, and power straps mode uses generate. Just to make sure, they are the same and we'll stick with generate, right?
Also, I'm not sure what it means to use the enum in the settings, could you explain a bit more?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jingyi- let's use generated instead of generate. We'll change the power straps mode to generate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so John's comment above is alluding to that problem. I think the desired action is to use generated and just ignore the power straps mode for now.

As for use, if you look in the code, right now it uses strings - the intention is to use this enum instead

if bumps_mode == "empty":

@Jingyi99
Copy link
Contributor Author

It seems like I broke something...

Copy link
Member

@edwardcwang edwardcwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For type hinting comments, let's keep them proper

@@ -970,7 +973,7 @@ def get_gds_map_file(self) -> Optional[str]:
:return: Fully-resolved path to GDS map file or None.
"""
# Mode can be auto, empty, or manual
gds_map_mode = str(self.get_setting("par.inputs.gds_map_mode")) # type: str
gds_map_mode = ModeType.from_str(str(self.get_setting("par.inputs.gds_map_mode"))) # type: ModeType Enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/hammer-vlsi/hammer_vlsi/hammer_tool.py Outdated Show resolved Hide resolved
src/hammer-vlsi/hammer_vlsi/hammer_tool.py Show resolved Hide resolved
@@ -1323,15 +1323,15 @@ def generate_power_spec_commands(self) -> List[str]:
return []

power_spec_contents = "" # type: str
power_spec_mode = str(self.get_setting("vlsi.inputs.power_spec_mode")) # type: str
if power_spec_mode == "empty":
power_spec_mode = ModeType.from_str(str(self.get_setting("vlsi.inputs.power_spec_mode"))) # type: ModeType Enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -970,7 +973,7 @@ def get_gds_map_file(self) -> Optional[str]:
:return: Fully-resolved path to GDS map file or None.
"""
# Mode can be auto, empty, or manual
gds_map_mode = str(self.get_setting("par.inputs.gds_map_mode")) # type: str
gds_map_mode = ModeType.from_str(str(self.get_setting("par.inputs.gds_map_mode"))) # type: ModeType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to create a static helper method called ModeType.from_setting that takes the HammerTool object and the setting string as args and returns a ModeType. e.g.

class ModeType:
  @staticmethod
  def from_setting(tool: HammerTool, setting: str) -> ModeType:
    return ModeType.from_str(str(tool.get_setting(setting)))

which would then allow the following change (no need for type hint, either):

Suggested change
gds_map_mode = ModeType.from_str(str(self.get_setting("par.inputs.gds_map_mode"))) # type: ModeType
gds_map_mode = ModeType.from_setting(self, "par.inputs.gds_map_mode")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to nitpick too much - at that point I would prefer almost gds_map_mode = self.get_mode_setting("par.inputs.gds_map_mode") to avoid a dependency from ModeType -> HammerTool

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also like that, perhaps more.

@Jingyi99
Copy link
Contributor Author

Sorry for introducing bugs. The errors in the unit tests are

File "/buildbot/run_unittests/build/src/hammer-vlsi/hammer_vlsi/hammer_tool.py", line 1135, in HammerTool
  def get_mode_setting(self, setting: str) -> ModeType:
NameError: name 'ModeType' is not defined

Is it potentially because I was not importing properly?
Also, are there any units tests that I can run locally?
Thanks!

@jwright6323
Copy link
Contributor

Hi Jingyi- you can run the unittests in src/test/unittests.sh: https://github.com/ucb-bar/hammer/blob/master/src/test/unittests.sh
You cal also run the typechecker by running the mypy_with_exclusions.sh script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement very low priority No workaround needed, not urgent, no timeline needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants