Ferric
A Probabilistic Programming Language in Rust with a declarative syntax.
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Example
use Instant;
use make_model;
make_model!
License
How it works
Ferric's make_model! macro declares a probabilistic model and the
relationships between random variables. Within the macro you:
- Define random variables and their generative distributions.
- Mark variables with
observeto indicate data the model will be conditioned on. - Mark variables with
queryto indicate values you want returned in posterior samples.
After expansion, the macro produces a module containing a Model type.
You construct the model by supplying values for the observed fields
(for example let model = grass::Model { grass_wet: true };). Use the
model's sampling API (for example model.sample_iter()) to draw
samples from the posterior; each sample contains the queried variables
as fields that you can inspect to estimate posterior probabilities.
Refer to the Example above for a canonical, end-to-end usage sample.
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
🛠 Development & Testing
1. Install Rust
If you haven't installed Rust yet, follow the official installation instructions here: Install Rust and Cargo Once installed, ensure your toolchain is up to date:
2. Install Coverage Tools
We use cargo-llvm-cov for accurate, source-based code coverage. You will need to install the tool and the required LLVM components:
# Install the LLVM tools component
# Install cargo-llvm-cov
3. Running Tests
To run the standard test suite:
4. Generating Coverage Reports
You can generate coverage data in multiple formats to match our CI environment or for local inspection:
- View in Browser (HTML):
- Generate LCOV (for Coveralls/IDEs):
- Console Summary:
5. IDE Integration (Optional)
If you use VS Code, install the Coverage Gutters extension. After generating an lcov.info file, click the Watch button in the bottom status bar to see line-by-line coverage (green/red highlights) directly in your editor.
Developer
If you're working on the Ferric codebase itself and need to expand the make_model! macro for debugging or inspection, install the following developer tools:
# Install the rust source component (required by some expansion tools)
# Install cargo-expand to make `cargo expand` available
Then you can expand the grass example (or any example) with:
# Expand the `grass` example and print expanded Rust to stdout
# Or save the expanded output to a file for easier reading
Note: cargo expand is a separate tool (provided by the cargo-expand crate) and is not included in the default Cargo installation.
Publishing to crates.io
Follow this updated sequence to publish the crate and any internal dependencies (recommended):
-
- Run tests & build locally:
-
- Ensure versions are synced and
pathdeps includeversion:
- In
ferric-macros/Cargo.tomlset the release version (e.g.0.1.3). - In
ferric/Cargo.tomlreference the local path and published version:
- Ensure versions are synced and
= { = "../ferric-macros", = "0.1.3" }
-
- Obtain crates.io authentication (one-time or CI):
# or (for CI/session)
-
- Publish internal/proc-macro crates first (if any). For
ferric-macros:
- Publish internal/proc-macro crates first (if any). For
- Wait a short time (30–60s) after publishing for the crates.io index to update.
-
- Package & dry-run the main crate, then publish:
- If `cargo package` fails with a dependency version error, it means a required dependency version is not yet available on crates.io — publish that dependency first.
-
- Tag and push git commits:
-
- Post-release housekeeping:
- Move
Unreleasedchanges into the released section ofCHANGELOG.mdand add a newUnreleasedheading. - Bump the next development version if you follow a
X.Y.Z-devworkflow. - Publish docs or update the website and announce the release.
Notes and tips:
- Always publish internal dependencies (proc macros, helper crates) before crates that depend on them.
- Keep
pathdependencies during development but include aversionsocargo packagevalidates. - If the main crate cannot find the new dependency version immediately after publishing, wait a short time and retry.
- Verify
readme,license, andrepositoryfields in eachCargo.tomlto ensure crates.io displays metadata correctly.