API Overview¶
Start with NewtonSolver, which handles model conversion, state validation, streams, and rigid body proxies.
Use native Solver when you need to manage CUDA arrays and model views yourself.
Common Entry Points¶
| API | Purpose | Reference |
|---|---|---|
ModelBuilder |
Newton builder extensions, rigid body proxies, extra constraints | Python API |
NewtonSolver |
Solver adapter for Newton models and states | Python API |
get_assets / get_asset |
Fetch and locate example assets | Python API |
configure_fluid |
Particle selection and fluid materials | Materials |
configure_granular |
Granular contacts, bonds, plasticity, fracture, adhesion | Materials |
ParticleSurface |
Dynamic triangle meshes from CUDA particles | Python API |
log_surface_mesh |
Send dynamic topology to a Newton viewer | Python API |
login / is_logged_in |
Native session authentication | Authentication |
set_log_callback |
Register native logging callbacks | Native API |
Model / State / Span / Solver |
CUDA memory views and native stepping | Native API |
NewtonSolver Constructor Parameters¶
| Parameter | Default | Meaning |
|---|---|---|
model |
Required | Newton model allocated on CUDA |
joint_damping |
100.0 | Normal damping for generated point-line constraints; finite and nonnegative |
joint_attachment_distance |
0.1 | Anchor spacing for joint direction constraints; finite and positive |
joint_line_half_length |
10.0 | Half-length of generated guide segments; finite and positive |
joint_drive_armature |
0.0 | Optional isotropic inertia regularization for driven bodies; finite and nonnegative |
joint_drive_armature adjusts body inertia; Newton's model.joint_armature adds inertia to supported relative joint DOFs.
They are separate parameters. Retain defaults initially and use joint examples when tuning them.
The Five step Arguments¶
| Argument | Requirement |
|---|---|
state_in |
Newton state with model-compatible counts, dtypes, and device |
state_out |
Separate output state with the same structure |
control |
Newton control for driven joints; may be None without drives |
contacts |
Latest contacts; may be None without shape contacts |
dt |
Seconds; finite and positive |
Native Solver.step() overloads have different signatures; follow the argument order for the chosen interface.
See Simulation Loop for the complete lifecycle.
Native API Example¶
Understand Span First¶
Span(ptr=array.ptr, size=array.size) stores a contiguous CUDA address and an element count.
The size is not measured in bytes. Span neither allocates nor frees memory, and does not keep Warp arrays alive.
Retain all original arrays for indices, masses, gravity, positions, and velocities until their GPU work completes.
numpy.ndarray.ctypes.data is a CPU address and cannot be passed as CUDA memory.
Noncontiguous views, mismatched dtypes, pointers on another device, and freed arrays are also invalid.
A nonzero size requires a non-null address.
Complete Downloadable Example¶
This example uses two particles with zero gravity, constant velocities, and no contacts
to demonstrate ownership and native stepping.
Native Solver does not automatically read environment credentials; the script authenticates interactively in the same process.
"""Demonstrate native Span ownership with a small constant-velocity scene."""
import getpass
import numpy as np
import warp as wp
import style3d_sim as s3d
def span(array: wp.array) -> s3d.Span:
return s3d.Span(ptr=array.ptr, size=array.size)
def main() -> None:
wp.init()
if not wp.is_cuda_available():
raise RuntimeError("This sample requires CUDA")
if not s3d.is_logged_in():
if not s3d.login(input("Style3D Sim account: ").strip(), getpass.getpass("Password: "), False):
raise RuntimeError("Style3D Sim login failed")
device = wp.get_device("cuda:0")
indices = wp.array([0, 1], dtype=wp.int32, device=device)
masses = wp.array([1.0, 1.0], dtype=wp.float32, device=device)
gravity = wp.array([[0.0, 0.0, 0.0]], dtype=wp.vec3, device=device)
positions = wp.array([[0.0, 0.0, 1.0], [1.0, 0.0, 1.0]], dtype=wp.vec3, device=device)
velocities = wp.array([[0.1, 0.0, 0.0], [0.1, 0.0, 0.0]], dtype=wp.vec3, device=device)
next_positions = wp.clone(positions)
next_velocities = wp.clone(velocities)
model = s3d.Model()
model.particle_count = 2
model.particle_indices = span(indices)
model.particle_masses = span(masses)
model.world_count = 1
model.gravity = span(gravity)
state, following = s3d.State(), s3d.State()
state.particle_q, state.particle_qd = span(positions), span(velocities)
following.particle_q, following.particle_qd = span(next_positions), span(next_velocities)
solver = s3d.Solver()
solver.initialize(model)
stream = wp.get_stream(device)
# Keep all Warp allocations alive until asynchronous native work completes.
for _ in range(60):
solver.step(state, following, 1.0 / 60.0, stream)
state, following = following, state
wp.synchronize()
assert np.isfinite(positions.numpy()).all()
print("Native simulation completed")
if __name__ == "__main__":
main()
For contacts or joint controls, choose the relevant native overload and populate Contact, Control, and model Spans yourself.
Beginners can use NewtonSolver to handle those mappings.
Logging Callbacks¶
Register an application callback before creating the solver:
import style3d_sim as s3d
def log_message(file_name, function_name, line, level, message):
print(f"[{level}] {function_name}:{line} {message}")
s3d.set_log_callback(log_message)
Callbacks receive the file name, function name, line number, level, and message. Avoid expensive GPU copies in frequent callbacks and exclude credentials from logs.
How References Stay Updated¶
Documentation builds statically extract public signatures, properties, and docstrings from .py and _core.pyi.
Python signature changes appear automatically. After a native interface change,
maintainers update stubs using the matching extension:
The reference generator does not load _core. New native interfaces appear only after the stubs are updated.