Getting started¶
Install¶
-
The package (Python 3.10+):
pip install orlabpip install 'orlab[pandas]'adds DataFrame export (Helper.get_dataframe); everything else works without it. -
A JDK — 17 or 21, Adoptium Temurin tested. Let the installer set
JAVA_HOME; JPype finds the JVM through it. If it can't, either exportJAVA_HOMEyourself or passOpenRocketInstance(jvm_path="/path/to/libjvm.so"). -
An OpenRocket jar — let orlab fetch and verify one into its cache:
python -m orlab fetchAfter that,
OpenRocketInstance()needs no configuration. To use a jar you already have instead, passjar_path=toOpenRocketInstance(...)or setORLAB_JAR; the jar guide covers the full resolution order, the cache, and fetching versions orlab doesn't pin.
First simulation¶
import orlab
with orlab.OpenRocketInstance() as instance:
orl = orlab.Helper(instance)
doc = orl.load_doc("rocket.ork")
sim = doc.getSimulation(0)
orl.run_simulation(sim)
data = orl.get_timeseries(
sim, [orlab.FlightDataType.TYPE_TIME, orlab.FlightDataType.TYPE_ALTITUDE]
)
events = orl.get_events(sim)
apogee_time = events[orlab.FlightEvent.APOGEE][0]
finals = orl.get_final_values(sim, [orlab.FlightDataType.TYPE_ALTITUDE])
sim and doc are live Java objects — anything OpenRocket can do to them,
you can too (sim.getOptions().setLaunchRodAngle(...),
orl.get_component_named(sim.getRocket(), "Nose cone").setOverrideMass(...),
…). The Helper methods cover the common paths and convert results to
Python/numpy types.
Worth knowing¶
- One OpenRocket jar per process. JPype cannot restart a JVM: the JVM
starts on first use and stays up until the interpreter exits. Sequential
withblocks and notebook re-runs on the same jar reuse it; a different jar raisesOrlabError. Compare versions with subprocesses. - Seeds:
run_simulationrandomizes the simulation seed on every call by default — what monte-carlo loops want. Passrandomize_seed=Falseto keep a seed you set viasim.getOptions().setRandomSeed(...). On OpenRocket 24.12, a fixed seed reproduces results within one process, but not across processes when wind is enabled (the wind model draws its own entropy at startup). - Memory: large studies may need a bigger heap —
OpenRocketInstance(jvm_args=("-Xmx4g",)). - Version differences: requesting a flight-data constant the loaded
OpenRocket version does not have raises
orlab.errors.UnsupportedFlightDataTypenaming the versions that have it. Constants newer than orlab's enum can be passed as strings:orl.get_timeseries(sim, ["TYPE_SOME_NEW_TYPE"]). - Listeners: subclass
orlab.AbstractSimulationListenerand pass instances viarun_simulation(sim, listeners=[...]). OpenRocket clones listeners (shallow-copy) before the run — mutate shared state (append to a list you keep a reference to) rather than rebinding attributes onselfand reading them back afterwards. Exceptions raised in a listener propagate out ofrun_simulationintact.