DSG Optimization API Reference#
adsg_core.optimization.graph_processor.GraphProcessor(graph: DSGType, encoding_timeout: float = None, encoder_type: SelChoiceEncoderType = None)
#
Base class for the graph processor: the object that captures all logic for using an architecture graph in an optimization problem. A graph processor specifies the optimization problem parameters (design variables, objectives, constraints, other output) and contains methods for converting design variables to objectives/constraints/output.
The graph passed to the processor should be one describing the whole design space, and it should already have external functions defined.
constraints: List[Constraint]
cached
property
#
The optimization problem constraints
des_vars: List[DesVar]
property
#
The optimization problem design variables, ordered as follows:
- Selection choices
- Connection choices
- Additional design variables
Within these groups, design variables are ordered by their name in natural order.
graph: DSGType
property
#
The DSG that forms the basis for this optimization problem
objectives: List[Objective]
cached
property
#
The optimization problem objectives
fix_des_var(des_var: DesVar, value: Union[int, float] = None)
#
Fix a design variable to a specific value. Provide None to unfix.
fixed_value(des_var: DesVar) -> Union[float, int]
#
Get the value of a fixed design variable
free_des_var(des_var: DesVar)
#
Unfix a design variable
get_all_discrete_x(with_fixed=True) -> Optional[Tuple[np.ndarray, np.ndarray]]
#
Returns all possible discrete design vectors. Warning: contains no limits on time or size!
get_graph(des_var_values: Sequence[Union[int, float]], create=True) -> Tuple[DSGType, List[Union[int, float]], List[bool]]
#
Creates a DSG instance from a design vector; optionally only returning the imputed design vector and activeness vector without actually creating the graph
get_imputation_ratio(with_fixed=False, include_cont=True) -> float
#
Get the imputation ratio: the ratio between the declared and valid design space sizes. A value of 1 indicates there is no design space hierarchy, values greater than 1 indicate hierarchy.
get_n_design_space(with_fixed=False, include_cont=False) -> int
#
Get the declared design space size (Cartesian product of discrete variables)
get_n_valid_designs(with_fixed=False, include_cont=False) -> int
#
Get the number of valid (discrete) architectures
get_random_design_vector() -> Sequence[Union[int, float]]
#
Generate a random design vector
get_statistics()
#
Computes the following statistics: - Number of valid combinatorial design points (1) - Number of combinatorial design points (2) - Imputation ratio (2) / (1) --> lower is better - Information index (0 = 1 variable with n options; 1 = m variables with 2 options) --> higher is better - Distance correlation (-1 to 1, 1 means perfect correlation) --> higher is better - Number of existence patterns
for: selection-choices, each connection-choice, additional design variables, total
is_fixed(des_var: DesVar) -> bool
#
Returns whether a design variable is fixed
print_stats()
#
Get and print statistics
adsg_core.optimization.evaluator.DSGEvaluator(graph: DSGType, encoding_timeout: float = None, encoder_type: SelChoiceEncoderType = None)
#
Base class for implementing an evaluator that directly evaluates DSG instances. Override _evaluate to implement the evaluation.
Extends GraphProcessor, so all its functions are also available.
evaluate(dsg: DSGType) -> Tuple[List[float], List[float]]
#
Evaluate a DSG instance. Returns a list of objective values and a list of constraint values.
_evaluate(dsg: DSGType, metric_nodes: List[MetricNode]) -> Dict[MetricNode, float]
#
Implement this function to provide DSG evaluation. Should return a mapping from metric node to float (NaN is allowed).
get_problem(n_parallel=None, parallel_processes=True)
#
Get an SBArchOpt problem instance.
adsg_core.optimization.dv_output_defs.DesVar(name: str, options: list = None, bounds: Tuple[float, float] = None, node: Union[DesignVariableNode, ChoiceNode] = None, is_ordinal=False, conditionally_active=False)
#
Class representing a design variable. A design variable can either be discrete (options are specified) or continuous (bounds are specified). A discrete variable can be ordinal or categorical.
bounds: Optional[Tuple[float, float]]
property
#
Bounds (if continuous)
is_discrete: bool
property
#
Whether the design variable is discrete or continuous
is_ordinal: bool
property
#
Whether the design variable is ordinal or categorical (only relevant if it is a discrete design variable)
n_opts: Optional[int]
property
#
Number of options (if discrete)
name: str
property
#
Design variable name
node: Optional[Union[DesignVariableNode, ChoiceNode]]
property
#
Associated choice node
options: Optional[list]
property
#
List of options (if discrete)
rand()
#
Generate a random value
adsg_core.optimization.dv_output_defs.Objective(name: str, direction=Direction.MIN, node: MetricNode = None)
#
adsg_core.optimization.dv_output_defs.Constraint(name: str, ref: float = 0.0, direction=Direction.LTE, node: MetricNode = None)
#
Class representing an inequality constraint. The direction specifies the side which is considered feasible.
adsg_core.optimization.problem.DSGDesignSpace(processor: GraphProcessor)
#
SBArchOpt design space implementation for a DSG design problem.
adsg_core.optimization.problem.DSGArchOptProblem(evaluator: DSGEvaluator, n_parallel=None, parallel_processes=True)
#
SBArchOpt wrapper for a DSG optimization problem. Note that under the
hood, SBArchOpt uses pymoo.
The connection is made between the ArchOptProblemBase class (which specifies all information needed to optimize an
architecture optimization problem), and the DSGEvaluator class, which contains all information for
running a DSG architecture optimization problem.
Parallel processing is possible by setting n_parallel to a number higher than 1.
By default, assumes parallel processing is done within the thread and therefore starts a multiprocessing pool to
run the parallel evaluations.
Ensure SBArchOpt is installed: pip install sb-arch-opt
Example usage:
from pymoo.optimize import minimize
from sb_arch_opt.algo.pymoo_interface import get_nsga2
evaluator = ... # Instance of DSGEvaluator
algorithm = get_nsga2(pop_size=100)
problem = DSGArchOptProblem(evaluator)
result = minimize(problem, algorithm, termination=('n_eval', 500))