Skip to content

Isn't the OneShot RL Skeleton working correctly? #177

@Rintarooort

Description

@Rintarooort

What is your work environment?
OS: macOS 15.5(24F74)

Python version: 3.13.3

Package versions: See requirements.txt section below

SCML version: 0.7.6

Describe the topic you would like to discuss
It seems that context_switch in the OneShotRLAgent may not be functioning as intended in the SCML-OneShot RL skeleton code.

In particular, the SupplierContext is being used even when the agent's production_level is 1, which should correspond to a consumer. This suggests that the context-switching mechanism might not be selecting the correct context based on the agent's level in the production graph.

To investigate, I added logging in the context_switch method of OneShotRLAgent (in scml/oneshot/rl/agent.py) like so:

def context_switch(self):
    aolist = zip(
        self._action_managers, self._obs_managers, range(len(self._obs_managers))
    )
    if self._randomize_test_order:
        aolist = list(aolist)
        shuffle(aolist)
    self._valid_index = -1
    for a, o, i in aolist:
        if a.context.is_valid_awi(
            self.awi, types=(type(self),), raise_on_failure=True
        ) and o.context.is_valid_awi(
            self.awi, types=(type(self),), raise_on_failure=True
        ):
            self._valid_index = i
            print(f"\nproduction level:{self.awi.level}")
            print(
                f"Agent {self.id} is using model {i} with action manager {a.context.__class__.__name__} and observation manager {o.context.__class__.__name__}"
            )
            break

However, based on the logs, even when production level: 1, the selected context is still SupplierContext, as shown below:

production level:1
Agent 06My@1 is using model 0 with action manager SupplierContext and observation manager SupplierContext

production level:1
Agent 04My@1 is using model 0 with action manager SupplierContext and observation manager SupplierContext
...

This suggests that the consumer-specific context (e.g., ConsumerContext) is not being selected properly.

Additional context
All models and contexts are initialized correctly and passed to the agent.

I confirmed that production_level reflects correct consumer/supplier assignment.

The full simulation and evaluation run correctly, but the model may be learning under the wrong context.

If this is not a bug but rather a misconfiguration on my part, I would appreciate any guidance on how to properly configure or validate the context-switching mechanism.

(For privacy, I have removed identifiable user and path information from the log below.)

Sample log output

production level:0
Agent 00My@0 is using model 0 with action manager SupplierContext and observation manager SupplierContext

production level:1
Agent 06My@1 is using model 0 with action manager SupplierContext and observation manager SupplierContext

requirements.txt

Details anyio==4.9.0 appnope==0.1.4 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 beautifulsoup4==4.13.4 bleach==6.2.0 certifi==2025.4.26 cffi==1.17.1 charset-normalizer==3.4.2 click==8.1.8 click-config-file==0.6.0 cloudpickle==3.1.1 colorlog==6.9.0 comm==0.2.2 configobj==5.0.9 contourpy==1.3.2 cycler==0.12.1 debugpy==1.8.14 decorator==5.2.1 defusedxml==0.7.1 dill==0.4.0 executing==2.2.0 Farama-Notifications==0.0.4 fastjsonschema==2.21.1 filelock==3.18.0 fonttools==4.58.0 fqdn==1.5.1 fsspec==2025.5.0 gif==23.3.0 gymnasium==1.1.1 h11==0.16.0 httpcore==1.0.9 httpx==0.28.1 hypothesis==6.131.23 idna==3.10 inflect==5.6.2 iniconfig==2.1.0 ipykernel==6.29.5 ipython==9.2.0 ipython_pygments_lexers==1.1.1 ipywidgets==8.1.7 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 joblib==1.5.0 json5==0.12.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2025.4.1 jupyter==1.1.1 jupyter-console==6.6.3 jupyter-events==0.12.0 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.16.0 jupyter_server_terminals==0.5.3 jupyterlab==4.4.2 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==3.0.15 kiwisolver==1.4.8 markdown-it-py==3.0.0 MarkupSafe==3.0.2 matplotlib==3.10.3 matplotlib-inline==0.1.7 mdurl==0.1.2 mistune==3.1.3 mpmath==1.3.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 negmas==0.11.3 nest-asyncio==1.6.0 networkx==3.4.2 notebook==7.4.2 notebook_shim==0.2.4 numpy==2.2.6 overrides==7.7.0 packaging==25.0 pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 pexpect==4.9.0 pillow==11.2.1 platformdirs==4.3.8 pluggy==1.6.0 progressbar2==4.5.0 prometheus_client==0.22.0 prompt_toolkit==3.0.51 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 py4j==0.10.9.9 pycparser==2.22 Pygments==2.19.1 pyparsing==3.2.3 pytest==8.3.5 pytest-runner==6.0.1 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 python-utils==3.9.1 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.4.0 referencing==0.36.2 requests==2.32.3 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rich==14.0.0 rpds-py==0.25.1 scikit-learn==1.6.1 scipy==1.15.3 scml==0.7.6 seaborn==0.13.2 Send2Trash==1.8.3 setuptools==80.8.0 shellingham==1.5.4 six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 soupsieve==2.7 stable_baselines3==2.6.0 stack-data==0.6.3 stringcase==1.2.0 sympy==1.14.0 tabulate==0.9.0 terminado==0.18.1 threadpoolctl==3.6.0 tinycss2==1.4.0 torch==2.7.0 tornado==6.5.1 tqdm==4.67.1 traitlets==5.14.3 typer==0.15.4 types-python-dateutil==2.9.0.20250516 typing_extensions==4.13.2 tzdata==2025.2 uri-template==1.3.0 urllib3==2.4.0 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 widgetsnbextension==4.0.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions