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

Workshop March 2022 Examples #139

Merged
merged 14 commits into from
Mar 22, 2022
10 changes: 9 additions & 1 deletion src/Cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_input_specs(cls):
parallel = InputData.parameterInputFactory('parallel', descr=r"""Describes how to parallelize this run.""")
parallel.addSub(InputData.parameterInputFactory('outer', contentType=InputTypes.IntegerType,
descr=r"""the number of parallel runs to use for the outer optimization run. The product of this
number and \xmlNode{inner} should be at most the number of parallel process availabe on
number and \xmlNode{inner} should be at most the number of parallel process available on
your computing device. This should also be at most the number of samples needed per outer iteration;
for example, with 3 opt bound variables and using finite differencing, at most 4 parallel outer runs
can be used. \default{1}"""))
Expand Down Expand Up @@ -375,6 +375,14 @@ def read_input(self, xml):
self.raiseAnError('No <dispatch> node was provided in the <Case> node!')
if self._time_discretization is None:
self.raiseAnError('<time_discretization> node was not provided in the <Case> node!')
cores_requested = self.innerParallel * self.outerParallel
if cores_requested > 1:
# check to see if the number of processes available can meet the request
detected = os.cpu_count() - 1 # -1 to prevent machine OS locking up
if detected < cores_requested:
self.raiseAWarning('System may be overloaded and greatly increase run time! ' +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a comment for consideration:

On my Windows machine, requesting more cores than you have available results in an error and RAVEN will not run, not sure what the behavior is on Mac or Linux. We could raise an error here or raise a warning and wait for RAVEN to throw an error later, either way is probably fine. I think the important thing is to inform the user that they requested more cores than the machine has available. If that particular error is thrown later, the user will have an idea as to why the simulations were not run.

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 don't love how this is handled generally speaking; I think handling it better in RAVEN may lead to sensible error messages so we don't duplicate that effort in HERON.

f'Number of available cores detected: {detected}; ' +
f'Number requested: {cores_requested} (inner: {self.innerParallel} * outer: {self.outerParallel}) ')

# TODO what if time discretization not provided yet?
self.dispatcher.set_time_discr(self._time_discretization)
Expand Down
1 change: 0 additions & 1 deletion src/dispatch/pyomo_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def dispatch_window(self, time, time_offset,
attempts += 1
print(f'DEBUGG solve attempt {attempts} ...:')
# solve
solve_options = {'threads': 2}
soln = pyo.SolverFactory(self._solver).solve(m, options=solve_options)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure this is what is causing the automated tests to fail. Removing the options=solve_options should fix this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

whoops! fixed.

# check solve status
if soln.solver.status == SolverStatus.ok and soln.solver.termination_condition == TerminationCondition.optimal:
Expand Down
2 changes: 0 additions & 2 deletions templates/template_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class Template(TemplateBase, Base):

var_template = xmlUtils.newNode('variable')
var_template.append(xmlUtils.newNode('distribution'))
#var_template.append(xmlUtils.newNode('grid', attrib={'type':'value', 'construction':'custom'}))

############
# API #
Expand Down Expand Up @@ -496,7 +495,6 @@ def _modify_outer_samplers(self, template, case, components):
sampler = 'grid'
else:
sampler = 'opt'
print()

for component in components:
interaction = component.get_interaction()
Expand Down
2 changes: 1 addition & 1 deletion tests/workshop/htse/example1_simple/heron_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<mode>opt</mode>
<num_arma_samples>20</num_arma_samples>
<parallel>
<inner>10</inner>
<inner>2</inner>
</parallel>
<time_discretization>
<year_variable>YEAR</year_variable>
Expand Down