Skip to content
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

Sharrow Cache Dir Setting #893

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions activitysim/core/configuration/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ def _parse_arg(name, x):

return self

def parse_settings(self, settings):
def _parse_setting(name, x):
v = getattr(settings, x, None)
if v is not None:
setattr(self, name, v)

_parse_setting("cache_dir", "cache_dir")
_parse_setting("sharrow_cache_dir", "sharrow_cache_dir")
_parse_setting("profile_dir", "profile_dir")
_parse_setting("pipeline_file_name", "pipeline_file_name")
return

def get_working_subdir(self, subdir) -> Path:
if self.working_dir:
return self.working_dir.joinpath(subdir)
Expand Down
1 change: 1 addition & 0 deletions activitysim/core/mp_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ def setup_injectables_and_logging(injectables, locutor: bool = True) -> workflow
state = workflow.State()
state = state.initialize_filesystem(**injectables)
state.settings = injectables.get("settings", Settings())
state.filesystem.parse_settings(state.settings)

# register abm steps and other abm-specific injectables
# by default, assume we are running activitysim.abm
Expand Down
9 changes: 3 additions & 6 deletions activitysim/core/workflow/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,12 @@ def load_settings(self) -> State:
include_stack=False,
)

# the settings can redefine the cache directories.
cache_dir = raw_settings.pop("cache_dir", None)
Copy link
Member

Choose a reason for hiding this comment

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

We used "pop" here, this takes this setting off the raw_settings. The revision leaves the setting in place... should we be popping all these values?

I think we need to write a test [or tests] to make sure this is solving the problem well.

if cache_dir:
if self.filesystem.cache_dir != cache_dir:
logger.warning(f"settings file changes cache_dir to {cache_dir}")
self.filesystem.cache_dir = cache_dir
settings_class = self.__class__.settings.member_type
self.settings: Settings = settings_class.model_validate(raw_settings)

# need to parse any filesystem settings set in the settings file itself
self.filesystem.parse_settings(self.settings)

extra_settings = set(self.settings.__dict__) - set(settings_class.__fields__)

if extra_settings:
Expand Down
Loading