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

Expose option to set precision for variables #103

Open
wants to merge 74 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
7c32af2
Improve ReferenceIO solution shape check
schmoelder Dec 5, 2023
cbd69ae
Check cstr volume only when flow rate is not None
schmoelder Dec 2, 2023
5e10679
Fix calculation of conversion rates for MSSMA model
Dec 7, 2023
b4bb2a1
Update CI
schmoelder Dec 9, 2023
00d72cc
Only evaluate objects registered in objective/constraint functions
schmoelder Oct 24, 2023
c5f71d3
Fix objective names
schmoelder Oct 24, 2023
438c542
Restructure OptimizationProblem metrics
schmoelder Oct 25, 2023
5b4dd04
Add `results` in example callback.
schmoelder Oct 27, 2023
9015404
move create_hopsy_problem to separate method
flo-schu Jul 13, 2023
f4b35b1
implement else action if shapes of rounded and unrounded problems do …
flo-schu Jul 26, 2023
580a84e
Add support for creating x0 with linear equality constraints
schmoelder Nov 30, 2023
0125189
Raise warning if x0 is smaller than popsize
schmoelder Jan 9, 2024
3e1898b
Fix behavior of comparisons to references with multiple components
Dec 7, 2023
70e9dfb
Add examples for SMA parameter determination using Yamamoto and inver…
Dec 15, 2023
dd851e7
Temporarily disable test_fit_column_parameters to avoid breaking CI
Jan 10, 2024
5287ec8
Fix jupytext formatting
schmoelder Jan 10, 2024
89ec75e
Add n_difference_metrics property
schmoelder Dec 9, 2023
394d08c
Improve figure styling
schmoelder Dec 9, 2023
6e49da1
Allow setting empty list for output_state for units without destination
schmoelder Dec 2, 2023
a9389d7
Untransform x when evaluating callbacks.
Jan 9, 2024
980dad7
Clarify that OptimizationProblem.transform expects independent space
Jan 10, 2024
23c04ce
Remove increased burn-in when using equality constraints
Jan 10, 2024
d451fbc
Assume x0 contains only independent variables
Jan 10, 2024
aa3f922
Return dependent variables for x0 by default
Jan 10, 2024
fd13a12
Move chebyshev center to own method
schmoelder Jan 10, 2024
895dfe8
Improve docstring
schmoelder Jan 10, 2024
b47cb30
Add check_individual method
schmoelder Jan 10, 2024
8dfde9a
Move validation of x0 to OptimizerBase
schmoelder Jan 10, 2024
8c07312
Small fix: adjust variable types in optimizer.check_x0
Jan 15, 2024
c5f20f8
Use original space for chebychev center
schmoelder Jan 16, 2024
a7229c8
Fix calculation of flow rates for single Cstr
schmoelder Feb 2, 2024
724dc24
Add adapter for LangmuirLDFLiquidPhase
jAniceto Oct 20, 2023
3151154
Add method to create individuals
schmoelder Feb 5, 2024
3ae11df
Update docstrings
schmoelder Feb 7, 2024
f271649
Fix typo
schmoelder Feb 7, 2024
1b7a108
Improve error message
schmoelder Feb 7, 2024
9e1c0b1
Use check_mod_value instead of check_size for modulated parameters
schmoelder Feb 7, 2024
281fdfe
Make characteristic_charge_breaks optional
schmoelder Feb 7, 2024
596032e
Add Cstr to __all__
schmoelder Feb 7, 2024
fed3edb
Add bindings and adapter for two HIC isotherms:
Feb 7, 2024
7fe21b3
Add default value to docstring
schmoelder Feb 9, 2024
53b9b39
Add flag for optimizers that only support single objective
schmoelder Feb 14, 2024
403dcee
Add AxInterface
schmoelder Jun 24, 2023
982bc8a
Add Ax documentation
schmoelder Jun 24, 2023
f84f8da
Add behaviour tests for optimizers
schmoelder Jun 24, 2023
b899751
Fix docstring
schmoelder Feb 14, 2024
3037d18
Add optional pre-processing step before setting optimization variable
schmoelder Feb 26, 2024
b422b32
Use floats for output_state
schmoelder Feb 26, 2024
ad5f390
Fix numpy/scipy deprecation warnings
schmoelder Mar 2, 2024
0e1cb9a
Add short_id to Individual
schmoelder Mar 9, 2024
5dc274c
Fix NormLogTransform if lb==0
schmoelder Mar 9, 2024
80b2053
Add string representation to SolutionBase
schmoelder Mar 9, 2024
1dd7805
Wrap FlowSheet methods for improved docstrings
schmoelder Mar 11, 2024
1f55438
Make some internal methods private
schmoelder Mar 11, 2024
3d78930
Pass feed/eluent/product information to FlowSheet
schmoelder Mar 12, 2024
867573b
Add plot method to TransformBase
schmoelder Feb 5, 2024
a9c86dd
Allow setting state for dependent events
ronald-jaepel Mar 1, 2024
c4d5128
Only use independent variables for hopsy
schmoelder Mar 1, 2024
c21ae41
Use independent variables for linear constraints in Ax
ronald-jaepel Mar 12, 2024
748f08b
Improve behavior for fractionation with empty fractions
schmoelder Mar 11, 2024
ff060ef
Remove waste fractions in initial values if start time coincides with…
schmoelder Mar 14, 2024
441fba8
Cache more properties when locked
schmoelder Dec 5, 2023
0534130
Remove unnecessary code
schmoelder Dec 2, 2023
f208000
Unify post processing
schmoelder Jun 27, 2023
702fb42
Use individuals from meta front for reporting (instead of pareto front)
schmoelder Mar 17, 2024
176358d
Unify updating results
schmoelder Jun 27, 2023
d59c351
Cache results for meta scores
schmoelder Mar 17, 2024
2b2269c
Improve caching
schmoelder Mar 17, 2024
23eb591
Rename typed Dict to Dictionary to avoid conflict with addict
schmoelder Mar 17, 2024
542e142
Add sysinfo
schmoelder Mar 17, 2024
be0e1c8
Store additional information in optimization results
schmoelder Mar 17, 2024
c54b77e
Improve final processing of optimization results
schmoelder Mar 17, 2024
5928483
WIP: Use precision to allow for some slack when untransforming
schmoelder Jul 13, 2023
8f624bb
[Very WIP] something more on precision and transform_kwargs and stuff
schmoelder Mar 20, 2024
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
Prev Previous commit
Next Next commit
Restructure OptimizationProblem metrics
  • Loading branch information
