Metadata-Version: 2.2
Name: statsim-compiler
Version: 0.1.0
Summary: StatSim compiler — parse .sm models and compile to PyMC, Stan, TFP.js, Z3
Keywords: statsim,probabilistic-programming,bayesian,compiler,pymc,stan
Author: Anton Zemlyansky
License: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: C++
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Mathematics
Project-URL: Homepage, https://statsim.com
Project-URL: Source, https://github.com/statsim/compiler
Project-URL: Bug Tracker, https://github.com/statsim/compiler/issues
Requires-Python: >=3.9
Provides-Extra: pymc
Requires-Dist: pymc>=5.0; extra == "pymc"
Description-Content-Type: text/markdown

# statsim-compiler

Compiler for the [StatSim](https://statsim.com) modeling language. Parses `.sm` models and compiles them to multiple probabilistic programming backends.

## Install

```bash
pip install statsim-compiler
```

## Usage

```python
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 `.sm` source, returns a `BlockList`
- `compile(blocks, target)` — compile to target, returns `dict` with `code`, `data_names`, `param_names`, `inference_mode`
- `compile_script(blocks, target)` — compile to raw code string
- `model(source, target)` — parse + compile + return a runner (PyMC runner for `target='pymc'`)

## Runner API (PyMC)

```python
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](https://statsim.com/docs) for the full spec.

## License

MIT
