Set Up a Python Project#
The ovstage Python package binds the ovstage C data plane through ctypes. Its
shared loader must be discoverable when the first native operation runs. Programs use Stage and
PathDictionary (both context managers) plus numpy for tensor attribute
I/O.
Note
ovstage is pre-release. The examples consume ovstage as a published wheel
using uv; if the pinned wheel cannot be
resolved, the public wheel is not published yet.
Requirements#
Python 3.10–3.14 (
requires-python = ">=3.10,<3.15"). Recreate the environment with a supported interpreter rather than editing the constraint.NumPy, for tensor I/O (
write_attribute(tensors=...),column.array(...)):pip install numpy
Making ovstage Importable#
Depend on the published ovstage wheel — for example a uv project that pins
it in pyproject.toml (the pattern the examples/python projects use), then
run with uv run. Alternatively, put the ovstage package on PYTHONPATH
directly.
Configuring Transform Updates#
Pass a StageConfig when creating the stage to select the
hierarchy computation model used for automatic transform updates:
import ovstage
config = ovstage.StageConfig(
runtime_default_hierarchy_computation_model=(
ovstage.HierarchyComputationModel.CPU_INCREMENTAL
)
)
with ovstage.Stage("simulation", config=config) as stage:
# A manual computation can select the same configured model.
stage.compute_hierarchy(
input_ordinal=1,
output_ordinal=1,
model=ovstage.HierarchyComputationModel.RUNTIME_DEFAULT,
)
The setting is process-scoped. Configured stages may coexist when their
concrete settings match; creating a stage with a conflicting setting while
another stage remains live raises OvstageError.
RUNTIME_DEFAULT is meaningful as a manual selector. As a configured value,
it does not override the active process default; a fresh process defaults to
CPU incremental.
stage.config returns a detached copy of the process configuration captured
by that stage. It contains the explicit entries from the initialization that
established the active process state; it does not materialize omitted defaults.
Configuring Ordinal Admission#
Use OrdinalAdmissionPolicy to choose how mutations are
checked against retained value and prim-lifecycle changes:
import ovstage
config = ovstage.StageConfig(
runtime_default_ordinal_admission_policy=ovstage.OrdinalAdmissionPolicy.NONDECREASING
)
with ovstage.Stage("simulation", config=config) as stage:
assert (
stage.config.runtime_default_ordinal_admission_policy
== ovstage.OrdinalAdmissionPolicy.NONDECREASING
)
The default is NONDECREASING, which permits repeated writes
at the same unsealed ordinal, while FLOOR_ONLY skips retained-history
conflicts. See Ordinal Admission Policies for the comparison rules.
This setting shares the process lifetime of the hierarchy configuration.
Omission, None and DEFAULT inherit the active policy; they select the
nondecreasing policy only when starting a fresh lifetime. Matching concrete
configurations may coexist. A conflicting policy raises
OvstageError without acquiring an initialization reference
or changing either setting. Close all stages and release any other initialization
references and retained instance owners before selecting another policy.
stage.config reports the original explicit entries, so an omitted policy
remains None and an explicit DEFAULT remains DEFAULT.
Configuring Population Threads#
Population reads what its selectors select serially by default. Set
population_thread_limit to let a population
operation use more threads for those reads:
import ovstage
# Let the runtime choose how many threads each population operation uses.
config = ovstage.StageConfig(population_thread_limit=ovstage.POPULATION_THREAD_LIMIT_AUTO)
with ovstage.Stage("simulation", config=config) as stage:
assert stage.config.population_thread_limit == ovstage.POPULATION_THREAD_LIMIT_AUTO
The limit counts the thread that runs the operation: 1 is serial, N
allows up to N threads, and POPULATION_THREAD_LIMIT_AUTO
lets the runtime choose, up to the concurrency the process allows. The runtime
may use fewer threads. Populated data is the same for every limit.
The limit does not cover the rest of a population operation. Opening and
composing the USD stage and populating the rendering domain keep their own
concurrency, so a limit of 1 does not make a whole population operation
single-threaded. Which population work the limit covers may grow between
releases.
The limit shares the process lifetime of the settings above. None and 0
keep the active limit; a different limit raises OvstageError
until every stage and initialization reference is released.
Selecting the Implementation#
Warning
History support is experimental. The history_selective
implementation, the ovstage.history.v1 selection extension behind
enable_history() and the
retention_window setting can change between
releases without a deprecation period. The library does not guarantee
source compatibility, ABI or semantics. Isolate their use behind an
application adapter. Check availability at run time.
A stage is an instance of the implementation that
implementation selects. Each implementation
of the library has a name and documents it. None or an empty name selects
the default implementation, history_latest.
history_latest is the default. History is off: the stage keeps the latest
value of every cell, and a read returns it.
enable_history() raises
OvstageError with NOT_SUPPORTED on such a stage. Set
the field to select it by name:
import ovstage
# Select the default implementation for this stage by name. History is off.
config = ovstage.StageConfig(implementation="history_latest")
with ovstage.Stage("simulation", config=config) as stage:
assert stage.config.implementation == "history_latest"
config works on every stage and reports the name
the stage was created with.
history_selective turns history on for the pairs the application selects.
enable_history() selects the (prim, attribute)
pairs that retain their earlier sealed values.
retention_window
(OVSTAGE_CONFIG_RETENTION_WINDOW, default 4) bounds the number of sealed
ordinals each selected pair retains. Every other cell keeps the latest value.
The stage serves the history extension ovstage.history.v1. It does not
serve the experimental device placement extension: the placement inputs
raise OvstageError on it. Every other operation runs as
on a stage of history_latest. See Earlier Values of Selected Pairs for the
complete sequence and for the recovery after a failed selection:
config = ovstage.StageConfig(implementation="history_selective", retention_window=8)
with ovstage.Stage("simulation", config=config) as stage:
assert stage.config.implementation == "history_selective"
# ... select pairs with stage.enable_history(query, attributes) ...
The selection is per stage. Stages of different implementations share one
process, so a stage of history_selective and a stage of history_latest
can be open together. A value that is not a string or None raises
TypeError. A name that no implementation of the library has raises
OvstageError with INVALID_ARGUMENT, and no stage is
created. The retention window shares the process lifetime of the settings
above.
Minimal Program#
# Write one value per prim, then advance the watermark before reading.
# wait() reports asynchronous failures; the context manager and finally
# block release the read and its result even if consuming the data fails.
stage.write_attribute(
query, attr, ordinal=1, tensors=np.array([1.0, 2.0, 3.0], np.float32), is_array=False
).wait()
stage.advance_write_floor(ordinal=1).wait()
with stage.read_attributes(query, [attr], OrdinalRange.latest(1)) as read:
read.wait()
group = read.fetch_next()
if group is None:
raise SystemExit("read returned no group at ordinal 1")
try:
# column.array(i) is a zero-copy numpy view of tensor i (CPU).
column = group.columns[0]
print("read back ordinal", column.ordinal, column.array(0)) # -> [1. 2. 3.]
finally:
stage.release_group(group)
Where to Go Next#
Getting Started in Python — run the minimal example.
Python API Reference — the full Python API reference.
Application Flow — the end-to-end lifecycle.