Skip to content

Matlab auto configure - #2177

Open
ssun30 wants to merge 12 commits into
Cantera:mainfrom
ssun30:matlab_autoConfigure
Open

ssun30 wants to merge 12 commits into
Cantera:mainfrom
ssun30:matlab_autoConfigure

Conversation

@ssun30

@ssun30 ssun30 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request

The MATLAB toolbox is being packaged for MATLAB File Exchange from a separate repository. The package bundles the data files, and MATLAB downloads a self-contained Cantera library (all third-party dependencies statically linked) alongside the compiled interface at install time. This PR adds the MATLAB-side setup for that distribution:

  • Add ct.install: a one-time setup that moves the downloaded interface into the toolbox, adds it to the saved MATLAB path, registers the bundled data directory as a persistent preference, and verifies that Cantera loads.
  • Add ct.uninstall: unloads Cantera and removes the saved path entry and preferences, to be run before removing the toolbox in the Add-On Manager.
  • ct.load now puts the interface folder (which also holds the Cantera shared library) on the OS loader path and re-registers the data directory saved by ct.install.
  • Add ct.addDataDirectories.
  • Fixes: Cantera error text is passed as a format argument so % and \ in messages are preserved; ReactorNet tolerance setters use mReactornet_setTolerances; warning identifiers in ct.unload use a valid format; two tests are updated to match current messages and limits.

If applicable, fill in the issue number this pull request is fixing

Replaces #2146 since it covers a broader list of changes.

If applicable, provide an example illustrating new features this pull request is introducing

This is a pre-requisite for https://github.com/ssun30/cantera_matlab to move out of pre-alpha stage as it introduces the necessary changes to achieve a true one-click install experience for MATLAB users.

AI Statement (required)

Extensive use of generative AI. ct.install, ct.uninstall, and the changes to ct.load and ct.isLoaded were written with an agentic coding tool (Claude Code) from a design I specified: what each function does and how preferences and paths are handled. The tool made implementation decisions, such as removing the prompt-based configuration in favor of a fully automated process running in the background. I reviewed all generated code and tested install, load, reload across MATLAB restarts, and uninstall manually on Windows with MATLAB R2024b.

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • AI Statement is included
  • The pull request is ready for review

@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.23810% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.41%. Comparing base (096972d) to head (e1c1f0e).

Files with missing lines Patch % Lines
interfaces/matlab/Utility/+ct/load.m 42.85% 28 Missing ⚠️
interfaces/matlab/Utility/+ct/buildInterface.m 0.00% 9 Missing ⚠️
interfaces/matlab/Utility/+ct/unload.m 0.00% 4 Missing ⚠️
interfaces/matlab/Utility/+ct/isLoaded.m 50.00% 3 Missing ⚠️
...terfaces/matlab/Utility/+ct/private/hasInterface.m 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2177      +/-   ##
==========================================
- Coverage   77.45%   77.41%   -0.05%     
==========================================
  Files         470      473       +3     
  Lines       57184    57248      +64     
  Branches     9195     9195              
==========================================
+ Hits        44292    44318      +26     
- Misses       9823     9861      +38     
  Partials     3069     3069              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bryanwweber bryanwweber 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.

There's a few bugs here.

Comment thread test/matlab/ctTestPureFluid.m Resolved
Comment thread test/matlab/ctTestFlowReactor2.m Resolved
@ssun30
ssun30 requested a review from bryanwweber October 5, 2026 20:57
@ssun30
ssun30 force-pushed the matlab_autoConfigure branch 3 times, most recently from 97bf782 to 086b347 Compare October 8, 2026 09:59
@ssun30
ssun30 force-pushed the matlab_autoConfigure branch from 086b347 to c5d60c1 Compare October 22, 2026 05:39

@speth speth 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 for continuing to work on the Matlab toolbox installation, @ssun30. Can you help explain how these additions contribute to the goal of a "one click" install experience for toolbox installation and removal? For instance, are the install and uninstall functions ones that will be called automatically by the installer? If so, it would be helpful to explain that in the docstrings for these methods. Otherwise, they seem like mostly unnecessary overhead if the user has to call these manually.

I'm also a little confused about how you're planning for the data files to be distributed here. If they're included with the Matlab toolbox, then they should be installed to a location that is known relative to the toolbox itself, right? In that case, ct.load should already be able to add the data directory based on the relative path to itself, right? This is what the Python module does.

I don't really understand the role of the build_cantera_library.py script. This seems like an extra layer of indirection over just running scons with the appropriate options as part of a GitHub Actions job. And even if you want to break it off as a script, there's a lot of stuff going on in there that seems unnecessary if the point is that this is a script run as part of an Actions job rather than by a user on their local machine. If this is more of a "it works, just don't look at the messy internals" thing, maybe it would be better to have this step be part of the toolbox build itself and live in that repository.

ssun30 and others added 9 commits November 23, 2026 15:08
Add a utility function that adds directories to Cantera's search path
for data files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The MLTBX ships the compiled interface for each platform together with a
self-contained Cantera library and the Cantera data files. Users no
longer need a separate Cantera installation or to launch MATLAB from a
Conda environment.

