Skip to content

Commit

Permalink
Sharrow Cache Dir Setting (#893)
Browse files Browse the repository at this point in the history
* setting necessary filesystem changes from settings file

* set for multiprocessing
  • Loading branch information
dhensle authored Oct 24, 2024
1 parent ecb00b5 commit cecb570
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
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)
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

0 comments on commit cecb570

Please sign in to comment.