Skip to content

Commit

Permalink
adapted template script to experiment class
Browse files Browse the repository at this point in the history
  • Loading branch information
alperyeg committed Sep 17, 2020
1 parent 2aad0f4 commit 53a286e
Showing 1 changed file with 29 additions and 68 deletions.
97 changes: 29 additions & 68 deletions bin/l2l-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import os

from l2l.utils.environment import Environment
from l2l.utils.experiment import Experiment

from l2l.logging_tools import create_shared_logger_data, configure_loggers
from l2l.optimizees.optimizee import Optimizee
from l2l.optimizees.optimizee import Optimizee, OptimizeeParameters
from l2l.optimizers.optimizer import Optimizer, OptimizerParameters
from l2l.paths import Paths

Expand All @@ -21,80 +22,40 @@


def main():
# TODO when using the template: Give some *meaningful* name here
name = 'L2L'

# TODO when using the template: make a path.conf file and write the root path there
try:
with open('bin/path.conf') as f:
root_dir_path = f.read().strip()
except FileNotFoundError:
raise FileNotFoundError(
"You have not set the root path to store your results."
" Write the path to a path.conf text file in the bin directory"
" before running the simulation"
)
paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path)

# Load the logging config which tells us where and what to log (loglevel, destination)

print("All output logs can be found in directory ", paths.logs_path)

# Create an environment that handles running our simulation
# This initializes an environment. This environment is based on the Pypet implementation.
# Uncomment 'freeze_input', 'multipproc', 'use_scoop' and 'wrap_mode' lines to disable running the experiment
# across cores and nodes.
env = Environment(trajectory=name, filename=paths.output_dir_path, file_title='{} data'.format(name),
comment='{} data'.format(name),
add_time=True,
freeze_input=False,
multiproc=True,
automatic_storing=True,
log_stdout=False, # Sends stdout to logs
)
create_shared_logger_data(logger_names=['bin', 'optimizers'],
log_levels=['INFO', 'INFO'],
log_to_consoles=[True, True],
sim_name=name,
log_directory=paths.logs_path)
configure_loggers()

# Get the trajectory from the environment.
traj = env.trajectory

# Set JUBE params
traj.f_add_parameter_group("JUBE_params", "Contains JUBE parameters")
# Execution command
traj.f_add_parameter_to_group("JUBE_params", "exec", "python " +
os.path.join(paths.simulation_path, "run_files/run_optimizee.py"))
# Paths
traj.f_add_parameter_to_group("JUBE_params", "paths", paths)
# TODO: use the experiment module to prepare and run later the simulation
# define a directory to store the results
experiment = Experiment(root_dir_path='~/home/user/L2L/results')
# TODO when using the template: use keywords to prepare the experiment and
# create a dictionary for jube parameters
# prepare_experiment returns the trajectory and all jube parameters
jube_params = {"nodes": "2",
"walltime": "10:00:00",
"ppn": "1",
"cpu_pp": "1"}
traj, all_jube_params = experiment.prepare_experiment(name='L2L',
log_stdout=True,
**jube_params)

## Innerloop simulator
# TODO when using the template: Change the optimizee to the appropriate Optimizee class
# TODO when using the template: Change the optimizee to the appropriate
# Optimizee class
optimizee = Optimizee(traj)

# Prepare optimizee for jube runs
jube.prepare_optimizee(optimizee, paths.simulation_path)
# TODO Create optimizee parameters
optimizee_parameters = OptimizeeParameters()

## Outerloop optimizer initialization
# TODO when using the template: Change the optimizer to the appropriate Optimizer class
# and use the right value for optimizee_fitness_weights. Length is the number of dimensions of fitness, and
# negative value implies minimization and vice versa
# TODO when using the template: Change the optimizer to the appropriate
# Optimizer class and use the right value for optimizee_fitness_weights.
# Length is the number of dimensions of fitness, and negative value
# implies minimization and vice versa
optimizer_parameters = OptimizerParameters()
optimizer = Optimizer(traj, optimizee.create_individual, (1.0,), optimizer_parameters)

# Add post processing
env.add_postprocessing(optimizer.post_process)

# Run the simulation with all parameter combinations
env.run(optimizee.simulate)

## Outerloop optimizer end
optimizer.end(traj)
optimizer = Optimizer(traj, optimizee.create_individual, (1.0,),
optimizer_parameters)

# Finally disable logging and close all log-files
env.disable_logging()
experiment.run_experiment(optimizee=optimizee,
optimizee_parameters=optimizee_parameters,
optimizer=optimizer,
optimizer_parameters=optimizer_parameters)


if __name__ == '__main__':
Expand Down

0 comments on commit 53a286e

Please sign in to comment.