Skip to main content

Crate probl

Crate probl 

Source
Expand description

Compile and run Probl programs from Rust.

Probl is a small language for explicit random choices and weighted worlds: a draw explores its outcomes, each in a world of its own, weighted by how likely it is, and a report collects what the worlds say. This crate is its supported API; the command line (probl-cli) and the playground are built on it.

let source = "let a ~ d6\nlet b ~ d6\nreport a + b >= 10 as \"ten or more\"";
let program = probl::compile("dice.probl", source)?;
let outcome = program.run(&probl::Options::new())?;

let ten = outcome.report("ten or more").unwrap().groups()[0].probability().unwrap();
assert!((ten.point().unwrap() - 6.0 / 36.0).abs() < 1e-12);
assert!(ten.is_complete());
assert_eq!(outcome.text(), "enumerated\n\nten or more    16.67%\n");

A run’s Outcome has its text, as probl run prints it, and each report’s numbers, with what’s known about their accuracy: whether unresolved weight affects them, their bounds, and when sampling, their Monte Carlo error. A program that reads data has it loaded first, with Program::load, from Files the host chooses.

The crates probl-syntax, probl-sema and probl-engine are internal: their APIs change with every release.

Structs§

AssertionResult
Cancel
Stops a run, or the loading of data, from another thread. Clones share the same switch.
ConfidenceInterval
Data
A program’s data, read by Program::load. It can be given to any number of runs of that program.
DataSource
A file, or standard input, that was read: what results were computed from.
Date
A calendar date, from 0001-01-01 to 9999-12-31. It prints, and parses, as YYYY-MM-DD.
DateTime
A calendar datetime with nanosecond precision, normalized to UTC when an input includes an offset. No timezone metadata is retained.
Diagnostic
An error or a warning about a place in a program. It keeps the program’s source, so it can render itself.
Error
A problem compiling a program, loading its data or running it.
Estimate
One reported quantity, such as a probability or a mean, with what’s known about its accuracy.
Evidence
The evidence: the probability (or density) of what the program observed, as a natural logarithm, so that tiny likelihoods don’t underflow.
ExactUpdates
How one variable’s draws were delayed and updated exactly, over all the runs.
FailedRun
The sampled run in which a fault stopped the program.
Failure
The worlds of a partial run that failed at one place, with one kind of fault (docs/semantics.md, section 11).
FaultContext
What a fault that stopped a run says about itself: the failing operation’s inputs, and how often it fails. Every part is optional: an absent one couldn’t be established, which doesn’t mean zero. Its Error’s diagnostic has the same as a note.
FaultInput
An input of a failing operation, in a FaultContext.
Group
What a report saw for one key.
Interval
A range of numbers, both ends included.
Limits
Upper bounds on what a run, and the loading of its data, may do. A program’s @max_worlds and @max_iterations can lower them, never raise them. The default is the command line’s; change a field to change one:
LocalFiles
Local files, for someone running their own programs: the program is trusted, but not with anything but files.
LocalSources
Files on disk: a file imports another relative to its own directory. A path must end in .probl. A file’s identity is its canonical path, so a file reached through a link or by another relative path is the same file. Like LocalFiles, this follows the local file system’s rules; it isn’t a sandbox.
MemoryFiles
Files given as bytes, by the path a program reads them with. There’s no standard input.
MemorySources
Files given as text, by their paths, with / between directories. A file imports another relative to its own directory, as on disk.
NumericSummary
The summaries of real numbers, or of continuous values.
Options
How to run a program. Every setting is optional:
Outcome
What a run gives back.
ParseDateError
A date that isn’t YYYY-MM-DD, or is out of range.
ParseDateTimeError
Program
A compiled program. Cloning it is cheap, and it can run any number of times, from any thread.
QuantileApproximation
Retention/accuracy metadata, separate from Monte Carlo sampling uncertainty. Capacity controls space and measured accuracy, not a guaranteed rank error. More fields may be added, so it’s only constructed by Probl.
Report
One report: what it saw, for each of its keys.
ReportCollectionError
A collection policy that doesn’t parse, or names an invalid capacity.
ReportSummary
Checked, ordered summary columns. Empty selections, duplicates, more than 32 columns and nonfinite/out-of-range quantiles are rejected.
ReportSummaryError
Sampling
How a program was sampled.
SamplingUncertainty
A sampled quantity’s Monte Carlo error.
Snapshots
Another Files, keeping the bytes of everything it has read, so that reading it again gives the same data until clear. The REPL keeps its data this way: it runs a session whose program changes with every input, and earlier bindings mustn’t change under it.
SourceText
An imported file’s text, with its identity and the name diagnostics give it.
Stats
How much work the engine did.
TestCase
One independent test, including its compile error if only this test could not be compiled. Other tests in the suite remain executable.
TestResult
TestSuite
Unresolved
The weight that loops and limits cut off before it finished: an unnormalized bound, not a probability. When sampling, it’s per run.

Enums§

ConfidenceMethod
ErrorKind
What kind of problem an Error is.
EvidenceKind
What kind of number the evidence is.
FailureMode
What a fault in one world, like a division by zero, does to the others (docs/semantics.md, section 11). The world that fails always stops there.
Mode
How a program runs: its @mode, or what Options choose instead.
ReportCollection
What a report retains. Exact collection is the default. More policies may be added, so matches outside this crate need a wildcard arm.
ReportStatistic
One requested report column. A median uses midpoint ties; a quantile uses the weighted inverse CDF, including at level 0.5. More statistics may be added, so matches outside this crate need a wildcard arm.
SamplingStatus
What’s known about a sampled quantity’s Monte Carlo error.
Severity
How serious a Diagnostic is.
SummaryError
Why NumericSummary::quantile gave no quantile.
TestStatus

Constants§

VERSION
This version of Probl.

Traits§

Files
Where read("…") finds data. A program only names paths: what they refer to, and whether they may be read at all, is the host’s to decide, and a program can’t widen it.
Sources
Where the files a program imports come from. A program only names paths: what they refer to, and whether they may be read at all, is the host’s to decide.

Functions§

compile
Compile a program. name is what its diagnostics call it, such as its file’s name. Warnings come with the program; errors come instead of it, as an error of kind Compile.
compile_tests
Compile explicit test syntax. Ordinary compile never enables it based on a filename. A suite owns its source snapshot; executing it doesn’t reload modules.
compile_with
Compile a program that may import files, from sources. name is what its diagnostics call the entry file, and what sources resolves its imports against. Each file the program imports is read once, and each diagnostic says which file it’s about.