Skip to content

Fix MATLAB interface samples#1911

Merged
speth merged 18 commits intoCantera:mainfrom
ssun30:matlab_fix_samples
Sep 7, 2025
Merged

Fix MATLAB interface samples#1911
speth merged 18 commits intoCantera:mainfrom
ssun30:matlab_fix_samples

Conversation

@ssun30
Copy link
Copy Markdown
Contributor

@ssun30 ssun30 commented Jun 18, 2025

There are numerous changes to class structures to the MATLAB interface that necessitate modifications to our current collection of MATLAB samples.

Changes proposed in this pull request

  • Fix crashes/solver errors in MATLAB samples.
  • Compare the results to their equivalent Python samples to make sure the solutions are correct.

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

Not a fix to #1722 Flame fixes have been deferred to a later PR.

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
  • The pull request is ready for review

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 18, 2025

Codecov Report

❌ Patch coverage is 34.42623% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.43%. Comparing base (4cac7ac) to head (c70683f).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
interfaces/matlab_experimental/Utility/ctPaths.m 0.00% 31 Missing ⚠️
interfaces/matlab_experimental/Utility/ctLoad.m 69.23% 8 Missing ⚠️
interfaces/matlab_experimental/OneDim/Sim1D.m 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1911      +/-   ##
==========================================
+ Coverage   75.04%   75.43%   +0.39%     
==========================================
  Files         450      450              
  Lines       56236    56276      +40     
  Branches     9302     9302              
==========================================
+ Hits        42201    42453     +252     
+ Misses      10898    10687     -211     
+ Partials     3137     3136       -1     

☔ View full report in Codecov by Sentry.
📢 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.

@ssun30 ssun30 force-pushed the matlab_fix_samples branch from 9a6a562 to f8ebb67 Compare June 20, 2025 13:38
Copy link
Copy Markdown
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

@ssun30 ... thanks for addressing!

Out of curiosity: for the Python API, all examples are tested as part of a CI job, see run-examples in .github/workflows/main.yml.

The relevant code is:

   - name: Run the examples
        # See https://unix.stackexchange.com/a/392973 for an explanation of the -exec part.
        run: |
          ln -s libcantera_shared.so build/lib/libcantera_shared.so.3
          export LD_LIBRARY_PATH=build/lib
          find samples/python -type f -iname "*.py" \
          -exec sh -c 'for n; do echo "$n" | tee -a results.txt && python3 "$n" >> results.txt || exit 1; done' sh {} +

I believe it's possible to do something similar here as it's possible to run MATLAB scripts from the command line:

matlab -r "try, run('rankine.m'), catch, exit(1), end, exit(0)"

where I had set matlab to

alias matlab="/Applications/MATLAB_R2023b.app/bin/matlab -nojvm -nodesktop"

on macOS (fwiw, I just ran a quick test so the options may not be the greatest selection)

@ssun30 ssun30 force-pushed the matlab_fix_samples branch 2 times, most recently from f6520e5 to 4863f99 Compare June 30, 2025 20:10
@ssun30 ssun30 force-pushed the matlab_fix_samples branch 2 times, most recently from 36f788e to 123e0e8 Compare July 18, 2025 22:14
@ssun30 ssun30 force-pushed the matlab_fix_samples branch 3 times, most recently from 0aec705 to fc5bd71 Compare August 5, 2025 02:31
@ssun30 ssun30 marked this pull request as ready for review August 5, 2025 02:32
@ssun30 ssun30 requested a review from ischoegl August 5, 2025 02:32
Copy link
Copy Markdown
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

@ssun30 ... thanks for pushing the MATLAB toolbox closer to the finishing line. Changes to the samples are ok, but I do have comments regarding the updated approach for folder management:

  • The ctPaths interface is too complicated - it should be sufficient to provide the root location, and use logic based on known relative paths
  • Except for unit tests, compiled Cantera should use the installed location
  • Unit tests don't need to be installed or distributed with the MLTBX

At this juncture, it also makes sense to start testing all operating systems in CI jobs, i.e., Windows, macOS, and Linux. This can likely be done as a standard matrix job. Further, examples should be run as part of the CI jobs as pointed out in a comment above.

Copy link
Copy Markdown
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

Thanks @ssun30. Thanks for addressing the ctPaths issue which to me was the biggest concern. There are some remaining issues that should be easy to address.

I'm 👍 with deferring some decisions regarding installation and CI runs, but hope that you'll address that feedback in other PRs. Both should be addressed before the 'experimental' suffix can be removed.

Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

I think there's a fair bit of improvement still needed with how paths are set up, but I would suggest that we hold off on that for now in the interest of getting the main feature of this PR in place, which is to have the Matlab CI job run successfully and include running the examples as part of the testing in that job.

% It assumes that the ``gas`` object represents a reacting ideal gas mixture.

% Set the state of the gas, based on the current solution vector.
gas.basis = 'mass';
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.

The default basis should already be "mass", which would be consistent with the Python interface, though I see that the behavior defined in ThermoPhase.m is in fact to default to molar properties.

Copy link
Copy Markdown
Member

@ischoegl ischoegl Sep 6, 2025

Choose a reason for hiding this comment

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

I agree that default behaviors across interfaces should be consistent. The mass/mole switching is unfortunately handled by the interfaces, see Cantera/enhancements#219. Obviously not something that should be addressed here.

@ischoegl ischoegl dismissed their stale review August 26, 2025 20:39

I will defer to @speth for the final approval.

Copy link
Copy Markdown
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

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

I'm likewise interested in resolving the installation question, but I also feel fine with deferring that to after this work. I just had a few simple fixes for consistency and maybe some cleanup.

@ischoegl ischoegl mentioned this pull request Aug 31, 2025
5 tasks
@ssun30 ssun30 force-pushed the matlab_fix_samples branch from b20f051 to 837625c Compare September 4, 2025 17:03
bryanwweber
bryanwweber previously approved these changes Sep 7, 2025
Copy link
Copy Markdown
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

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

Thanks @ssun30 this looks good to me now

ischoegl
ischoegl previously approved these changes Sep 7, 2025
Copy link
Copy Markdown
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

Thanks, @ssun30! While some issues remain to be resolved in follow-up PRs, this is progress.

ssun30 and others added 18 commits September 7, 2025 18:35
Changed refine criteria for Diff_flame
Modified several samples to include this change
Replaced ctRoot with ctPaths, this will allow the
user to set paths to the shared libraries, header
files, and toolboxes more freely, instead of
relying on relative paths to a fixed path for
a certain conda environment.
Currently Func1 may have a partially constructed
object that gets destructed when checks for the
types of input arguments fail, a warning will pop
up when the destructor is called.
Now it only uses relative paths to the environment
where cantera is installed.
The test_examples script can still be used to
run all examples by the user, but it's not
necessary for the unit test suite.
for installing the MATLAB toolbox
Fixed some formatting with cell markers
Now the unit test suite has its own set up methods
to handle the paths
@speth speth dismissed stale reviews from ischoegl and bryanwweber via c70683f September 7, 2025 22:44
@speth speth force-pushed the matlab_fix_samples branch from 1f2b74a to c70683f Compare September 7, 2025 22:44
Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

This is definitely progress in the right direction. Looking forward to more in additional PRs.

@speth speth merged commit 2e01594 into Cantera:main Sep 7, 2025
50 of 51 checks passed
@ssun30 ssun30 deleted the matlab_fix_samples branch September 9, 2025 19:19
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.

5 participants