-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: ngen_cal_model_configure
model hook
#161
Changes from all commits
2cae8a5
17badd5
5e3ad14
c101bf0
b1a2cea
56e96db
88f5ae3
29c3528
dd18e0e
813def9
94cd2aa
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ | |||||||
|
||||||||
from abc import ABC, abstractmethod | ||||||||
from ngen.cal.meta import JobMeta | ||||||||
from ngen.cal.configuration import Model | ||||||||
from ngen.cal.configuration import Model, NoModel | ||||||||
from ngen.cal.utils import pushd | ||||||||
from pathlib import Path | ||||||||
from typing import TYPE_CHECKING | ||||||||
|
@@ -59,9 +59,14 @@ def best_params(self) -> str: | |||||||
|
||||||||
class Agent(BaseAgent): | ||||||||
|
||||||||
def __init__(self, model_conf, workdir: Path, log: bool=False, restart: bool=False, parameters: Mapping[str, Any] | None = {}): | ||||||||
def __init__(self, model: Model, workdir: Path, log: bool=False, restart: bool=False, parameters: Mapping[str, Any] | None = {}): | ||||||||
self._workdir = workdir | ||||||||
self._job = None | ||||||||
assert not isinstance(model.model, NoModel), "invariant" | ||||||||
# NOTE: if support for new models is added, support for other model | ||||||||
# type variants will be required | ||||||||
ngen_model = model.model.unwrap() | ||||||||
self._model = model | ||||||||
if restart: | ||||||||
# find prior ngen workdirs | ||||||||
# FIXME if a user starts with an independent calibration strategy | ||||||||
|
@@ -72,17 +77,15 @@ def __init__(self, model_conf, workdir: Path, log: bool=False, restart: bool=Fal | |||||||
# 0 correctly since not all basin params can be loaded. | ||||||||
# There are probably some similar issues with explicit and independent, since they have | ||||||||
# similar data semantics | ||||||||
workdirs = list(Path.glob(workdir, model_conf['type']+"_*_worker")) | ||||||||
workdirs = list(Path.glob(workdir, ngen_model.type+"_*_worker")) | ||||||||
if len(workdirs) > 1: | ||||||||
print("More than one existing workdir, cannot restart") | ||||||||
elif len(workdirs) == 1: | ||||||||
self._job = JobMeta(model_conf['type'], workdir, workdirs[0], log=log) | ||||||||
self._job = JobMeta(ngen_model.type, workdir, workdirs[0], log=log) | ||||||||
|
||||||||
if self._job is None: | ||||||||
self._job = JobMeta(model_conf['type'], workdir, log=log) | ||||||||
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. These steps are minutely important to the use of the Agent, and I don't think they can be dropped...The agent manipulates the configs to ensure root/workdirs are set appropriately under the automatically created agent working dirs. 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. I don't think they are dropped? I was just pulling them from the 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. Sorry, this comment ended up being unclear, it was intended for lines 81-83 where workdir and binary are configured relative to the Agent's dynamically created workdir. These are critical for correct operation of agents especially in PSO where multiple agents are running simultaneously. As noted in disscussion with @aaraney the current 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. Opened #167 to track this. |
||||||||
resolved_binary = Path(model_conf['binary']).resolve() | ||||||||
model_conf['workdir'] = self.job.workdir | ||||||||
self._model = Model(model=model_conf, binary=resolved_binary) | ||||||||
self._job = JobMeta(ngen_model.type, workdir, log=log) | ||||||||
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. I think we are still missing the updated model workdir. An agent has a job which nests information and job/model files under a dynamically created workdir
Suggested change
|
||||||||
ngen_model.workdir = self.job.workdir | ||||||||
self._model.model.resolve_paths(self.job.workdir) | ||||||||
|
||||||||
self._params = parameters | ||||||||
|
@@ -117,4 +120,4 @@ def duplicate(self) -> Agent: | |||||||
data = self.model.__root__.copy(deep=True) | ||||||||
#return a new agent, which has a unique Model instance | ||||||||
#and its own Job/workspace | ||||||||
return Agent(data.dict(by_alias=True), self._workdir) | ||||||||
return Agent(data, self._workdir) |
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.