-
Notifications
You must be signed in to change notification settings - Fork 31
Allow callables directly in the simulation model #254
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,30 +16,31 @@ | |||||||||||||||||||
|
|
||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||
|
|
||||||||||||||||||||
| from queens.drivers._driver import Driver | ||||||||||||||||||||
| from queens.models._model import Model | ||||||||||||||||||||
| from queens.schedulers._scheduler import Scheduler, SchedulerCallableSignature | ||||||||||||||||||||
| from queens.utils.logger_settings import log_init_args | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class Simulation(Model): | ||||||||||||||||||||
| """Simulation model class. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Attributes: | ||||||||||||||||||||
| scheduler (Scheduler): Scheduler for the simulations | ||||||||||||||||||||
| driver (Driver): Driver for the simulations | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| """Simulation model class.""" | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @log_init_args | ||||||||||||||||||||
| def __init__(self, scheduler, driver): | ||||||||||||||||||||
| def __init__(self, scheduler: Scheduler, driver: Driver | SchedulerCallableSignature): | ||||||||||||||||||||
| """Initialize simulation model. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Args: | ||||||||||||||||||||
| scheduler (Scheduler): Scheduler for the simulations | ||||||||||||||||||||
| driver (Driver): Driver for the simulations | ||||||||||||||||||||
| scheduler: Scheduler for the simulations | ||||||||||||||||||||
| driver: Driver for the simulations | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| super().__init__() | ||||||||||||||||||||
| self.scheduler = scheduler | ||||||||||||||||||||
| self.driver = driver | ||||||||||||||||||||
| self.scheduler.copy_files_to_experiment_dir(self.driver.files_to_copy) | ||||||||||||||||||||
| self.function: SchedulerCallableSignature | ||||||||||||||||||||
| if isinstance(driver, Driver): | ||||||||||||||||||||
| self.function = driver.run_from_parameters | ||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this, I reverted the |
||||||||||||||||||||
| self.scheduler.copy_files_to_experiment_dir(driver.files_to_copy) | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| self.function = driver | ||||||||||||||||||||
|
Comment on lines
+38
to
+43
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I mentioned to you in person my personal preference would be this version and keeping the
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def _evaluate(self, samples: np.ndarray) -> dict: | ||||||||||||||||||||
| """Evaluate model with current set of input samples. | ||||||||||||||||||||
|
|
@@ -51,7 +52,7 @@ def _evaluate(self, samples: np.ndarray) -> dict: | |||||||||||||||||||
| response (dict): Response of the underlying model at input samples | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| self.response = self.create_result_dict_from_scheduler_output( | ||||||||||||||||||||
| self.scheduler.evaluate(samples, self.driver) | ||||||||||||||||||||
| self.scheduler.evaluate(samples, self.function) | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| return self.response | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the discussion of #244 and #245, I split up the functionality to allow the use of the driver without parameters. Once more, naming can be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a default to the parameters like
parameters=Nonein the init of the driver to indicate that parameters are not necessarily needed anymore? If we decide to do that, this function here needs to check that the parameters are not None before callingsample_as_dict.