Your first Bilt model
In this tutorial, you'll build a small motion model and use the same equation to calculate either distance or speed. You'll learn how to declare a system, describe a relationship, create an implementation and request a result.
You only need basic Python. You do not need to understand symbolic algebra or solvers to get started.
1. Set up a project
Bilt requires Python 3.15 or newer. We'll use uv to create a project and install a pre-built release wheel from the Bilt package index:
uv init --python 3.15 my-bilt-project
cd my-bilt-project
uv add bilt --index bilt=https://bilt-framework.github.io/bilt/packages/ --no-build-package bilt
Wheels are published for Linux x86-64 (glibc 2.28+), macOS (Apple Silicon and Intel) and Windows x86-64. If no compatible wheel is available, or you need unreleased changes, install from source instead with a Rust toolchain:
uv add "git+https://github.com/bilt-framework/bilt.git"
Open the generated main.py. Replace its contents with the Python blocks below, in order, then run the file at the end.
2. Declare the values in a system
A system names the quantities that belong to a model. For a simple journey, those are distance, speed and time:
from bilt import Implementation, Interface, equation, field, system
@system
class Motion(metaclass=Interface):
distance: float = field()
speed: float = field()
time: float = field()
@system and metaclass=Interface tell Bilt that Motion is a system interface. Each field() declares a value. Nothing has been calculated yet, and none of these values is permanently an input or output.
3. Describe the relationship
We know that distance equals speed multiplied by time. Add an equation to describe that relationship:
@equation
def motion_relation(distance: float, speed: float, time: float) -> bool:
return distance == speed * time
This looks like a normal Python function, but @equation makes Bilt interpret its body symbolically. It describes the relationship rather than a specific sequence of calculations.
Bilt reads the equation's source code when it is defined, so put it in a Python source file such as main.py.
4. Create an implementation and ask for distance
An implementation connects the system interface to the relationships it can use:
model = Implementation(Motion, [motion_relation])
with model:
journey = Motion(speed=20.0, time=5.0)
distance = journey.distance
assert distance == 100.0
print("Distance:", distance)
Distance: 100.0
The instance supplies two known values. Reading journey.distance asks Bilt to calculate the missing value using the active implementation.
5. Ask the same model a different question
Now suppose we know distance and time but need speed:
with model:
another_journey = Motion(distance=100.0, time=5.0)
speed = another_journey.speed
assert speed == 20.0
print("Speed:", speed)
Speed: 20.0
We have not changed the equation or written a separate formula for speed. Bilt works out a supported way to use the relationship from the known values and requested result.
Run the complete file:
uv run python main.py
You should see:
Distance: 100.0
Speed: 20.0
6. Try it yourself
Change the known values, or create a fresh Motion instance with distance and speed to request its time. Try adding an assertion for the answer you expect.
This small model illustrates the central idea: the model describes relationships, while the request determines the calculation.
In real engineering models, you can also give values physical units, connect reusable subsystems and work with named tensors. Bilt supports many, but not all, possible rearrangements or coupled solves.
Where next?
Read the modelling philosophy and systems and values chapters to continue through the guide in order, or jump to a particular topic:
- Equations and acausal modelling explains how Bilt represents relationships and what kinds of equations it supports.
- Units in models adds physical dimensions and unit conversions.
- Two springs in series extends the same approach to reusable subsystems and coupled equations.
- Systems and implementations API documents the interfaces used in this tutorial.