Skip to content

Commit bec1a19

Browse files
fix(custom_experiments): required_properties parameter of decorator was required instead of optional (#278)
* fix(core): required_properties param of decorator should be optional * build(core): Add custom experiment example Test the custom experiment we give as example to user in docs. * test: there should now be 3 experiments * fix(test): update other assertion * fix(test): update one more assertion --------- Co-authored-by: Alessandro Pomponio <[email protected]>
1 parent 40ce0b0 commit bec1a19

File tree

8 files changed

+68
-4
lines changed

8 files changed

+68
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (c) IBM Corporation
2+
# SPDX-License-Identifier: MIT
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) IBM Corporation
2+
# SPDX-License-Identifier: MIT
3+
4+
from typing import Any
5+
6+
from orchestrator.modules.actuators.custom_experiments import custom_experiment
7+
8+
9+
@custom_experiment(output_property_identifiers=["density"])
10+
def calculate_density(mass: float, volume: float) -> dict[str, Any]:
11+
density_value = mass / volume if volume else None
12+
return {"density": density_value}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[build-system]
2+
requires = ["hatchling", "uv-dynamic-versioning>=0.7.0"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "density_test"
7+
description = "Example custom experiment from website docs"
8+
dynamic = ["version"]
9+
10+
[tool.hatch.build]
11+
# Include the full namespace path
12+
include = [
13+
"density/**",
14+
]
15+
16+
[tool.hatch.build.targets.wheel]
17+
only-include = [
18+
"density"
19+
]
20+
21+
[tool.hatch.version]
22+
source = "uv-dynamic-versioning"
23+
24+
[tool.uv-dynamic-versioning]
25+
vcs = "git"
26+
style = "pep440"
27+
pattern = "default-unprefixed"
28+
fallback-version = "0.0.0"
29+
tagged-metadata = true
30+
dirty = true
31+
bump = true
32+
33+
#Add entry point for custom experiments
34+
[project.entry-points."ado.custom_experiments"]
35+
optimization_test_functions = "density.density"
36+

orchestrator/modules/actuators/custom_experiments.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ def check_parameters_valid(func, _required_properties, _optional_properties):
275275

276276

277277
def custom_experiment(
278-
required_properties: list[ConstitutiveProperty | ObservedProperty],
279278
output_property_identifiers: list[str],
279+
required_properties: list[ConstitutiveProperty | ObservedProperty] | None = None,
280280
optional_properties: list[ConstitutiveProperty] | None = None,
281281
parameterization: dict[str, typing.Any] | None = None,
282282
metadata: dict[str, typing.Any] | None = None,
@@ -323,6 +323,7 @@ def calculate_density(mass, volume):
323323

324324
metadata = metadata if metadata else {}
325325
logger = logging.getLogger("custom_experiment_decorator")
326+
required_properties = required_properties if required_properties else []
326327

327328
ray_options_model = None
328329
if ray_options is not None:

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ test = [
8282
"ado-ray-tune",
8383
"ado-sfttrainer",
8484
"anomalous-series",
85+
"density-test",
8586
"optimization-test-functions",
8687
"pfas-custom-functions",
8788
"profile-space",
@@ -100,6 +101,7 @@ members = [
100101
"plugins/operators/profile_space",
101102
"plugins/operators/anomalous_series",
102103
"plugins/actuators/example_actuator",
104+
"examples/density_example",
103105
]
104106

105107
[tool.uv.sources]
@@ -110,6 +112,7 @@ pfas-custom-functions = { workspace = true }
110112
profile-space = { workspace = true }
111113
anomalous-series = { workspace = true }
112114
robotic-lab = { workspace = true }
115+
density-test = { workspace = true }
113116

114117
[project.scripts]
115118
ado = "orchestrator.cli.core.cli:app"

tests/actuators/test_actuators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ def test_custom_experiments(objectiveFunctionConfiguration, experiment_catalogs)
104104
# - examples/optimization_test_functions/custom_experiments
105105
# Locally this may not work because we might have more or less of these.
106106
assert (
107-
len(catalog.experiments) == 2
108-
), "Expected 2 experiments in the custom_experiments catalog for testing "
107+
len(catalog.experiments) == 3
108+
), "Expected 3 experiments in the custom_experiments catalog for testing "
109109

110110
identifiers = {e.identifier for e in catalog.experiments}
111111
assert {
112112
"acid_test",
113+
"calculate_density",
113114
"nevergrad_opt_3d_test_func",
114115
} == identifiers, f"Expected the experiments to be called - acid_test and nevergrad_opt_3d_test_func but they are called {identifiers}"
115116
loaded = custom_experiments.loadedExperiment.remote(
@@ -124,7 +125,7 @@ def test_custom_experiments(objectiveFunctionConfiguration, experiment_catalogs)
124125
"custom_experiments"
125126
)
126127

127-
assert len(c.experiments) == 2
128+
assert len(c.experiments) == 3
128129

129130
for e in c.experiments:
130131
assert catalog.experimentForReference(e.reference) is not None

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ commands=
5151
pytest -n auto --dist worksteal -rx -vv --log-level=INFO --color=yes tests/
5252
# Run the SFTTrainer tests
5353
pytest -n auto --dist worksteal -rx -vv --log-level=INFO --color=yes plugins/actuators/sfttrainer/ado_actuators/sfttrainer/tests/
54+
# Basic test of custom experiment examples
55+
ado describe experiment calculate_density
5456
# Basic test of ray_tune
5557
ado get operator ray_tune
5658
ado template operation --operator-name=ray_tune

uv.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)