activitysim
activitysim copied to clipboard
test_prototype_mtc does not work with activitysim 1.3.1
When running activitysim 1.3.1 (installed using the Hacky solution documented in #919), test_prototype_mtc does NOT run, throwing a yaml syntax error.
To Reproduce
- Install activitysim 1.3.1 with
mamba create -n asim activitysim=1.3.1 multimethod=1.9 -c conda-forge --override-channels(see #919 for why multimethod=1.9 is required) - Follow the steps on https://activitysim.github.io/activitysim/v1.3.1/users-guide/run_primary_example.html
activitysim run -c configs -o output -d datagives the following:
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/object/apply:activitysim.core.config.log_file_path'
in "configs\logging.yaml", line 43, column 17
Additional Context
The config line in question is
!!python/object/apply:activitysim.core.config.log_file_path ['activitysim.log']
The relevant tracer line being (I think):
Lib\site-packages\activitysim\core\workflow\logging.py", line 96, in config_logger
config_dict = yaml.load(f, Loader=yaml.SafeLoader)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Working hypothesis
My guess for why this is happening is because at some point activitysim switched to using yaml.SafeLoader at some point, and the config tag !!python/object/apply doesn't work with yaml.SafeLoder.
The most reasonable ChatGPT suggestion states:
Add a Custom Constructor in the Code Update the YAML loader in the activitysim\core\workflow\logging.py file to handle the !!python/object/apply tag.
Here's how to define and register a custom constructor:
import yaml from activitysim.core.config import log_file_path # Define a constructor for the custom tag def log_file_path_constructor(loader, node): args = loader.construct_sequence(node) # Extract the arguments return log_file_path(*args) # Register the constructor for the specific tag yaml.add_constructor( 'tag:yaml.org,2002:python/object/apply:activitysim.core.config.log_file_path', log_file_path_constructor )Place this code in the activitysim\core\workflow\logging.py file before the yaml.load call.
But I don't know enough to act on this.