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

test_prototype_mtc does not work with activitysim 1.3.1 #920

Open
chunhochow opened this issue Jan 17, 2025 · 0 comments
Open

test_prototype_mtc does not work with activitysim 1.3.1 #920

chunhochow opened this issue Jan 17, 2025 · 0 comments
Labels
Bug Something isn't working/bug f

Comments

@chunhochow
Copy link

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

  1. Install activitysim 1.3.1 with mamba create -n asim activitysim=1.3.1 multimethod=1.9 -c conda-forge --override-channels (see activitysim 1.3.1 on conda-forge also requires multimethod=1.9 #919 for why multimethod=1.9 is required)
  2. Follow the steps on https://activitysim.github.io/activitysim/v1.3.1/users-guide/run_primary_example.html
  3. activitysim run -c configs -o output -d data gives 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.

@chunhochow chunhochow added the Bug Something isn't working/bug f label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working/bug f
Projects
None yet
Development

No branches or pull requests

1 participant