schmoelder committed Jan 24, 2024
commit 438c5425e4488b4e99ce936c3db589edd19951e9
218 changes: 34 additions & 184 deletions CADETProcess/optimization/optimizationProblem.py
Original file line number Diff line number Diff line change
@@ -994,7 +994,7 @@ def add_objective(
objective = Objective(
objective,
name,
type='minimize',
minimize=True,
n_objectives=n_objectives,
bad_metrics=bad_metrics,
evaluation_objects=evaluation_objects,
@@ -3419,38 +3419,33 @@ def __str__(self):
return self.name


class Objective(Structure):
"""Wrapper class to evaluate objective functions."""
class Metric(Structure):
"""Wrapper class to evaluate metrics (e.g. objective/nonlincon) functions."""

objective = Callable()
func = Callable()
name = String()
# TODO: umbennennen
type = Switch(valid=['minimize', 'maximize'])
n_objectives = RangedInteger(lb=1)
n_metrics = n_objectives
n_metrics = RangedInteger(lb=1)
bad_metrics = SizedNdArray(size='n_metrics', default=np.inf)

def __init__(
self,
objective,
func,
name,
type='minimize',
n_objectives=1,
n_metrics=1,
bad_metrics=np.inf,
evaluation_objects=None,
evaluators=None,
labels=None,
args=None,
kwargs=None):

self.objective = objective
self.func = func
self.name = name

self.type = type
self.n_objectives = n_objectives
self.n_metrics = n_metrics

if np.isscalar(bad_metrics):
bad_metrics = np.tile(bad_metrics, n_objectives)
bad_metrics = np.tile(bad_metrics, n_metrics)
self.bad_metrics = bad_metrics

self.evaluation_objects = evaluation_objects
@@ -3470,7 +3465,7 @@ def labels(self):
return self._labels

try:
labels = self.objective.labels
labels = self.func.labels
except AttributeError:
labels = [f'{self.name}']
if self.n_metrics > 1:
@@ -3509,7 +3504,7 @@ def __call__(self, request):
else:
kwargs = self.kwargs

f = self.objective(request, *args, **kwargs)
f = self.func(request, *args, **kwargs)

return np.array(f, ndmin=1)

@@ -3519,103 +3514,29 @@ def __str__(self):
return self.name


class NonlinearConstraint(Structure):
"""Wrapper class to evaluate nonlinear constraint functions."""

nonlinear_constraint = Callable()
name = String()
n_nonlinear_constraints = RangedInteger(lb=1)
n_metrics = n_nonlinear_constraints
bad_metrics = SizedNdArray(size='n_metrics', default=np.inf)

def __init__(
self,
nonlinear_constraint,
name,
bounds=0,
n_nonlinear_constraints=1,
bad_metrics=np.inf,
evaluation_objects=None,
evaluators=None,
labels=None,
args=None,
kwargs=None):

self.nonlinear_constraint = nonlinear_constraint
self.name = name

self.bounds = bounds
self.n_nonlinear_constraints = n_nonlinear_constraints

if np.isscalar(bad_metrics):
bad_metrics = np.tile(bad_metrics, n_nonlinear_constraints)
self.bad_metrics = bad_metrics

self.evaluation_objects = evaluation_objects
self.evaluators = evaluators

self.labels = labels

self.args = args
self.kwargs = kwargs

self.id = uuid.uuid4()

@property
def labels(self):
"""list: List of metric labels."""
if self._labels is not None:
return self._labels

try:
labels = self.nonlinear_constraint.labels
except AttributeError:
labels = [f'{self.name}']
if self.n_metrics > 1:
labels = [
f'{self.name}_{i}'
for i in range(self.n_metrics)
]

if len(self.evaluation_objects) > 1:
labels = [
f"{eval_obj}_{l}"
for l in labels
for eval_obj in self.evaluation_objects
]

return labels

@labels.setter
def labels(self, labels):
if labels is not None:

if len(labels) != self.n_metrics:
raise CADETProcessError(
f"Expected {self.n_metrics} labels."
)
class Objective(Metric):
"""Wrapper class to evaluate objective functions."""
minimize = Bool(default=True)
objective = Metric.func
n_objectives = Metric.n_metrics

self._labels = labels
def __init__(self, *args, n_objectives=1, minimize=True, **kwargs):
self.minimize = minimize

def __call__(self, request):
if self.args is None:
args = ()
else:
args = self.args
super().__init__(*args, n_metrics=n_objectives, **kwargs)

if self.kwargs is None:
kwargs = {}
else:
kwargs = self.kwargs

g = self.nonlinear_constraint(request, *args, **kwargs)
class NonlinearConstraint(Metric):
"""Wrapper class to evaluate nonlinear constraint functions."""

return np.array(g, ndmin=1)
minimize = Bool(default=True)
nonlinear_constraint = Metric.func
n_nonlinear_constraints = Metric.n_metrics

evaluate = __call__
def __init__(self, *args, n_nonlinear_constraints=1, bounds=0, **kwargs):
self.bounds = bounds

def __str__(self):
return self.name
super().__init__(*args, n_metrics=n_nonlinear_constraints, **kwargs)


class Callback(Structure):
@@ -3726,86 +3647,15 @@ def __str__(self):
return self.name


class MetaScore(Structure):
class MetaScore(Metric):
"""Wrapper class to evaluate meta scores."""
meta_score = Metric.func
n_meta_scores = Metric.n_metrics

meta_score = Callable()
name = String()
n_meta_scores = RangedInteger(lb=1)
n_metrics = n_meta_scores
bad_metrics = SizedNdArray(size='n_metrics', default=np.inf)

def __init__(
self,
meta_score,
name,
n_meta_scores=1,
bad_metrics=np.inf,
evaluation_objects=None,
evaluators=None,
labels=None):

self.meta_score = meta_score
self.name = name

self.n_meta_scores = n_meta_scores

if np.isscalar(bad_metrics):
bad_metrics = np.tile(bad_metrics, n_meta_scores)
self.bad_metrics = bad_metrics

self.evaluation_objects = evaluation_objects
self.evaluators = evaluators

self.labels = labels

self.id = uuid.uuid4()

@property
def labels(self):
"""list: List of metric labels."""
if self._labels is not None:
return self._labels

try:
labels = self.meta_score.labels
except AttributeError:
labels = [f'{self.name}']
if self.n_metrics > 1:
labels = [
f'{self.name}_{i}'
for i in range(self.n_metrics)
]

if len(self.evaluation_objects) > 1:
labels = [
f"{eval_obj}_{l}"
for l in labels
for eval_obj in self.evaluation_objects
]

return labels

@labels.setter
def labels(self, labels):
if labels is not None:

if len(labels) != self.n_metrics:
raise CADETProcessError(
f"Expected {self.n_metrics} labels."
)

self._labels = labels

def __call__(self, *args, **kwargs):
m = self.meta_score(*args, **kwargs)

return np.array(m, ndmin=1)

evaluate = __call__
def __init__(self, *args, bounds=0, **kwargs):
self.bounds = bounds

def __str__(self):
return self.name
super().__init__(*args, **kwargs)


class MultiCriteriaDecisionFunction(Structure):