cyrxnopt package
Submodules
cyrxnopt.NestedVenv module
- class cyrxnopt.NestedVenv.NestedVenv(virtual_dir: str | Path)[source]
Bases:
EnvBuilder- activate() None[source]
Activates the current virtual environment as the primary virtual environment. If the venv is active but not primary, it will be reactivated as the primary venv.
- Raises:
RuntimeError – The virtual environment does not exist.
- property binary_directory: Path
The venv subdirectory containing binaries based on operating system.
- Returns:
Full path to the venv binary directory
- Return type:
Path
- create(env_dir: Any = '') None[source]
Creates the virtual environment at the given location.
- Parameters:
env_dir (AnyPath) – Desired venv directory
- deactivate() None[source]
Deactivates the virtual environment regardless of if it is the primary virtual environment.
- is_active() bool[source]
Checks if the virtual environment is active or not.
This checks if the virtual environment path is in the PATH environment variable or not.
- Returns:
Whether the venv is active (True) or not (False).
- Return type:
- is_primary() bool[source]
Checks if the virtual environment is the primary active virtual environment.
This checks if the virtual environment path is the first entry in the PATH environment variable. This menas its packages will be found first.
- TODO: Recognize other virtual environments to ensure we are
the first virtual environment without needing to be the first element in the PATH environment variable.
- Returns:
Whether the venv is primary (True) or not (False).
- Return type:
- pip_freeze() list[str][source]
Returns the list of modules in the virtual environment as they would be returned by ‘pip freeze’.
- Raises:
CalledProcessError – An error occurred when running pip freeze
- pip_install(package_name: str, package_path: Path | None = None, editable: bool = False) None[source]
Install a package to the active virtual environment using
pip installfor an editable install.
- pip_install_e(package_path: Path, package_name: str = '') None[source]
Install a package to the active virtual environment using
pip installfor an editable install.- Parameters:
package_path (Path) – Path to the package location
package_name (str, optional) – Name of the package, defaults to “”. If not provided, the package name is assumed to the the last part of
package_path.
- Raises:
CalledProcessError – An error occurred when running
pip install
- pip_install_r(req_file: Path) None[source]
Installs package requirements from a “requirements.txt”-style file.
- Parameters:
req_file (str) – Requirements file to use
- Raises:
CalledProcessError – An error occurred when running
pip installfor a package
- property prefix: Path
The prefix directory for this venv.
- Returns:
Full path to the prefix directory for this venv
- Return type:
Path
cyrxnopt.OptimizerABC module
- class cyrxnopt.OptimizerABC.OptimizerABC(venv: NestedVenv)[source]
Bases:
ABCThis is the abstract class for general optimizer algorithms which include all the abstract functions need.
- check_install() bool[source]
Check if an installation for this optimizer exists or not.
- Returns:
Whether the optimizer is installed (True) or not (False).
- Return type:
- abstractmethod get_config() list[dict[str, Any]][source]
Provides descriptions for valid configuration settings for an optimizer.
This method provides information about the possible configuration options and their default values for a given optimizer. The intent is for this method to provide the necessary information for a user-facing program to present the configuration options to the user. Once the user has chosen their desired configurations, they can be set for the optimizer using
set_config().The configuration descriptions returned by this function are dictionaries with three keys, “name”, “type”, and “value”:
“name” will contain the name for the config option in snake_case, with “continuous” or “categorical” prepended to the name if two versions of the option are needed for continuous and categorical variables.
“type” will contain the Python type annotation describing the type to use for this option (for translating to strictly typed languages)
“value” will provide the default value of the option.
“range” is optional and used to specify the allowed range for numbers or to constrain what options a string input can accept. For example, a description of an option for the optimization direction could be:
{ "name": "optimization_direction", "type": str, "value": "min", "range": ["min", "max"] }
“description” is an optional description of the purpose of a config option, along with any caveats that may come with it.
- install(local_paths: dict[str, str] = {}) None[source]
Install the optimizer and its dependencies.
The list of packages to be installed can be checked with the
OptimizerABC.dependencies()property.- Parameters:
local_paths (dict[str, str], optional) – Mapping of package names to local paths to the packages to be installed. The package names in the mapping must match a name returned by
OptimizerABC.dependencies(). Defaults to {}
- abstractmethod predict(prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable | None = None) list[Any][source]
Abstract optimizer prediction function.
- Parameters:
- Returns:
The next suggested conditions to perform
- Return type:
list[Any]
- abstractmethod set_config(experiment_dir: str, config: dict[str, Any]) None[source]
Generates initial configurations and files for an optimizer.
Valid configuration options should be retrieved using
get_config()before calling this function. The key for each option must match the corresponding “name” field and the value type must match the one assigned in the “type” field from the optimizer’sget_config()method.
- abstractmethod train(prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable[[...], float] | None = None) list[Any][source]
Abstract optimizer training function.
- Parameters:
prev_param (list[Any]) – Parameters provided from the previous prediction or training step.
yield_value (float) – Result from the previous prediction or training step.
experiment_dir (str) – Output directory for the optimizer algorithm.
obj_func (Optional[Callable[..., float]], optional) – Objective function to optimize, defaults to None
- Returns:
The next suggested reaction to perform
- Return type:
list[Any]
cyrxnopt.OptimizerAmlro module
- class cyrxnopt.OptimizerAmlro.OptimizerAmlro(venv: NestedVenv)[source]
Bases:
OptimizerABC- get_config() list[dict[str, Any]][source]
Gets the configuration options available for this optimizer.
See
OptimizerABC.get_config()for more information about the config descriptions returned by this method and for general usage information.
- predict(prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable[[...], float] | None = None) list[Any][source]
Searches for the best parameters and records results from prior steps.
OptimizerAmlro.set_config()andOptimizerAmlro.train()must be called prior to this method to generate the necessary files and initial training data for the model.The previous parameter+result is recorded during the next call to
predict(). Theprev_paramandyield_valuevalues provided here are always recorded. Importantly, this also means that the last suggested parameter+result pair from prediction will not be recorded unless either anotherpredict()call is made afterward!- Parameters:
prev_param (list[Any]) – Parameters provided from the previous prediction or from the final call to
OptimizerAmlro.train()yield_value (float) – Result from the previous suggested conditions
experiment_dir (str) – Output directory for saving data files
config (dict[str, Any]) – CyRxnOpt-level config for the optimizer
obj_func (Optional[Callable[..., float]], optional) – Ignored for this optimizer, defaults to None
- Returns:
The next suggested reaction to perform
- Return type:
list[Any]
- set_config(experiment_dir: str, config: dict[str, Any]) None[source]
Generates necessary data files based on the given config.
See
OptimizerABC.set_config()for more information about how to form the config dictionary and for general usage information.
- train(prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable[[...], float] | None = None) list[Any][source]
Suggests and records training data points needed for AMLRO.
OptimizerAmlro.set_config()must be called prior to this method to generate the necessary files.The previous parameter+result is recorded during the next call to either
train()orpredict(). This means that on the first call here, theprev_paramandyield_valuevalues provided are ignored. Importantly, this also means that the last suggested parameter+result pair from training will not be recorded unless either anothertrain()or a subsequentpredict()call are made afterward!- Parameters:
prev_param (list[Any]) – Experimental parameter combination from the previous experiment, provide an empty list for the first call
yield_value (float) – Experimental yield
experiment_dir (str) – Output directory for saving data files
config (dict[str, Any]) – CyRxnOpt-level config for the optimizer
obj_func (Optional[Callable[..., float]], optional) – Ignored for this optimizer, defaults to None
- Returns:
Next parameter combination to perform, or an empty list (
[]) if all training points have been performed- Return type:
list[Any]
cyrxnopt.OptimizerController module
- cyrxnopt.OptimizerController.check_install(optimizer_name: str, venv: NestedVenv) bool[source]
Checks if an optimizer is installed in the given environment.
- Parameters:
optimizer_name (str) – Name of the optimizer algorithm
venv (NestedVenv) – Environment containing the optimizer installation
- Returns:
Whether the optimizer is installed (True) or not (False)
- Return type:
- cyrxnopt.OptimizerController.get_config(optimizer_name: str, venv: NestedVenv) list[dict[str, Any]][source]
Gets the description of the options available for an optimizer.
- Parameters:
optimizer_name (str) – Name of the optimizer algorithm
venv (NestedVenv) – Environment containing the optimizer installation
- Returns:
Descriptions for valid configuration values of the optimizer.
- Return type:
- cyrxnopt.OptimizerController.get_optimizer(optimizer_name: str, venv: NestedVenv) OptimizerABC[source]
Gets an instance of the requested optimizer algorithm
- Parameters:
optimizer_name (str) – Name of the optimizer algorithm
venv (NestedVenv) – Environment containing the optimizer installation
- Raises:
RuntimeError – Invalid optimizer name given
- Returns:
Requested optimizer
- Return type:
- cyrxnopt.OptimizerController.install(optimizer_name: str, venv: NestedVenv, local_paths: dict[str, str] = {}) None[source]
Installs an optimizer into the given environment.
- Parameters:
optimizer_name (str) – Name of the optimizer algorithm
venv (NestedVenv) – Environment containing the optimizer installation
local_paths (dict[str, str], optional) – Mapping of package names to local paths to the packages to be installed, defaults to {}
- cyrxnopt.OptimizerController.predict(optimizer_name: str, venv: NestedVenv, prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable | None = None) list[Any][source]
Predicts new reaction conditions using the given optimizer.
- Parameters:
optimizer_name (str) – Name of the optimizer algorithm
venv (NestedVenv) – Environment containing the optimizer installation
prev_param (list[Any]) – experimental parameter combination for previous experiment
yield_value (float) – experimental yield
experiment_dir (str) – experimental directory for saving data files
config (dict[str, Any]) – Initial reaction feature configurations
obj_func (Optional[Callable], optional) – Objective function needed to optimize, defaults to None
- Returns:
Next suggested reaction conditions
- Return type:
list[Any]
- cyrxnopt.OptimizerController.set_config(optimizer_name: str, venv: NestedVenv, config: dict[str, Any], experiment_dir: str) None[source]
Sets the provided options for the given optimizer.
- Parameters:
optimizer_name (str) – Name of the optimizer algorithm
venv (NestedVenv) – Environment containing the optimizer installation
experiment_dir (str) – Directory to be used for the current experiment. This is where the config files will be output.
- cyrxnopt.OptimizerController.train(optimizer_name: str, venv: NestedVenv, prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable | None = None) list[Any][source]
Predicts new reaction conditions using the given optimizer.
- Parameters:
optimizer_name (str) – Name of the optimizer algorithm
venv (NestedVenv) – Environment containing the optimizer installation
prev_param (list[Any]) – Previous suggested reaction conditions
yield_value (float) – Yield value from previous reaction conditions
experiment_dir (str) – Output directory for the current experiment
obj_func (Optional[Callable], optional) – Objective function to optimize, defaults to None
- Returns:
The next suggested conditions to perform
- Return type:
list[Any]
cyrxnopt.OptimizerEDBOp module
- class cyrxnopt.OptimizerEDBOp.OptimizerEDBOp(venv: NestedVenv)[source]
Bases:
OptimizerABC- get_config() list[dict[str, Any]][source]
Get the configuration options available for this optimizer.
See
OptimizerABC.get_config()for more information about the config descriptions returned by this method and for general usage information.
- predict(prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable[[...], float] | None = None) list[Any][source]
Searches for the best parameters and records results from prior steps.
OptimizerEDBOp.set_config()must be called prior to this method to generate the necessary files.- Parameters:
prev_param (list[Any]) – Parameters provided from the previous prediction, provide an empty list for the first call
yield_value (float) – Experimental yield
experiment_dir (str) – Output directory for any generated files
config (dict[str, Any]) – CyRxnOpt-level config for the optimizer
obj_func (Optional[Callable[..., float]], optional) – Ignored for this optimizer, defaults to None
- Returns:
The next suggested reaction to perform
- Return type:
list[Any]
cyrxnopt.OptimizerNMSimplex module
- class cyrxnopt.OptimizerNMSimplex.OptimizerNMSimplex(venv: NestedVenv)[source]
Bases:
OptimizerABC- get_config() list[dict[str, Any]][source]
Gets the configuration options available for this optimizer.
See
OptimizerABC.get_config()for more information about the config descriptions returned by this method and for general usage information.
- predict(prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable[[...], float] | None = None) list[Any][source]
Find the desired optimum of the provided objective function.
- Parameters:
prev_param (list[Any]) – Parameters provided from the previous prediction, provide an empty list for the first call
yield_value (float) – Result from the previous prediction
experiment_dir (str) – Output directory for the optimizer algorithm
config (dict[str, Any]) – CyRxnOpt-level config for the optimizer
obj_func (Optional[Callable[..., float]], optional) – Objective function to optimize, defaults to None
- Returns:
The next suggested reaction to perform
- Return type:
list[Any]
cyrxnopt.OptimizerSQSnobFit module
- class cyrxnopt.OptimizerSQSnobFit.OptimizerSQSnobFit(venv: NestedVenv)[source]
Bases:
OptimizerABC- get_config() list[dict[str, Any]][source]
Get the configuration options available for this optimizer.
See
OptimizerABC.get_config()for more information about the config descriptions returned by this method and for general usage information.
- predict(prev_param: list[Any], yield_value: float, experiment_dir: str, config: dict[str, Any], obj_func: Callable[[...], float] | None = None) list[Any][source]
Find the desired optimum of the provided objective function.
- Parameters:
prev_param (list[Any]) – Parameters provided from the previous prediction, provide an empty list for the first call
yield_value (float) – Result from the previous prediction
experiment_dir (str) – Output directory for the optimizer algorithm
config (dict[str, Any]) – CyRxnOpt-level config for the optimizer
obj_func (Optional[Callable[..., float]], optional) – Objective function to optimize, defaults to None
- Returns:
The next suggested reaction to perform
- Return type:
list[Any]