- ct.install sets the toolbox up once: it saves the data directory
  shipped with the toolbox (or one given as DataDirectory) as a MATLAB
  preference and verifies that Cantera loads. Later calls do nothing
  unless the installation is incomplete or Force is true.
- ct.uninstall unloads Cantera and removes the saved preferences, so the
  toolbox can then be removed in the Add-On Manager.
- ct.load requires the interface built for the current platform, adds
  its folder to the MATLAB path and to the dynamic loader path, and
  re-adds the data directory saved by ct.install.
- ct.isLoaded returns false instead of an error when the interface is
  not on the MATLAB path.
- ctLib becomes a private function, and ct.unload warning identifiers
  use the 'ct:unload:' form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the scripts the cantera_matlab toolbox uses to build its library to
interfaces/matlab/buildUtilities: the library is built with all
third-party dependencies vendored and linked statically, and audited for
non-system dependencies. The toolbox stages these scripts with the rest
of interfaces/matlab and leaves them out of the packaged MLTBX.

The new 'matlab-library' job builds this library on each OS image, and
'matlab-bundled' runs the same matrix and tests as the 'matlab' job with
it, without installing third-party runtime libraries or preloading
OpenBLAS/LAPACK. The existing job can be skipped by setting the
repository variable SKIP_MATLAB_SYSTEM_LIBS to 'true'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R2024b is the oldest release supported by the MATLAB toolbox, so test it
on every OS image without excluded combinations, installing the Visual
C++ 2022 build tools it needs on windows-2025. The library is no longer
needed on windows-2022.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The self-contained library has no third-party runtime dependencies, so
it should load in-process on every platform, including Linux, where the
library built with system dependencies cannot. Load it in-process before
running the tests, which then use the loaded library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With MATLAB R2026b, the clibgen build command on macOS no longer
includes a -std flag. With Xcode 15, clang then defaults to C++98 and
fails to compile the MATLAB Data API headers, breaking the "MATLAB
latest on macos-14" CI job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The interface is built with the system compiler, whose libstdc++ can be
newer than the one MATLAB ships. MATLAB R2024b ships the libstdc++ from
GCC 12 (up to GLIBCXX_3.4.30), while an interface built with GCC 13 needs
GLIBCXX_3.4.32, so it only loaded with the system libstdc++ preloaded.
Linking libstdc++ and libgcc statically removes that dependency; the
interface loads and passes the tests in-process on R2024b and R2026b
without LD_PRELOAD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the interface and the Cantera library both linked statically against
libstdc++, the tests no longer need the system libstdc++ preloaded. Only
building the interface still needs it on Linux, where MATLAB R2024b
crashes while generating the interface otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MATLAB is tested with the self-contained library that ships with the
MATLAB toolbox instead, in the 'matlab-bundled' job. The disabled job is
to be removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ssun30
ssun30 force-pushed the matlab_autoConfigure branch from c5d60c1 to 25ca0e2 Compare November 23, 2026 20:08
ssun30 and others added 2 commits November 23, 2026 15:22
The toolbox installer cannot run code, so ct.install and ct.uninstall would always be manual steps. Like the Python module, ct.load now adds the data files found relative to the toolbox, so no setup or saved preferences are needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run scons with the self-contained build options instead of the build script, which moves to the MATLAB toolbox repository, and build the interface against the in-tree library. The bundled jobs move from the retired macos-14 runners to macos-15 and macos-26, and no longer set CANTERA_DATA, so they test that ct.load finds the data files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The old MATLAB job, already disabled, built the interface against a Cantera
library with system dependencies. It is removed, and the job that tests the
self-contained library shipped with the MATLAB toolbox takes over its name.
@ssun30

ssun30 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for continuing to work on the Matlab toolbox installation, @ssun30. Can you help explain how these additions contribute to the goal of a "one click" install experience for toolbox installation and removal? For instance, are the install and uninstall functions ones that will be called automatically by the installer? If so, it would be helpful to explain that in the docstrings for these methods. Otherwise, they seem like mostly unnecessary overhead if the user has to call these manually.

I'm also a little confused about how you're planning for the data files to be distributed here. If they're included with the Matlab toolbox, then they should be installed to a location that is known relative to the toolbox itself, right? In that case, ct.load should already be able to add the data directory based on the relative path to itself, right? This is what the Python module does.

I don't really understand the role of the build_cantera_library.py script. This seems like an extra layer of indirection over just running scons with the appropriate options as part of a GitHub Actions job. And even if you want to break it off as a script, there's a lot of stuff going on in there that seems unnecessary if the point is that this is a script run as part of an Actions job rather than by a user on their local machine. If this is more of a "it works, just don't look at the messy internals" thing, maybe it would be better to have this step be part of the toolbox build itself and live in that repository.

Thanks for the review @speth . You were right on all three points and I've changed them accordingly.

ct.install and ct.uninstall are now removed. I originally added them since the MLTBX installer can't run code on install or uninstall (ToolboxOptions has no hook for it), so I used the MATLAB preference method as a workaround. Now ct.load will add data directory relative to its own location the same way the Python module does, so no further setup will be required on the user side.

The build_cantera_library.py and the dependency audit code were originally hosted on the cantera_matlab repository. I couldn't recall exactly why I moved it here, but I agree it should stay on that repo.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants