StatSim compiler — parse .sm models and compile to PyMC, Stan, TFP.js, Z3
Project description
statsim-compiler
Compiler for the StatSim modeling language. Parses .sm models and compiles them to multiple probabilistic programming backends.
Install
pip install statsim-compiler
Usage
from statsim_compiler import parse, compile, model
# Parse and compile to PyMC code
blocks = parse('p ~ Beta(1, 1)\nx ~ Bin(10, p) | 7\nsample(5000)')
result = compile(blocks, 'pymc')
print(result['code']) # PyMC source code
print(result['param_names']) # ['p']
# High-level: parse + compile + get a runner
runner = model('p ~ Beta(1, 1)\nx ~ Bin(10, p) | 7\nsample(5000)')
print(runner.code) # generated PyMC code
trace = runner.run() # run MCMC inference (requires pymc)
Targets
| Target | Output |
|---|---|
pymc |
PyMC Python code |
stan |
Stan code |
tfpjs |
TensorFlow Probability (JavaScript) |
z3 |
Z3 constraint solver (Python) |
API
parse(source)— parse.smsource, returns aBlockListcompile(blocks, target)— compile to target, returnsdictwithcode,data_names,param_names,inference_modecompile_script(blocks, target)— compile to raw code stringmodel(source, target)— parse + compile + return a runner (PyMC runner fortarget='pymc')
Runner API (PyMC)
runner = model(source, 'pymc')
runner.code # generated source
runner.run(data, **kwargs) # run inference, returns InferenceData
runner.build(data, **kwargs) # get pm.Model for extension
Language
One line, one concept. Math notation:
p ~ Beta(1, 1) # prior
x ~ Bin(10, p) | 7 # observation
delta = p_B - p_A # deterministic
y[i] ~ N(mu, sigma), i=1:N # plated
sample(5000) # directive
See the language reference for the full spec.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file statsim_compiler-0.1.0.tar.gz.
File metadata
- Download URL: statsim_compiler-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50d66f0cfed2f24ff3b5d1ed19306bf2afe65617fafc69976ce9fe219e2c383c
|
|
| MD5 |
afc3a23d7876bf247c74a852b77bb378
|
|
| BLAKE2b-256 |
5ded5438a77fe5ec90c78af7d7194bee41ceda3fc8749dc94975e2206876cd3d
|
File details
Details for the file statsim_compiler-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: statsim_compiler-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 309.3 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b22efd398543976ecf1f4eee0ed6110396e391536df501430e430a5f12627e4
|
|
| MD5 |
d704a1795223edc508ae776b5545fdeb
|
|
| BLAKE2b-256 |
6eb261242945290703b6044cc22cd8066722eb53be1ce03908ec20704499bfa2
|