-
Notifications
You must be signed in to change notification settings - Fork 5
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
Update defaults #15
Update defaults #15
Changes from all commits
2e41457
f9870f7
c24fbd1
efb8a43
bb18f51
46f2a98
9654ba2
e3755ff
b52299b
5f6a3b3
ae76630
bf7226d
d9e7d2d
bf40fde
27cc753
50d6ed6
8d3629e
8b13031
7aa2927
cb1a5c9
aaf834f
65f2a10
f4660f2
3627f08
03f7b60
cf3ba30
0d96539
9957ed7
c56a704
ffe44d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import openmc | ||
import numpy as np | ||
|
||
pu = openmc.Material() | ||
pu.set_density("g/cm3", 19.84) | ||
pu.add_nuclide("Pu239", 1) | ||
mats = openmc.Materials([pu]) | ||
|
||
radius = {{radius}} | ||
|
||
fuel_sphere = openmc.Sphere(r=radius, boundary_type='vacuum') | ||
fuel_cell = openmc.Cell(fill=pu, region=-fuel_sphere) | ||
univ = openmc.Universe(cells=[fuel_cell]) | ||
geom = openmc.Geometry(univ) | ||
|
||
settings = openmc.Settings() | ||
settings.batches = 100 | ||
settings.inactive = 20 | ||
settings.particles = 20000 | ||
settings.temperature = {"multipole": True, "method": "interpolation"} | ||
|
||
|
||
mats.export_to_xml() | ||
geom.export_to_xml() | ||
settings.export_to_xml() | ||
openmc.run() |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"control_variables": { | ||
"radius": {"min": 1.0, "max": 8.0} | ||
}, | ||
"evaluators": { | ||
"openmc": { | ||
"input_script": "critical_sphere.py", | ||
"inputs": ["radius"], | ||
"outputs": ["keff", "radius"], | ||
"keep_files": false | ||
} | ||
}, | ||
"constraints": {"keff": {"operator": [">="], "constrained_val": [1.0]}}, | ||
"algorithm": { | ||
"parallel": "multiprocessing", | ||
"objective": ["min"], | ||
"optimized_variable": ["radius"], | ||
"pop_size": 80, | ||
"generations": 10, | ||
"mutation_probability": 0.23, | ||
"mating_probability": 0.46, | ||
"selection_operator": {"operator": "selTournament", "inds": 15, "tournsize": 5}, | ||
"mutation_operator": { | ||
"operator": "mutPolynomialBounded", | ||
"eta": 0.23, | ||
"indpb": 0.23 | ||
}, | ||
"mating_operator": {"operator": "cxBlend", "alpha": 0.46} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
|
||
class InputValidation: | ||
"""The InputValidation class contains methods to read and validate the JSON | ||
ROLLO input file to ensure the user defined all key parameters. If the user | ||
did not, ROLLO raises an exception to tell the user which parameters are | ||
missing. | ||
ROLLO input file to ensure the user defined all key parameters. If the | ||
user did not, ROLLO raises an exception to tell the user which | ||
parameters are missing. | ||
|
||
Attributes | ||
---------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming the variable for this class as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll address this in #20 |
||
|
@@ -18,8 +18,8 @@ class InputValidation: | |
def __init__(self, input_dict): | ||
self.input = input_dict | ||
|
||
def add_all_defaults(self, input_dict): | ||
""" Goes through the entire input_dict and adds default inputs if they | ||
def add_all_defaults(self): | ||
"""Goes through the entire input_dict and adds default inputs if they | ||
are missing from the input_dict | ||
|
||
Parameters | ||
|
@@ -33,6 +33,7 @@ def add_all_defaults(self, input_dict): | |
input file dict with additional missing default inputs | ||
|
||
""" | ||
input_dict = self.input.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you go ahead and rename the class variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll address this in #20 |
||
input_evaluators = {} | ||
for solver in input_dict["evaluators"]: | ||
input_evaluators[solver] = input_dict["evaluators"][solver] | ||
|
@@ -41,26 +42,37 @@ def add_all_defaults(self, input_dict): | |
) | ||
input_algorithm = input_dict["algorithm"] | ||
input_algorithm = self.default_check(input_algorithm, "objective", "min") | ||
input_algorithm = self.default_check(input_algorithm, "pop_size", 100) | ||
input_algorithm = self.default_check(input_algorithm, "pop_size", 60) | ||
input_algorithm = self.default_check(input_algorithm, "generations", 10) | ||
input_algorithm = self.default_check( | ||
input_algorithm, "selection_operator", {"operator": "selBest", "inds": 1} | ||
input_algorithm, "mutation_probability", 0.23 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sanity check: You're adding more checks for the input file, yes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? All the checks are in the input_validation.py file. |
||
) | ||
input_algorithm = self.default_check( | ||
input_algorithm, "mating_probability", 0.47 | ||
) | ||
input_algorithm = self.default_check( | ||
input_algorithm, | ||
"selection_operator", | ||
{"operator": "selTournament", "inds": 15, "tournsize": 5}, | ||
) | ||
input_algorithm = self.default_check( | ||
input_algorithm, | ||
"mutation_operator", | ||
{"operator": "mutGaussian", "indpb": 0.5, "mu": 0.5, "sigma": 0.5}, | ||
{"operator": "mutPolynomialBounded", "eta": 0.23, "indpb": 0.23}, | ||
) | ||
input_algorithm = self.default_check( | ||
input_algorithm, "mating_operator", {"operator": "cxOnePoint"} | ||
input_algorithm, | ||
"mating_operator", | ||
{"operator": "cxBlend", "alpha": 0.46}, | ||
) | ||
reloaded_input_dict = input_dict.copy() | ||
reloaded_input_dict["evaluators"] = input_evaluators | ||
reloaded_input_dict["algorithm"] = input_algorithm | ||
return reloaded_input_dict | ||
self.input = reloaded_input_dict.copy() | ||
return | ||
|
||
def default_check(self, input_dict, variable, default_val): | ||
"""Checks if a single variable is missing from a dict, and adds a | ||
"""Checks if a single variable is missing from a dict, and adds a | ||
default value if it is | ||
|
||
Parameters | ||
|
@@ -217,8 +229,8 @@ def validate_algorithm(self, input_algorithm, input_evaluators): | |
# k value cannot be larger than pop size | ||
if input_algorithm["selection_operator"]["operator"] == "selTournament": | ||
if ( | ||
input_algorithm["selection_operator"]["inds"] > | ||
input_algorithm["pop_size"] | ||
input_algorithm["selection_operator"]["inds"] | ||
> input_algorithm["pop_size"] | ||
): | ||
raise Exception("Population size must be larger than inds.") | ||
return | ||
|
@@ -257,9 +269,9 @@ def validate_algorithm_operators(self, operator_type, input_algorithm): | |
op_op = op["operator"] | ||
except KeyError: | ||
print( | ||
"<Input Validation Error> You must define an operator for the " + | ||
operator_type + | ||
"_operator" | ||
"<Input Validation Error> You must define an operator for " | ||
+ operator_type | ||
+ "_operator" | ||
) | ||
raise | ||
else: | ||
|
@@ -461,11 +473,12 @@ def validate_evaluators(self, input_evaluators): | |
a = input_evaluators[evaluator]["output_script"] | ||
except KeyError: | ||
print( | ||
"<Input Validation Error> You must define an output_script for evaluator: " + | ||
evaluator + | ||
" since the outputs: " + | ||
str(which_strings) + | ||
" are not inputs or pre-defined outputs." | ||
"<Input Validation Error>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh yeah the way these plus signs are is much better :) |
||
+ "You must define an output_script for evaluator: " | ||
+ evaluator | ||
+ " since the outputs: " | ||
+ str(which_strings) | ||
+ " are not inputs or pre-defined outputs." | ||
) | ||
raise | ||
return | ||
|
@@ -511,12 +524,12 @@ def validate_in_list(self, variable, accepted_variables, name): | |
|
||
""" | ||
assert variable in accepted_variables, ( | ||
"<Input Validation Error> variable: " + | ||
name + | ||
", only accepts: " + | ||
str(accepted_variables) + | ||
" not variable: " + | ||
variable | ||
"<Input Validation Error> variable: " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
+ name | ||
+ ", only accepts: " | ||
+ str(accepted_variables) | ||
+ " not variable: " | ||
+ variable | ||
) | ||
return | ||
|
||
|
@@ -544,19 +557,19 @@ def validate_correct_keys( | |
a = dict_to_validate[key] | ||
for key in dict_to_validate: | ||
assert key in combined_key_names, ( | ||
"<Input Validation Error> Only " + | ||
str(combined_key_names) + | ||
" are accepted for " + | ||
variable_type + | ||
", not variable: " + | ||
key | ||
"<Input Validation Error> Only " | ||
+ str(combined_key_names) | ||
+ " are accepted for " | ||
+ variable_type | ||
+ ", not variable: " | ||
+ key | ||
) | ||
except KeyError: | ||
print( | ||
"<Input Validation Error> " + | ||
str(key_names) + | ||
" variables must be defined for " + | ||
variable_type | ||
"<Input Validation Error> " | ||
+ str(key_names) | ||
+ " variables must be defined for " | ||
+ variable_type | ||
) | ||
raise | ||
except AssertionError as error: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain these deletions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From this PR, ROLLO will add default values for these parameters.