Skip to content

Model version switching relies on path state and a one-second pause #169

Description

@ehennestad

Which model version is active is a property of the MATLAB search path, and switching it relies on timing:

  • selectModelVersion removes every version folder from the path, adds the selected one, and then waits: pause(1) % Ad hoc value. Usually at least 0.3 - 0.4 seconds is necessary (line 77) for class definitions to be reloaded.
  • getModelVersion reads the version back by parsing path for version folders, cached for one second with tic/toc, and warns rather than errors when it finds more than one.
  • Any addpath(genpath(...)) from a host application can put a second version on the path; the resources folder name exists specifically to defeat genpath (see internal.constants.Paths).

This is fragile in three ways: a global side effect that any caller can change (openminds-kg-sync switches the version to v3 on every call, ehennestad/openminds-kg-sync#13); a timing workaround that will fail on a slow machine or a large class cache; and state that cannot be queried without parsing the path.

The Python library sidesteps this entirely because all versions are importable at once as namespaces, and fairgraph carries the version on the client object. MATLAB cannot hold two class definitions of the same name, so the path switch stays, but the surrounding machinery can be made explicit.

Proposal:

  • Keep the active version in one place (a setting or a lock file next to the generated folders) that selectModelVersion writes and getModelVersion reads, instead of deriving it from path.
  • Replace the pause with an explicit check that the expected class definition is the one loaded, retried with a short backoff, and an error if it is not.
  • Make putting two versions on the path an error, not a warning, since nothing downstream can work correctly in that state.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions