rocketsled.examples package¶
Submodules¶
rocketsled.examples.basic module¶
An example of the most basic rocketsled implementation. This file creates and executes a workflow containing one Firework.
- The Firework contains 2 Tasks.
- ObjectiveFuncTask - a task that reads x from the spec and
updates y in the spec, according to a simple known function.
2. OptTask - a task that stores optimiztion data in the db and optimizes the next guess.
workflows including multiple jobs and advanced dependencies. Please see the complex example, or the Fireworks and rocketsled documentation pages for more information:
https://hackingmaterials.github.io/rocketsled/ https://materialsproject.github.io/fireworks/
- class rocketsled.examples.basic.ObjectiveFuncTask(*args, **kwargs)¶
Bases:
fireworks.core.firework.FireTaskBase
An example task which just evaluates the following simple function:
f(x) = x[0] * x[1] / x[2]
Replace this code with your objective function if your objective function is relatively simple (i.e., only needs one Firework).
- run_task(fw_spec)¶
This method gets called when the Firetask is run. It can take in a Firework spec, perform some task using that data, and then return an output in the form of a FWAction.
- Args:
- fw_spec (dict): A Firework spec. This comes from the master spec.
In addition, this spec contains a special “_fw_env” key that contains the env settings of the FWorker calling this method. This provides for abstracting out certain commands or settings. For example, “foo” may be named “foo1” in resource 1 and “foo2” in resource 2. The FWorker env can specify { “foo”: “foo1”}, which maps an abstract variable “foo” to the relevant “foo1” or “foo2”. You can then write a task that uses fw_spec[“_fw_env”][“foo”] that will work across all these multiple resources.
- Returns:
(FWAction)
- rocketsled.examples.basic.wf_creator(x)¶
The workflow creator function required by rocketsled.
This wf_creator takes in an input vector x and returns a workflow which calculates y, the output. The requirements for using this wf_creator with rocketsled are:
OptTask is passed into a FireWork in the workflow
- The fields “_x” and “_y” are written to the spec of the FireWork
containing OptTask.
- You use MissionControl’s “configure” method to set up the optimization,
and pass in wf_creator as it’s first argument.
- Args:
- x (list): The wf_creator input vector. In this example, it is just 3
integers between 1 and 5 (inclusive).
- Returns:
- (Workflow): A workflow containing one FireWork (two FireTasks) which
is automatically set up to run the optimization loop.
rocketsled.examples.batch module¶
Running a batch optimization with a custom predictor.
Optimizing the 2D Rosenbrock function, which is a 2D function with one objective to be minimized. There are no Z descriptors so we use only the X coordinates for learning.
We show two examples here:
Running a batch optimization with a builtin predictor.
- Using your own custom predictor while still using
batch optimization.
Change the USE_CUSTOM_PREDICTOR variable False to use the builtin predictor.
See the documentation for more information on batch optimization and how it runs.
- class rocketsled.examples.batch.RosenbrockTask(*args, **kwargs)¶
Bases:
fireworks.core.firework.FireTaskBase
- run_task(fw_spec)¶
This method gets called when the Firetask is run. It can take in a Firework spec, perform some task using that data, and then return an output in the form of a FWAction.
- Args:
- fw_spec (dict): A Firework spec. This comes from the master spec.
In addition, this spec contains a special “_fw_env” key that contains the env settings of the FWorker calling this method. This provides for abstracting out certain commands or settings. For example, “foo” may be named “foo1” in resource 1 and “foo2” in resource 2. The FWorker env can specify { “foo”: “foo1”}, which maps an abstract variable “foo” to the relevant “foo1” or “foo2”. You can then write a task that uses fw_spec[“_fw_env”][“foo”] that will work across all these multiple resources.
- Returns:
(FWAction)
- rocketsled.examples.batch.custom_batch_predictor(XZ_explored, Y, x_dims, XZ_unexplored, batch_size=1)¶
Returns a prediction for the next best guess. The returned guess will be used to construct a new workflow with the workflow creator function.
The argument names need not be the same shown here, although their position must remain the same.
This particular implementation just returns a series of random guesses in the unexplored space.
- Args:
- XZ_explored ([list]): A list of lists; 2D array of samples (rows)
by features (columns) of points already evaluated in the search space. This is training data.
Y (list): A vector of samples; this is the training output. x_dims (list): The dimensions of the search space XZ_unexplored([list[): A list of lists; 2D array of samples (rows)
by features (columns) of points to be predicted. This is the ‘test’ or prediction dataset.
- Returns:
- x (list): A vector representing the set of parameters for the next best
guess, or for batches, a list of best next x guesses. Number of guesses must match batch_size.
- rocketsled.examples.batch.wf_creator_rosenbrock(x)¶
rocketsled.examples.complex module¶
Running a rocketsled optimization with a multi-part workflow, multi-objective objective function, z-features, as well as more advanced configuration.
Our workflow to optimize now has two Fireworks, each with one FireTask. The first firework runs the ‘expensive’ objective function, and the second firework runs only the optimization. This two-firework setup allows us to run the objective function and optimization on different computing resources, if desired.
We also use an objective function with more than one objective. Note that as long as we pass in the output vector to the spec (in the key “_y”, as in the basic example), we don’t need to make any other changes to tell rocketsled the objective function is multi-objective. Additionally, the objective function has dimensions of differing data types (int, float, categorical), which is automatically handled by rocketsled as long as the dimensions are passed into MissionControl.configure(…).
Finally, we add some arguments to the MissionControl configuration before launching.
- class rocketsled.examples.complex.ComplexMultiObjTask(*args, **kwargs)¶
Bases:
fireworks.core.firework.FireTaskBase
An example of a complex, multiobjective task with directly competing objectives. The input vector is defined on a search space with numerical and categorical inputs.
This task accepts a 3-vector of the form [int, float, str].
- run_task(fw_spec)¶
This method gets called when the Firetask is run. It can take in a Firework spec, perform some task using that data, and then return an output in the form of a FWAction.
- Args:
- fw_spec (dict): A Firework spec. This comes from the master spec.
In addition, this spec contains a special “_fw_env” key that contains the env settings of the FWorker calling this method. This provides for abstracting out certain commands or settings. For example, “foo” may be named “foo1” in resource 1 and “foo2” in resource 2. The FWorker env can specify { “foo”: “foo1”}, which maps an abstract variable “foo” to the relevant “foo1” or “foo2”. You can then write a task that uses fw_spec[“_fw_env”][“foo”] that will work across all these multiple resources.
- Returns:
(FWAction)
- rocketsled.examples.complex.get_z(x)¶
An example function demonstrating how to use z_features.
The get_z function should accept the same vector as the wf_creator (the x vector), and return all information that should be used for learning. If you want to use x for learning, make sure to include x in the returned z vector.
- Args:
- x ([list]): A 3 vector of the form [int, float, str], where the elements
are constrained to the search space given in x_dim above.
- Returns:
(list): The z vector, to be used for learning.
- rocketsled.examples.complex.wf_creator(x)¶
A workflow creator function returning a workflow of the following form:
- simulation (fw1)
optimization (fw2)
- Args:
- x ([list]): A 3 vector of the form [int, float, str], where the elements
are constrained to the search space given in x_dim above.
- Returns:
- (Workflow): The workflow which will run the simulation and optimization
fireworks.
Module contents¶
Examples for Rocketsled.