Missing Imports in Tutorials - Leads to "name 'MyExperiments' is not defined" Error

I noticed a small issue in some of the tutorials, starting from “Running Inference with a Pretrained Model”. There are two missing import statements at the beginning of the code that lead to errors when running the script:

  1. from dataclasses import asdict
  2. from benchmarks.configs.names import MyExperiments

The second one, particularly (from benchmarks.configs.names import MyExperiments), will result in an error message like this:

name ‘MyExperiments’ is not defined

This can be easily fixed by adding the missing import statements. Although it’s not a big problem, I thought it might be helpful for others who might encounter the same issue.

2 Likes

Thank you so much for pointing this out @xiaowenhao and welcome to the forum! :tada:

If you’d like and have time, you could open a PR and add this in to the tutorial - we appreciate it greatly when our community adds to the project!

Best,

Will

Hi @xiaowenhao, thank you for the report. To make sure I understand what happened.

The original my_experiments.py file has those imports already present:

# Copyright 2025 Thousand Brains Project
#
# Copyright may exist in Contributors' modifications
# and/or contributions to the work.
#
# Use of this source code is governed by the MIT
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

from dataclasses import asdict

from benchmarks.configs.names import MyExperiments

# Add your experiment configurations here
# e.g.: my_experiment_config = dict(...)


experiments = MyExperiments(
    # For each experiment name in MyExperiments, add its corresponding
    # configuration here.
    # e.g.: my_experiment=my_experiment_config
)
CONFIGS = asdict(experiments)

I am guessing that you copied and pasted the code block from Running Inference with a Pretrained Model and replaced the entire my_experiments.py file, or maybe pasted over the existing imports.

Is this what happened? If so, I think we likely need to improve our tutorial instructions.

1 Like

Yes, that’s exactly what happened. I didn’t notice that, and that caused the error I encountered. Thanks for your response!

1 Like

Thank you for the confirmation, and apologies for the trouble with the tutorial. We’ll look at how to structure this better so people won’t encounter the same issue.

2 Likes

I made the updates to the tutorials in this pull request: docs: include asdict and MyExperiments imports in all tutorials by tristanls · Pull Request #344 · thousandbrainsproject/tbp.monty · GitHub. As @brainwaves mentioned, if you find improvements that could be made, we appreciate any pull requests.

4 Likes