Skip to content

Matlab auto configure - #2177

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

ssun30 wants to merge 9 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 22.22222% with 112 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.30%. Comparing base (e906c2f) to head (086b347).

Files with missing lines Patch % Lines
interfaces/matlab/Utility/+ct/install.m 0.00% 46 Missing ⚠️
interfaces/matlab/Utility/+ct/load.m 31.57% 39 Missing ⚠️
interfaces/matlab/Utility/+ct/buildInterface.m 0.00% 9 Missing ⚠️
interfaces/matlab/Utility/+ct/uninstall.m 0.00% 6 Missing ⚠️
interfaces/matlab/Utility/+ct/unload.m 0.00% 4 Missing ⚠️
interfaces/matlab/Utility/+ct/addDataDirectories.m 0.00% 3 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   78.46%   78.30%   -0.16%     
==========================================
  Files         463      468       +5     
  Lines       55849    55973     +124     
  Branches     9169     9166       -3     
==========================================
+ Hits        43823    43832       +9     
- Misses       8960     9076     +116     
+ Partials     3066     3065       -1     

☔ 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 interfaces/matlab/+ct/+zeroD/ReactorNet.m Outdated
Comment thread test/matlab/ctTestPureFluid.m Outdated
Comment thread test/matlab/ctTestFlowReactor2.m Outdated
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>
@ssun30
ssun30 force-pushed the matlab_autoConfigure branch from 3994922 to bd75fdf Compare October 8, 2026 01:37
ssun30 and others added 4 commits October 8, 2026 00:03
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>
@ssun30
ssun30 force-pushed the matlab_autoConfigure branch from bd75fdf to aafc3dc Compare October 8, 2026 04:04
ssun30 and others added 4 commits October 8, 2026 01:23
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 97bf782 to 086b347 Compare October 8, 2026 09:59
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.

3 participants