Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@eddiebergman
Copy link
Contributor

@eddiebergman eddiebergman commented Feb 22, 2024

Fixes a bug where using pipeline.optimize was not actually calling the tell() of the optimizer. Added a test to ensure this does not get removed.

@LennartPurucker tagged for review, no need to if you don't have time as I unfortunately need to merge this now. I've confirmed it works with the tests but also in the other setting via good ol' print debugging. Changes are annotated to expedite the process.

@eddiebergman eddiebergman added the bug Something isn't working label Feb 22, 2024
@eddiebergman eddiebergman self-assigned this Feb 22, 2024
Comment on lines +1183 to +1185
if isinstance(optimizer, Optimizer):
_optimizer = optimizer
else:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main changes here is that previously we would always construct an optimizer, I just shifted the previous code into the else block while using the if part to check if we have an already instantiated one.

Comment on lines +904 to +906
optimizer: (
type[Optimizer] | Optimizer.CreateSignature | Optimizer | None
) = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now accept already instantiated optimizer (Optimizer)

Comment on lines 1255 to +1259

@task.on_result
def tell_optimizer(_: Any, report: Trial.Report) -> None:
_optimizer.tell(report)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, this should have been here...

Comment on lines +146 to +158
class MyOptimizer(SMACOptimizer):
def __init__(
self,
*args: Any,
**kwargs: Any,
) -> None:
self.told_report: Trial.Report | None = None
super().__init__(*args, **kwargs)

@override
def tell(self, report: Trial.Report) -> None:
self.told_report = report
return super().tell(report)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom optimizer we can inspect post fact, it just records the report it was tell'ed about, defaulting to SMAC optimizer for everything else.

Comment on lines +160 to +175
component = Component(object, space={"a": (0.0, 1.0)})
optimizer = MyOptimizer.create(
space=component,
metrics=METRIC,
bucket=PathBucket(tmp_path),
)

history = component.optimize(
target_funtion,
metric=METRIC,
optimizer=optimizer,
max_trials=1,
working_dir=tmp_path,
)

assert optimizer.told_report is history[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass in the instantiated optimizer and ensure that the report it was told about is exactly the same object that is recorded in the history.

@eddiebergman eddiebergman merged commit 0c5f865 into main Feb 22, 2024
@eddiebergman eddiebergman deleted the fix-pipeline-optimizer-tells-optimizer branch February 22, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant