Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
75d3c9a
feat(sim): default Newton rigid simulation to MJVBD V2
Sep 17, 2026
731a20d
fix(sim): tune MJVBD V2 manipulation examples and record limitations
Sep 18, 2026
51af322
fix(tutorial): align drawer damping across physics backends
Sep 20, 2026
bc5369b
docs(sim): clarify MJVBD V2 coupling and control limitations
Sep 20, 2026
5f19889
fix(sim): adapt examples to DexUni solver config
yuecideng Sep 29, 2026
1e9d5f9
Merge remote-tracking branch 'origin/main' into codex/dexuni-interfac…
yuecideng Sep 29, 2026
347ce76
fix(sim): unify Newton solver adaptation on DexUni
yuecideng Sep 29, 2026
aa9f0b6
feat(sim): expose DexUni contact sensor data
yuecideng Sep 29, 2026
1832e56
test(sim): cross-check DexUni contact impulses
yuecideng Sep 29, 2026
c763aad
test(sim): assert DexUni contact invariants
yuecideng Sep 29, 2026
32e08fc
Merge remote-tracking branch 'origin/main' into codex/dexuni-interfac…
yuecideng Oct 3, 2026
7049fcf
fix(sim): update DexUni migration validation
yuecideng Oct 3, 2026
a09bd7e
docs(sim): use DexUni terminology consistently
yuecideng Oct 3, 2026
ad9ba87
wip
yuecideng Oct 4, 2026
b589354
Merge latest main into DexUni interface adaptation
yuecideng Oct 10, 2026
9428020
feat(physics): support current DexUni two-way coupling contracts
yuecideng Oct 10, 2026
6e60b8e
fix(dexsim): adapt latest 0.5.1 runtime contracts
yuecideng Oct 20, 2026
794bbb9
feat(dexsim): consolidate two-way coupling adaptation from PR #720
yuecideng Oct 21, 2026
e8a6419
fix(dexsim): reconcile current particle material and task contracts
yuecideng Oct 21, 2026
fa953fe
feat(sim): Add a simple Newton functional solver example
yuecideng Oct 22, 2026
e3d087c
fix(sim): Reject closed loops in the simple slider solver
yuecideng Oct 22, 2026
a6b206b
test(sim): Distinguish optional SDK coverage from integration acceptance
yuecideng Oct 22, 2026
a6f863f
docs(sim): Resolve the integration SDK runtime dependencies
yuecideng Oct 22, 2026
3a75a46
fix(sim): Keep optional solver inspectable with released SDK
yuecideng Oct 22, 2026
9a7bbaa
fix(docs): Resolve optional solver annotations on released SDK
yuecideng Oct 22, 2026
3faf27d
fix(sim): Preserve supported Newton initialization targets
yuecideng Oct 22, 2026
3fcc0fb
feat(sim): Configure custom Newton solvers with direct factories
yuecideng Oct 24, 2026
b8922a0
Merge latest main into DexSim adaptation
yuecideng Oct 27, 2026
57d0262
fix(dexsim): follow current DexUni dispatch and device defaults
yuecideng Oct 27, 2026
1eef398
feat(sim): expose DexSim controls and deformable initialization
Oct 27, 2026
9a2d016
fix(sim): preserve continuous URDF joint limits for DexUni
yuecideng Oct 27, 2026
a48f07c
fix(examples): complete DexUni workflows and physical placement checks
yuecideng Oct 27, 2026
f9f128d
Merge main be57e1b97 into DexUni adaptation
yuecideng Oct 27, 2026
4d72509
fix(examples): preserve placement asset frames across renderers
yuecideng Oct 27, 2026
da67a3e
Merge main into codex/adapt-latest-dexsim
yuecideng Nov 2, 2026
37085da
Merge main and adapt DexSim 0.6 contact reports
yuecideng Nov 7, 2026
731427f
refactor(sim): narrow Newton articulation root options
yuecideng Nov 7, 2026
834f88d
refactor(sim): remove legacy AutoSolver compatibility
yuecideng Nov 7, 2026
a6c3693
docs(sim): standardize native DexUni automatic dispatch
yuecideng Nov 7, 2026
f249fbe
update dexsim version
yuecideng Nov 7, 2026
8f792d0
Merge branch 'main' into codex/adapt-latest-dexsim
yuecideng Nov 7, 2026
21d2bac
Adapt PR #844 solver providers to latest DexSim on PR #829
yuecideng Nov 7, 2026
28f8b6a
fix(sensors): honor native contact sampling boundaries
yuecideng Nov 7, 2026
3aafa0c
Merge latest main into codex/adapt-latest-dexsim
yuecideng Nov 9, 2026
97f5cb6
Merge latest DexSim adaptation and main into PR #844
yuecideng Nov 9, 2026
ab9bb96
Merge latest main into PR #844
yuecideng Nov 10, 2026
3b07241
Merge latest main into PR #844
yuecideng Nov 11, 2026
dad2cfc
refactor(sim): Move sample Newton provider into tutorial
yuecideng Nov 11, 2026
64db835
docs(sim): Visualize custom Newton tutorial with Viser
yuecideng Nov 11, 2026
1f79c32
feat(sim): Add offscreen camera preview to Newton tutorial
yuecideng Nov 11, 2026
eb95463
feat(sim): Record custom Newton tutorial offscreen video
yuecideng Nov 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions agent_context/topics/simulation-system/physics-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,32 @@ contact-path policy. Expert settings use the native option groups
are rejected for mappings and native config objects, and flat DexUni options
are rejected by native validation.
Standalone SPH is not a supported solver family; fluid settings belong under
[DexUni's nested SPH configuration](fluids.md). Gradient mode requires an explicit
`semi_implicit` solver. Read exact solver options/defaults in
`cfg/physics.py` and the installed DexSim config types; do not substitute a
[DexUni's nested SPH configuration](fluids.md). Robot presets select
`newton_dexuni` before the MuJoCo aliases and portable fallbacks. Gradient mode
requires an explicit `semi_implicit` solver or a direct/named provider supporting
the requested gradient mode. Functional Scene calls additionally require its
functional dynamics service. Python callers pass DexSim's
`ProviderNewtonSolverCfg` with a provider class/zero-argument factory directly
through `solver_cfg`; this path does not inspect installed metadata. DexSim
creates fresh instances per model build. Installed `dexsim.newton_solvers`
names pass through to DexSim's `RegisteredNewtonSolverCfg`; unregistered names
remain errors. Read exact solver options/defaults in `cfg/physics.py` and the
installed DexSim config types; do not substitute a
hardcoded fallback when an expected DexSim API is absent.

The spring-slider provider lives only in
`scripts/tutorials/sim/simple_newton_solver/`; see its
[tutorial](../../../docs/source/tutorial/simple_newton_solver.rst) for functional
Scene stepping. It is not a packaged solver or registered entry point.

Articulation initialization also calls `reset(clear_dynamics=False)` without a
later coordinated clear. Preserve its position hold targets and mimic target
propagation when the solver accepts them. Query the finalized public
`Scene.dynamics_capabilities().supported_control_fields`; only an explicit
exclusion of `joint_target_q` suppresses that command. Released SDKs predating
extensions retain their unrestricted target behavior. Extension SDKs missing
the query require an upgrade instead of guessing support from solver names.

`collision_cfg` owns the external Newton contact pipeline. Its
`update_interval=None` updates at the first local solver substep; positive `k`
updates at `0, k, 2k, ...`, reusing contacts between updates. `collision_cfg=None`
Expand Down
136 changes: 136 additions & 0 deletions docs/source/tutorial/simple_newton_solver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
Build a custom Newton solver
============================

This tutorial implements a spring-slider solver with DexSim's Newton extension
interface. All of its code lives in ``scripts/tutorials/sim/simple_newton_solver/``;
the provider is an example, not an EmbodiChain solver or package entry point.
The scene contains two independent prismatic sliders, one in each environment.

Run the example
---------------

Use a DexSim build that provides ``ProviderNewtonSolverCfg``,
``FunctionalDynamics`` and ``Scene.dynamics_capabilities()``. From the repository
root, run against an installed EmbodiChain environment or expose this checkout:

.. code-block:: bash

export PYTHONPATH="$PWD:$PWD/extensions${PYTHONPATH:+:$PYTHONPATH}"
python scripts/tutorials/sim/simple_newton_solver/demo.py --device cpu \
--preview-path simple_newton_solver_preview.png

Use ``--device cuda:0`` to run the same numerical example on CUDA. The script
runs headlessly. It checks native/functional parity and state isolation before
printing JSON. A successful CPU run reports approximately:

.. code-block:: json

{
"native_functional_parity": true,
"published_position": [0.020873, 0.031310],
"partial_reset_position": [0.0, 0.031310],
"force_gradient": [0.00012048, 0.00050749],
"force_scale_gradient": 0.00352685
}

The optional PNG plots the two slider trajectories. Its dashed final segment
shows that resetting ``arena_0`` returns only the first slider to zero.

For an image rendered by EmbodiChain's native offscreen camera, run:

.. code-block:: bash

python scripts/tutorials/sim/simple_newton_solver/demo.py --device cpu \
--render-path simple_newton_offscreen.png

The resulting PNG has environment 0 and 1 in the left and right columns, with
initial and after-30-step views in the top and bottom rows. The script reserves
FastRT before constructing the World, creates a ``CameraCfg`` in each arena,
renders through ``SimulationManager.render_camera_group()``, and reads the RGB
frames from ``Camera.get_data()``. This needs a working native GPU renderer even
when the solver runs on the CPU.

To record the same offscreen cameras as a video, run:

.. code-block:: bash

python scripts/tutorials/sim/simple_newton_solver/demo.py --device cpu \
--video-path simple_newton_offscreen.mp4

The H.264 MP4 places the two environments side by side and records all 30
native simulation steps at 10 fps, with short holds on the initial and final
poses. It requires ``ffmpeg`` with ``libx264`` on ``PATH``. Combine
``--render-path`` and ``--video-path`` to save both outputs in one run.

To inspect the actual EmbodiChain scene in Viser, run:

.. code-block:: bash

python scripts/tutorials/sim/simple_newton_solver/demo.py --device cpu \
--viser --viser-seconds 60

Open ``http://127.0.0.1:8080`` while the script runs. Viser receives both URDF
slider meshes, then shows 30 native simulation steps. The scene remains open
for the requested number of seconds after replay. Use ``--viser-port PORT`` if
8080 is in use. The ``base`` link has no visual geometry, so the visible objects
are the two cubes. This browser view uses EmbodiChain's
``SimulationManager.capture_visualization()`` and does not require a native
render window.

Follow the data flow
--------------------

1. ``demo.py`` passes the local ``SimpleSolverProvider`` class to
``NewtonPhysicsCfg`` through DexSim's ``ProviderNewtonSolverCfg``. The direct
factory path does not require package entry-point registration.
2. ``SimulationManager.prepare()`` finalizes the scene and asks DexSim to create
a fresh provider for the model. The provider validates the slider model and
declares effort-only controls, reset support and no CUDA Graph support.
3. ``_SliderDynamics.step()`` applies effort, spring force and damping, then
updates velocity and position with semi-implicit Euler. Its Torch operations
preserve gradients in the functional path.
4. The native ``SolverBase`` adapter calls that same transition under
``torch.no_grad()`` and writes the resulting state to the next Newton state.
``demo.py`` checks that one native step matches one functional step.
5. Functional stepping with ``publish=False`` leaves the live scene untouched.
``publish=True`` publishes a detached physical state and advances the Scene
clock once. The returned functional tensors retain their gradient graph.
Reset selects arenas independently.

For a slider coordinate ``q``, velocity ``v``, effort ``u``, trainable scale
``g`` and effective mass ``m``, the unconstrained transition is:

.. code-block:: text

force = clamp(g * u, -effort_limit, effort_limit)
acceleration = (force - stiffness * q - damping * v) / m
v_next = clamp(v + dt * acceleration, -velocity_limit, velocity_limit)
q_next = clamp(q + dt * v_next, lower_limit, upper_limit)

The implementation also includes joint damping in ``damping`` and stops the
slider when a position limit is reached. Gradients at clamp boundaries are
piecewise-defined; the example stays away from those boundaries.

.. dropdown:: Complete provider (solver.py)
:icon: code

.. literalinclude:: ../../../scripts/tutorials/sim/simple_newton_solver/solver.py
:language: python
:linenos:

.. dropdown:: Complete scene and rollout (demo.py)
:icon: code

.. literalinclude:: ../../../scripts/tutorials/sim/simple_newton_solver/demo.py
:language: python
:linenos:

Scope and next steps
--------------------

This educational solver accepts independent dynamic prismatic leaves with
fixed ancestors and zero gravity. It rejects moving-body collisions, particles,
mimic constraints, friction and position/velocity target drives. Its parameters
belong to one finalized model; save learned values explicitly before rebuilding
the scene. See the tutorial directory's ``README.md`` for SDK prerequisites,
limit behavior, and notes about differentiating Cartesian losses.
1 change: 1 addition & 0 deletions docs/source/tutorial/simulation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pages are ordered as a progressive learning path.
../robot
../sensor
../solver
../simple_newton_solver
../motion_gen
../trajectory_planning
../robot_workspace
Expand Down
51 changes: 40 additions & 11 deletions embodichain/lab/sim/cfg/physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,10 @@ class NewtonPhysicsCfg(PhysicsBackendCfg):
requires_grad: bool = False
"""Whether to finalize the Newton model with differentiable state enabled.

EmbodiChain currently requires the Semi-implicit solver for this mode and
disables CUDA graph capture when gradients are enabled.
Requires Semi-implicit or a direct/named provider supporting the requested
gradient mode. The provider validates native support during model creation;
Scene functional calls additionally require its functional dynamics service.
CUDA graph capture is disabled when gradients are enabled.
"""

use_cuda_graph: bool = True
Expand Down Expand Up @@ -387,6 +389,16 @@ class NewtonPhysicsCfg(PhysicsBackendCfg):
coupling requires ``joint_mode='dynamic'``. Current DexSim supports
full-surface rigid-soft feedback; native validation owns the compatible
contact modes and option combinations.

Installed ``dexsim.newton_solvers`` entry-point names are also accepted by
DexSim builds with the named-extension API. Extension names are exact;
options pass to their provider.

Python callers can pass DexSim's ``ProviderNewtonSolverCfg`` with a
``provider_factory`` class or zero-argument factory and provider ``options``.
That configuration passes through directly without package discovery. The
SDK creates a fresh provider for each model build; pass a factory rather
than a live provider or solver instance.
"""

collision_cfg: NewtonCollisionPipelineCfg | Mapping[str, Any] | None = field(
Expand Down Expand Up @@ -456,13 +468,16 @@ def to_dexsim_cfg(
solver_cfg_map=solver_cfg_map,
)

if self.requires_grad and (
solver_cfg is None or solver_cfg.solver_type != "semi_implicit"
solver_name = "dexuni" if solver_cfg is None else str(solver_cfg.solver_type)
if (
self.requires_grad
and solver_name in solver_cfg_map
and solver_name != "semi_implicit"
):
logger.log_error(
"Newton gradient mode requires an explicit "
"solver_type='semi_implicit'; the default does not select a "
"differentiable solver."
"solver_type='semi_implicit' or a provider supporting gradients; "
"the default does not select a differentiable solver."
)

collision_pipeline_cfg = None
Expand Down Expand Up @@ -537,11 +552,16 @@ def _normalize_newton_solver_type(solver_type: str) -> str:
"vbdsolvercfg": "vbd",
}
if key not in aliases:
logger.log_error(
f"Unsupported Newton solver type '{solver_type}'. "
"Expected one of 'dexuni', 'mjwarp', 'xpbd', 'semi_implicit', "
"'featherstone', or 'vbd'."
)
try:
from dexsim.engine.newton_physics import normalize_newton_solver_name
except ImportError as exc:
raise ValueError(
f"Solver {solver_type!r} requires a DexSim build with named solver extensions"
) from exc
try:
return normalize_newton_solver_name(solver_type)
except ValueError as exc:
logger.log_error(f"Unsupported Newton solver type {solver_type!r}. {exc}")
return aliases[key]


Expand All @@ -559,6 +579,11 @@ def _newton_solver_cfg_to_dexsim(
"Newton solver_cfg must be a mapping or a DexSim Newton solver "
"config object with a 'solver_type' attribute."
)
from dexsim.engine import newton_physics

provider_cfg_type = getattr(newton_physics, "ProviderNewtonSolverCfg", None)
if provider_cfg_type is not None and isinstance(solver_cfg, provider_cfg_type):
return solver_cfg
_normalize_newton_solver_type(str(solver_cfg.solver_type))
return solver_cfg

Expand All @@ -569,6 +594,10 @@ def _newton_solver_cfg_to_dexsim(
or "dexuni"
)
normalized_solver_type = _normalize_newton_solver_type(str(configured_solver_type))
if normalized_solver_type not in solver_cfg_map:
from dexsim.engine.newton_physics import RegisteredNewtonSolverCfg

return RegisteredNewtonSolverCfg(normalized_solver_type, solver_cfg_data)
solver_cfg_type = solver_cfg_map[normalized_solver_type]
return solver_cfg_type(**solver_cfg_data)

Expand Down
13 changes: 11 additions & 2 deletions embodichain/lab/sim/objects/articulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
from embodichain.lab.sim.objects.backends.newton import (
_configure_newton_mimic_compliance,
_stabilize_newton_mimic_target_write,
_supports_newton_position_targets,
)
from embodichain.utils.math import (
matrix_from_euler,
Expand Down Expand Up @@ -2828,6 +2829,11 @@ def reset(
num_instances = len(local_env_ids)
self.cfg: ArticulationCfg

write_hold_targets = (
not self.body_data.is_newton_backend
or _supports_newton_position_targets(self._spawn_result)
)

self.restore_visual_material(env_ids=local_env_ids)
self._restore_default_physical_properties(local_env_ids)

Expand Down Expand Up @@ -2876,8 +2882,11 @@ def reset(
# impulse when initialized away from their equality manifold.
qpos = self._project_mimic_qpos(qpos)
self.set_qpos(qpos, target=False, env_ids=local_env_ids)
# Set drive target to hold position.
self.set_qpos(qpos, target=True, env_ids=local_env_ids)
# Initialization uses clear_dynamics=False with no subsequent clear.
# Keep hold targets and mimic propagation for position-capable solvers;
# effort-only solvers use native reset bookkeeping without a command.
if write_hold_targets:
self.set_qpos(qpos, target=True, env_ids=local_env_ids)

if clear_dynamics:
self.clear_dynamics(env_ids=local_env_ids)
Expand Down
17 changes: 17 additions & 0 deletions embodichain/lab/sim/objects/backends/newton.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ def is_newton_scene(scene: object) -> bool:
return isinstance(scene, Scene) and scene.backend == "newton"


def _supports_newton_position_targets(scene: Scene) -> bool:
"""Query the finalized solver contract while preserving legacy SDK support."""
query = getattr(scene, "dynamics_capabilities", None)
if query is None:
from dexsim.engine import newton_physics

if hasattr(newton_physics, "NewtonSolverExtension"):
raise RuntimeError(
"Newton solver extensions require a compatible DexSim SDK with "
"Scene.dynamics_capabilities() for articulation initialization."
)
# Released SDKs predating extensions accept the existing target channels.
return True
fields = query().supported_control_fields
return fields is None or "joint_target_q" in fields


def _create_newton_standalone_state_sync(
model: Any,
body_ids: Sequence[int],
Expand Down
Loading
Loading