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

Define glpk launcher and expose command line and api option #112

Merged
merged 6 commits into from
Feb 23, 2021

Conversation

jenhagg
Copy link
Collaborator

@jenhagg jenhagg commented Feb 18, 2021

Purpose

Add new --solver parameter (and corresponding query string) which can currently be either gurobi or glpk. This enables running a simulation in test scenarios where a license is not available.

What it does

  • implement required launcher subclass
  • install glpk in docker image
  • make the launcher class determined (optionally) by end user, defaulting to gurobi
  • move launchers to separate file, to keep call.py relatively clean

Time to review

10 min

@jenhagg jenhagg self-assigned this Feb 18, 2021
@jenhagg jenhagg added this to the HTAACD milestone Feb 18, 2021
Comment on lines 36 to 39
launch_map = {"gurobi": GurobiLauncher, "glpk": GLPKLauncher}
if solver is None:
return GurobiLauncher
return launch_map[solver]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we provide a meaningful exception in case the user specifies something besides the keys in launch_map?

Should we allow a little more flexibility so that strings like "Gurobi" or "GLPK" still resolve successfully?

Should we define launch_map within the body of launchers.py so that we can do a single import?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Affirmative, all good ideas. I probably could have made this a draft PR since it's a bit rough currently.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like where it's headed so far.

Comment on lines 76 to 79
parser.add_argument(
"--solver",
help="Specify the solver to run the optimization. Will default to gurobi",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we define launch_map within launchers.py, does that let us do something like automatically populate the help string with a list of valid keys?

Comment on lines +115 to +119
runtime = round(end - start)
hours, minutes, seconds = sec2hms(runtime)
print(f"Run time: {hours}:{minutes:02d}:{seconds:02d}")

return runtime
Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to maximize our DRY, we could define a round_and_print_runtime method of the Launcher class and then call return self.round_and_print_runtime(start, end), but it's not really necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I wanted to reuse the code here but since it's interleaved it felt like the result would be harder to read. If we end up adding more solvers I would want to do something about it.

@danielolsen
Copy link
Contributor

The code looks good. Has it been tested?

@jenhagg
Copy link
Collaborator Author

jenhagg commented Feb 23, 2021

The code looks good. Has it been tested?

Yeah, just manual tests in a container - checked with invalid solver and completed a simulation with glpk

Copy link
Contributor

@danielolsen danielolsen left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants