-
-
Notifications
You must be signed in to change notification settings - Fork 422
Add a Julia Interface for Cantera (Cantera.jl) #2149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Fastaxx
wants to merge
24
commits into
Cantera:main
Choose a base branch
from
Fastaxx:interface-julia
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2ae2f65
sourcegen: add CLib recipes for kinetic derivatives, _ddX, and Reacto…
Fastaxx 9cb9882
julia: low-level CLib bindings, generator, and library loading
Fastaxx 9ff2c0a
julia: public API
Fastaxx f5b2474
julia: tests and examples
Fastaxx 0626c68
julia: documentation
Fastaxx 35b4217
ci: build libcantera from source and run the Julia suite
Fastaxx e095874
julia: wrap heat release rate, compressibility, expansion, temp limits
Fastaxx d1d5124
julia: wrap stoichiometry, mixture, standard-state, and RoP-derivativ…
Fastaxx 5c0a933
sourcegen: add CLib recipes for standard-state species properties
Fastaxx a608d6a
julia: wrap standard-state properties and heat production rates
Fastaxx c0dec73
ci: simplify Julia workflow
Fastaxx 01cffe5
julia: don't commit generated bindings
Fastaxx 227b4b5
julia: remove Documenter docs
Fastaxx 3f37cb7
sourcegen: tidy ctkin recipes
Fastaxx 89228be
julia: address source review comments
Fastaxx 8d3d15f
julia: fix example run command
Fastaxx 1e7fb08
julia: reorganize and expand tests
Fastaxx 4d2ebec
update authors list
Fastaxx 3516755
julia: strip trailing whitespace
Fastaxx c64d0cb
julia: build docs with scons
Fastaxx d9c67c6
julia: document metaprogrammed thermo accessors
Fastaxx b44cfdf
Update interfaces/julia/.gitignore
Fastaxx 16043b1
julia: type sub-phase view parents concretely
Fastaxx af3cff4
julia: scaffold CLib bindings with sourcegen
Fastaxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # CI for the experimental Julia interface (interfaces/julia). | ||
| # | ||
| # Builds libcantera *from this checkout* (so the generated CLib matches the | ||
| # bindings, including functions this branch adds/renames), then runs the Julia | ||
| # test suite against the freshly built library on Linux. | ||
| name: Julia interface | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - 'interfaces/julia/**' | ||
| - 'interfaces/sourcegen/**' | ||
| - 'interfaces/clib/**' | ||
| - '.github/workflows/julia-interface.yml' | ||
| pull_request: | ||
| paths: | ||
| - 'interfaces/julia/**' | ||
| - 'interfaces/sourcegen/**' | ||
| - 'interfaces/clib/**' | ||
| - '.github/workflows/julia-interface.yml' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Julia ${{ matrix.julia-version }} on ubuntu-latest | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| shell: bash -el {0} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| julia-version: ['1'] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up build dependencies (conda) | ||
| uses: conda-incubator/setup-miniconda@fc2d68f6413eb2d87b895e92f8584b5b94a10167 # v3.3.0 | ||
| with: | ||
| miniforge-version: latest | ||
| activate-environment: build | ||
| python-version: '3.12' | ||
| channels: conda-forge | ||
|
|
||
| - name: Install Cantera build dependencies | ||
| run: | | ||
| # Build toolchain + C++ deps, plus sourcegen's Python deps (jinja2, | ||
| # ruamel.yaml) which are needed to regenerate the CLib during the build. | ||
| conda install -y scons cython "eigen" sundials fmt yaml-cpp hdf5 \ | ||
| "boost-cpp" doxygen openblas jinja2 "ruamel.yaml" | ||
|
|
||
| - name: Build libcantera (shared) | ||
| run: | | ||
| cat > cantera.conf <<EOF | ||
| prefix = '${CONDA_PREFIX}' | ||
| python_package = 'n' | ||
| f90_interface = 'n' | ||
| system_eigen = 'y' | ||
| system_sundials = 'y' | ||
| system_fmt = 'y' | ||
| system_yamlcpp = 'y' | ||
| system_blas_lapack = 'y' | ||
| extra_inc_dirs = '${CONDA_PREFIX}/include' | ||
| extra_lib_dirs = '${CONDA_PREFIX}/lib' | ||
| boost_inc_dir = '${CONDA_PREFIX}/include' | ||
| googletest = 'none' | ||
| EOF | ||
| # `scons build` regenerates the CLib and the low-level Julia bindings | ||
| # from interfaces/sourcegen and auto-generates the doxygen tag it | ||
| # needs (doxygen installed above). | ||
| scons build -j2 | ||
|
|
||
| - name: Set up Julia | ||
| uses: julia-actions/setup-julia@4c0cb0fce8556fdb04a90347310e5db8b1f98fb9 # v2.7.0 | ||
| with: | ||
| version: ${{ matrix.julia-version }} | ||
|
|
||
| - name: Run tests | ||
| env: | ||
| CANTERA_LIBRARY_PATH: ${{ github.workspace }}/build/lib | ||
| CANTERA_DATA: ${{ github.workspace }}/data | ||
| run: | | ||
| julia --project=interfaces/julia -e 'using Pkg; Pkg.instantiate()' | ||
| julia --project=interfaces/julia interfaces/julia/test/runtests.jl | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Julia resolves this per-environment; do not commit. | ||
| Manifest.toml | ||
|
|
||
| /src/generated/ | ||
|
|
||
| # Documenter output. | ||
| docs/build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name = "Cantera" | ||
| uuid = "c8cccd67-5bbd-4b73-b352-8d151246ed36" | ||
| authors = ["Cantera Developers <developers@cantera.org>"] | ||
| version = "0.1.0" | ||
|
|
||
|
Comment on lines
+4
to
+5
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess while this is very much a pre-release feature, we can leave this as an 0.x version, it should be updated to match the Cantera version once this matures. |
||
| [compat] | ||
| julia = "1.9" | ||
|
|
||
| [extras] | ||
| LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
| Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
|
||
| [targets] | ||
| test = ["LinearAlgebra", "Test"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Cantera.jl | ||
|
|
||
| A Julia interface to [Cantera](https://cantera.org) for chemical | ||
| kinetics, thermodynamics, and transport. It links Cantera's native `libcantera` | ||
| directly through the generated CLib API — it is **not** a reimplementation of | ||
| Cantera and has **no** Python dependency. | ||
|
|
||
| ## Install | ||
|
|
||
| Requires Julia 1.9+ and a compiled `libcantera`. Point the package at the | ||
| library (a directory or a full path) and the mechanism data: | ||
|
|
||
| ```bash | ||
| export CANTERA_LIBRARY_PATH=/path/to/cantera/lib # or use a conda env | ||
| export CANTERA_DATA=/path/to/cantera/data # for gri30.yaml, etc. | ||
| ``` | ||
|
|
||
| The low-level CLib bindings are scaffolded by `scons build` and are kept up to | ||
| date by the build process. | ||
|
|
||
| ```julia | ||
| using Pkg | ||
| Pkg.activate("interfaces/julia") | ||
| Pkg.instantiate() | ||
| ``` | ||
|
|
||
| ## Quickstart | ||
|
|
||
| ```julia | ||
| using Cantera | ||
| gas = Solution("gri30.yaml") | ||
| set_TPX!(gas, 1000.0, one_atm, "H2:2, O2:1, N2:4") | ||
| net = ReactorNet(IdealGasReactor(gas)) | ||
| advance!(net, 1e-3) | ||
| temperature(gas) # ignited temperature [K] | ||
| ``` | ||
|
|
||
| ## Documentation | ||
|
|
||
| Exported functions carry docstrings, accessible from the Julia REPL help mode | ||
| (type `?` followed by the function name). See the [`examples/`](examples) | ||
| directory for runnable usage. | ||
|
|
||
| ## Status | ||
|
|
||
| Experimental. This interface targets Cantera's experimental CLib backend, and | ||
| APIs may change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """SConscript file for the generated Julia CLib bindings.""" | ||
| from pathlib import Path | ||
|
|
||
| Import("env", "build") | ||
|
|
||
| # Generated file names can be anticipated from the CLib specifications | ||
| auto_path = Path(Dir("#interfaces/sourcegen/src/sourcegen/headers").abspath) | ||
| yaml_files = sorted(auto_path.glob("ct*.yaml")) | ||
| generated_files = ["#interfaces/julia/src/generated/_manifest.jl"] | ||
| generated_files.extend( | ||
| f"#interfaces/julia/src/generated/lib{yaml_file.stem}.jl" | ||
| for yaml_file in yaml_files) | ||
|
|
||
| sourcegen = env.Command( | ||
| generated_files, | ||
| "#build/doc/Cantera.tag", | ||
| ("$python_cmd -m interfaces.sourcegen.src.sourcegen " | ||
| f"--api=julia --output={Path(Dir('#interfaces/julia').abspath)}") | ||
| ) | ||
| env.Depends(sourcegen, [File(ff) for ff in yaml_files]) | ||
| env.Depends(sourcegen, env.Glob("#interfaces/sourcegen/src/sourcegen/*.py")) | ||
| env.Depends(sourcegen, env.Glob("#interfaces/sourcegen/src/sourcegen/julia/*.*")) | ||
|
|
||
| build(sourcegen) | ||
|
|
||
| Return("sourcegen") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [deps] | ||
| Cantera = "c8cccd67-5bbd-4b73-b352-8d151246ed36" | ||
| Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
|
|
||
| [compat] | ||
| Documenter = "1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Build the Cantera.jl documentation with Documenter. | ||
| # | ||
| # julia --project=interfaces/julia/docs interfaces/julia/docs/make.jl | ||
| # | ||
| # The generated HTML is written to `docs/build`, which the Cantera doc build | ||
| # (doc/SConscript) copies into `build/doc/html/julia` so it is deployed | ||
| # alongside the rest of the Cantera documentation. There is intentionally no | ||
| # `deploydocs` call: deployment is handled by the top-level docs workflow. | ||
| # | ||
| # Requires a working libcantera and the generated CLib bindings (see the | ||
| # interface README); `using Cantera` loads the library to introspect docstrings. | ||
|
|
||
| using Documenter | ||
| using Cantera | ||
|
|
||
| makedocs( | ||
| sitename = "Cantera.jl", | ||
| modules = [Cantera], | ||
| authors = "Cantera Developers", | ||
| pages = [ | ||
| "Home" => "index.md", | ||
| "API Reference" => "reference.md", | ||
| ], | ||
| format = Documenter.HTML( | ||
| prettyurls = get(ENV, "CI", "false") == "true", | ||
| canonical = "https://cantera.org/dev/julia", | ||
| # The API reference is a single @autodocs page; allow it to exceed the | ||
| # default 200 KiB cap rather than splitting the generated listing. | ||
| size_threshold = 512 * 1024, | ||
| ), | ||
| warnonly = true, # the CLib backend is experimental; don't fail on missing refs | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Cantera.jl | ||
|
|
||
| A Julia interface to [Cantera](https://cantera.org) for chemical kinetics, | ||
| thermodynamics, and transport. It links Cantera's native `libcantera` directly | ||
| through the generated CLib API — it is **not** a reimplementation of Cantera and | ||
| has **no** Python dependency. | ||
|
|
||
| !!! warning "Experimental" | ||
| This interface targets Cantera's experimental CLib backend. The API may | ||
| change between releases. | ||
|
|
||
| ## Installation | ||
|
|
||
| Requires Julia 1.9+ and a compiled `libcantera`. Point the package at the | ||
| library and the mechanism data: | ||
|
|
||
| ```bash | ||
| export CANTERA_LIBRARY_PATH=/path/to/cantera/lib # or use a conda env | ||
| export CANTERA_DATA=/path/to/cantera/data # for gri30.yaml, etc. | ||
| ``` | ||
|
|
||
| The low-level CLib bindings are scaffolded by `scons build`, so only the | ||
| environment needs to be instantiated: | ||
|
|
||
| ```bash | ||
| julia --project=interfaces/julia -e 'using Pkg; Pkg.instantiate()' | ||
| ``` | ||
|
|
||
| ## Quickstart | ||
|
|
||
| ```julia | ||
| using Cantera | ||
|
|
||
| gas = Solution("gri30.yaml") | ||
| set_TPX!(gas, 1000.0, one_atm, "H2:2, O2:1, N2:4") | ||
| net = ReactorNet(IdealGasReactor(gas)) | ||
| advance!(net, 1e-3) | ||
| temperature(gas) # ignited temperature [K] | ||
| ``` | ||
|
|
||
| See the [`examples/`](https://github.com/Cantera/cantera/tree/main/interfaces/julia/examples) | ||
| directory for more runnable usage, and the [API Reference](reference.md) for the | ||
| full list of documented functions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # API Reference | ||
|
|
||
| Documentation for the functions and types exported by `Cantera.jl`. | ||
|
|
||
| ```@autodocs | ||
| Modules = [Cantera] | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.