Skip to content

Configure the MATLAB Runtime location with PACE_MCR_DIR / PACE_MCR_VERSION - #43

Open
g5t wants to merge 4 commits into
pace-neutrons:mainfrom
g5t:mcr-from-environment
Open

g5t wants to merge 4 commits into
pace-neutrons:mainfrom
g5t:mcr-from-environment

Conversation

@g5t

@g5t g5t commented Oct 28, 2026

Copy link
Copy Markdown
Member

This lets a site or container set the MATLAB Runtime location once, through environment variables, instead of every script passing matlab_path and matlab_version to Matlab(). It also fixes three bugs that kept the existing PACE_MCR_DIR support from working on Linux.

We hit these while packaging pace_neutrons in an Apptainer image for ESS's VISA analysis machines. That image sets the runtime location in its environment, and users call Matlab() with no arguments.

Changes

Matlab() reads PACE_MCR_DIR and PACE_MCR_VERSION (76b5cb3)

  • Both are used only when the matching argument isn't given, so explicit arguments still take precedence.
  • With a path but no version, the available versions are now looked up inside that path. Previously the default search locations were searched and the path was ignored.
  • pace_neutrons -d/--matlab-dir was parsed but never used. It now sets PACE_MCR_DIR.
  • worker_v4 no longer passes PACE_MCR_VERSION on itself, since Matlab() reads it.
  • The installation docs said the -d location is remembered between runs, which was never implemented. They now describe the environment variables instead.

Version strings with an R prefix are accepted (95183ce)

  • When PACE_MCR_DIR is set, pace_neutrons_cli.utils.set_env exports PACE_MCR_VERSION=R2024a, and worker_v4 passed that to Matlab(matlab_version=...). But the CTFs are keyed 2024a, so the call failed:
    RuntimeError: Compiled library for MATLAB version R2024a not found. Please use: [2021b, 2022a, ...]
    
  • This broke parallel workers whenever PACE_MCR_DIR was set. Matlab() now strips a leading R, so R2024a and 2024a both work.

The runtime library version is parsed on Linux and macOS (e8299f9)

  • get_mlpath derived the version by splitting the library name at the first .. That only works for Windows' mclmcrrt24_1.dll.
  • On Linux the library is libmwmclmcrrt.so.24.1, which gave an empty string and KeyError: ''. So PACE_MCR_DIR, and with this PR -d, never worked through the pace_neutrons and worker_v4 entry points on Linux.
  • The version is now taken with a regular expression that handles all three platforms' names.

Testing

  • These changes are pure Python, so I tested them by overlaying the changed files on the pace_neutrons 0.4.0 wheel in a Python 3.12 venv.
    • The runtime was a fake directory containing only R2024a/runtime/glnxa64/libmwmclmcrrt.so.24.1.
    • Matlab(matlab_version=...) with R2024a, 2024a or r2024A now gets past the CTF lookup.
    • With only PACE_MCR_DIR set, Matlab() picks the 2024a CTF and reaches _libpymcr.
    • get_mlpath() returns (<dir>, 'R2024a').
    • The library-name regex gives the right version for the Windows, Linux and macOS names, for both 24.1 and 9.14.
  • Not yet run against a real runtime. That will happen in the VISA image (R2024a, Ubuntu 22.04), and I'll report back here.
  • The existing test suite needs a MATLAB Runtime, so I didn't add a test to it.

g5t added 3 commits October 28, 2026 09:39
The CLI's set_env exports PACE_MCR_VERSION as e.g. 'R2024a' when
PACE_MCR_DIR is set, and worker_v4 passes it on to Matlab(matlab_version=...),
but the compiled CTFs are keyed by '2024a'. The lookup therefore failed with
'Compiled library for MATLAB version R2024a not found', breaking parallel
workers whenever PACE_MCR_DIR was used. Strip a leading 'R' before matching.
get_mlpath derived the runtime version from the mclmcrrt library name by
splitting on the first '.', which only works for the Windows name
(mclmcrrt24_1.dll). On Linux the library is libmwmclmcrrt.so.24.1, giving
an empty version and a KeyError, so PACE_MCR_DIR could not be used with
the pace_neutrons or worker_v4 entry points there.
Matlab() now falls back to these environment variables when matlab_path
or matlab_version are not given, so a site or container can configure
the runtime once instead of every script passing it. When only a path is
known, the available versions are checked inside that path rather than
in the default search locations.

The -d/--matlab-dir option was parsed but never used; it now sets
PACE_MCR_DIR. worker_v4 no longer needs to forward PACE_MCR_VERSION
itself. The installation docs claimed -d was remembered between runs,
which was never implemented; they now describe the environment variables.

@mducle mducle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Changes look good.

The CI failed at the first step to build PACE but with a non-helpful Jenkins error... I'm going to assume it all passes as I don't want to touch Jenkins again and will migrate the CI to self-hosted github actions (at a later date!)

runtime/glnxa64 also holds the libmwmclmcrrt.so symlink, and inside a
SIF the glob lists it first, so the version pattern found nothing and
pace_neutrons failed with AttributeError. Take the version from the
first library name that has one.
@g5t

g5t commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

I've now actually tested this branch in an apptainer SIF image running on ESS VISA; and as far as I can tell everything works (following the minor change in the latest commit).

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ Proxy