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

Enhances pgen to take in the environment specified in a study. #209

Merged
merged 6 commits into from
Dec 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions maestrowf/maestro.py
Original file line number Diff line number Diff line change
@@ -90,12 +90,13 @@ def cancel_study(args):
return 0


def load_parameter_generator(path, kwargs):
def load_parameter_generator(path, env, kwargs):
"""
Import and load custom parameter Python files.

:param path: Path to a Python file containing the function \
'get_custom_generator'.
:param env: A StudyEnvironment object containing custom information.
:param kwargs: Dictionary containing keyword arguments for the function \
'get_custom_generator'.
:returns: A populated ParameterGenerator instance.
@@ -109,20 +110,20 @@ def load_parameter_generator(path, kwargs):
spec = importlib.util.spec_from_file_location("custom_gen", path)
f = importlib.util.module_from_spec(spec)
spec.loader.exec_module(f)
return f.get_custom_generator(**kwargs)
return f.get_custom_generator(env, **kwargs)
except ImportError:
try:
# Python 3.3
from importlib.machinery import SourceFileLoader
LOGGER.debug("Using Python 3.4 SourceFileLoader...")
f = SourceFileLoader("custom_gen", path).load_module()
return f.get_custom_generator(**kwargs)
return f.get_custom_generator(env, **kwargs)
except ImportError:
# Python 2
import imp
LOGGER.debug("Using Python 2 imp library...")
f = imp.load_source("custom_gen", path)
return f.get_custom_generator(**kwargs)
return f.get_custom_generator(env, **kwargs)
except Exception as e:
LOGGER.exception(str(e))
raise e
@@ -183,22 +184,28 @@ def run_study(args):
LOGGER.exception(msg)
raise ArgumentError(msg)

# Addition of the $(SPECROOT) to the environment.
spec_root = os.path.split(args.specification)[0]
spec_root = Variable("SPECROOT", os.path.abspath(spec_root))
environment.add(spec_root)

# Handle loading a custom ParameterGenerator if specified.
if args.pgen:
# 'pgen_args' has a default of an empty list, which should translate
# to an empty dictionary.
kwargs = create_dictionary(args.pargs)
# Copy the Python file used to generate parameters.
shutil.copy(args.pgen, output_path)
parameters = load_parameter_generator(args.pgen, kwargs)

# Add keywords and environment from the spec to pgen args.
kwargs["OUTPUT_PATH"] = output_path
kwargs["SPECROOT"] = spec_root

# Load the parameter generator.
parameters = load_parameter_generator(args.pgen, environment, kwargs)
else:
parameters = spec.get_parameters()

# Addition of the $(SPECROOT) to the environment.
spec_root = os.path.split(args.specification)[0]
spec_root = Variable("SPECROOT", os.path.abspath(spec_root))
environment.add(spec_root)

# Setup the study.
study = Study(spec.name, spec.description, studyenv=environment,
parameters=parameters, steps=steps, out_path=output_path)
6 changes: 6 additions & 0 deletions samples/lulesh/lulesh_sample1_macosx.yaml
Original file line number Diff line number Diff line change
@@ -4,6 +4,12 @@ description:

env:
variables:
# DEFAULTS FOR MONTECARLO PGEN EXAMPLE
SMIN: 10
SMAX: 30
TRIALS: 50
ITER: 100

OUTPUT_PATH: ./sample_output/lulesh

labels:
6 changes: 6 additions & 0 deletions samples/lulesh/lulesh_sample1_unix.yaml
Original file line number Diff line number Diff line change
@@ -4,6 +4,12 @@ description:

env:
variables:
# DEFAULTS FOR MONTECARLO PGEN EXAMPLE
SMIN: 10
SMAX: 30
TRIALS: 50
ITER: 100

OUTPUT_PATH: ./sample_output/lulesh

labels:
2 changes: 1 addition & 1 deletion samples/parameterization/custom_generator.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
from maestrowf.datastructures.core import ParameterGenerator


def get_custom_generator():
def get_custom_generator(env, **kwargs):
"""
Create a custom populated ParameterGenerator.

2 changes: 1 addition & 1 deletion samples/parameterization/lulesh_custom_gen.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
from maestrowf.datastructures.core import ParameterGenerator


def get_custom_generator():
def get_custom_generator(env, **kwargs):
"""
Create a custom populated ParameterGenerator.

10 changes: 5 additions & 5 deletions samples/parameterization/lulesh_montecarlo_args.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
from maestrowf.datastructures.core import ParameterGenerator


def get_custom_generator(**kwargs):
def get_custom_generator(env, **kwargs):
"""
Create a custom populated ParameterGenerator.

@@ -17,10 +17,10 @@ def get_custom_generator(**kwargs):
:returns: A ParameterGenerator populated with parameters.
"""
p_gen = ParameterGenerator()
trials = int(kwargs.get("trials"))
size_min = int(kwargs.get("smin"))
size_max = int(kwargs.get("smax"))
iterations = int(kwargs.get("iter"))
trials = int(kwargs.get("trials", env.find("TRIALS").value))
size_min = int(kwargs.get("smin", env.find("SMIN").value))
size_max = int(kwargs.get("smax", env.find("SMAX").value))
iterations = int(kwargs.get("iter", env.find("ITER").value))
params = {
"TRIAL": {
"values": [i for i in range(1, trials)],