Skip to content

Commit 09b09b8

Browse files
feat: decorator for custom_experiments (#154)
* feat: add OPEN_CATEGORICAL_VARIABLE_TYPE * test: update to new exception msg * refactor: isSubDomain method It was getting long and complex. Create one function for each domain type that checks if another domain is a sub-domain of a domain of that type. * chore: simplification * feat: update open categorical types in entityspace Since the entityspace is fixed on creation strictly it can't have an open categorical dimension. We convert it to categorical with the values passed which will always be a sub-domain of the experiments open-categorical domain. * chore: doc strings * feat: custom_experiments as decorated functions as plugins Just decorate a python function with @custom_experiments to add it - No need for YAML - No need for ado_actuators namespace * feat: agent interface * refactor: update optimization_test_functions To use new decorator * refactor: update optimization_test_functions To use new decorator * refactor: further updates for using decorator * docs: temporarily change included file * fix: minor * fix: can't store function As it can't be serialized * feat: enhanced inference of domain also refactor code into more primitive functions * test: decoration functions * docs(website): Update custom experiment docs * fix: comment for future * feat: Add ExperimentModuleConf for clarity * refactor: change parameter name to output_property_identifiers * docs(website): improvements * feat: new module type * refactor: to new parameter name * chore: fix import * chore: typing * fix: not creating correct model * fix: incorrect anchor * fix: Handle exceptions from custom functions * fix: Handle exceptions from submit() * chore: spelling * test: execution of custom experiment * test: check and infer function properties * refactor: remove unused methods * test: check behaviour if optional property given * fix: Not using reference which may be parameterized * chore: black * chore: fix comment * Apply suggestions from code review Co-authored-by: Alessandro Pomponio <[email protected]> Signed-off-by: Michael Johnston <[email protected]> * refactor: change parameter name * refactor: reorder parameters * refactor: reorder parameters * fix: test --------- Signed-off-by: Michael Johnston <[email protected]> Co-authored-by: Alessandro Pomponio <[email protected]>
1 parent dee913e commit 09b09b8

File tree

16 files changed

+1113
-324
lines changed

16 files changed

+1113
-324
lines changed

.codespellrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
skip = toxenv,./examples/pfas-generative-models/data,./website/theme,adorchestrator.egg-info,*.svg,examples/pfas-generative-models/data/GM_Comparison/Transfromer/Sample_0/test_generations.csv
33
count =
44
quiet-level = 3
5-
ignore-words-list = ser,Transfromer
5+
ignore-words-list = ser,Transfromer,discus

examples/optimization_test_functions/custom_experiments/ado_actuators/optimization_test_functions/custom_experiments.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

examples/optimization_test_functions/custom_experiments/ado_actuators/optimization_test_functions/optimization_test_functions.py

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright (c) IBM Corporation
2+
# SPDX-License-Identifier: MIT
3+
4+
import logging
5+
import typing
6+
7+
from nevergrad.functions import ArtificialFunction
8+
9+
from orchestrator.modules.actuators.custom_experiments import custom_experiment
10+
from orchestrator.schema.domain import PropertyDomain, VariableTypeEnum
11+
from orchestrator.schema.property import (
12+
ConstitutiveProperty,
13+
)
14+
15+
moduleLog = logging.getLogger()
16+
17+
18+
# Decorate the python function with @custom_experiment
19+
# This tells ado
20+
# - The domains of all your parameters i.e. what are valid values they can take
21+
# - The name of the output variable
22+
# - If you use keyword args -> Can extract optional parameters and parameterization
23+
@custom_experiment(
24+
required_properties=[
25+
ConstitutiveProperty(
26+
identifier="x0",
27+
propertyDomain=PropertyDomain(
28+
variableType=VariableTypeEnum.CONTINUOUS_VARIABLE_TYPE
29+
),
30+
),
31+
ConstitutiveProperty(
32+
identifier="x1",
33+
propertyDomain=PropertyDomain(
34+
variableType=VariableTypeEnum.CONTINUOUS_VARIABLE_TYPE
35+
),
36+
),
37+
ConstitutiveProperty(
38+
identifier="x2",
39+
propertyDomain=PropertyDomain(
40+
variableType=VariableTypeEnum.CONTINUOUS_VARIABLE_TYPE
41+
),
42+
),
43+
],
44+
optional_properties=[
45+
ConstitutiveProperty(
46+
identifier="num_blocks",
47+
propertyDomain=PropertyDomain(
48+
variableType=VariableTypeEnum.DISCRETE_VARIABLE_TYPE,
49+
domainRange=[1, 10],
50+
interval=1,
51+
),
52+
),
53+
ConstitutiveProperty(
54+
identifier="name",
55+
propertyDomain=PropertyDomain(
56+
variableType=VariableTypeEnum.CATEGORICAL_VARIABLE_TYPE,
57+
values=["discus", "sphere", "cigar", "griewank", "rosenbrock", "st1"],
58+
),
59+
),
60+
],
61+
parameterization={"num_blocks": 1, "name": "rosenbrock"},
62+
output_property_identifiers=["function_value"],
63+
)
64+
def nevergrad_opt_3d_test_func(
65+
x0: float, x1: float, x2: float, name: str, num_blocks: int
66+
) -> dict[str, typing.Any]:
67+
68+
import numpy as np
69+
70+
# Get the function from nevergrad.functions.ArtificialFunction
71+
func = ArtificialFunction(
72+
name=name,
73+
num_blocks=num_blocks,
74+
block_dimension=int(3 / num_blocks),
75+
translation_factor=0.0,
76+
)
77+
78+
# Call the nevergrad function
79+
value = func(np.asarray([x0, x1, x2]))
80+
81+
return {"function_value": value}

examples/optimization_test_functions/custom_experiments/pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ dependencies = [
1313
[tool.hatch.build]
1414
# Include the full namespace path
1515
include = [
16-
"ado_actuators/optimization_test_functions/**",
16+
"optimization_test_functions/**",
1717
]
1818

1919
[tool.hatch.build.targets.wheel]
2020
only-include = [
21-
"ado_actuators/optimization_test_functions"
21+
"optimization_test_functions"
2222
]
2323

2424
[tool.hatch.version]
@@ -32,3 +32,8 @@ fallback-version = "0.0.0"
3232
tagged-metadata = true
3333
dirty = true
3434
bump = true
35+
36+
#Add entry point for custom experiments
37+
[project.entry-points."ado.custom_experiments"]
38+
optimization_test_functions = "optimization_test_functions.optimization_test_functions"
39+

orchestrator/cli/core/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
register_template_command(app)
6060
register_upgrade_command(app)
6161
register_version_command(app)
62+
# register_hamilton_command(app)
6263

6364

6465
@app.callback()

0 commit comments

Comments
 (0)