World Model Modules
This section documents the high-level world model, scene-graph integration, voxel grid management, and training utilities.
world.model
World-level wrapper and optimization front-end around the core factor graph.
This module defines the world model abstraction: a typed layer on top of
core.factor_graph.FactorGraph that understands high-level entities
(poses, places, rooms, voxels, objects, agents) and also centralizes
residual construction, JIT compilation, and solver orchestration.
In other words, :class:WorldModel is the bridge between:
• Low-level optimization (factor graph, residual functions, manifolds)
• High-level scene graph abstractions (poses, agents, rooms, voxels)
• Application code that wants a simple, stable API for "optimize my world"
The underlying :class:FactorGraph remains a relatively small, generic
data structure that stores variables and factors and knows nothing about
JAX, JIT, or manifolds. All JAX-specific logic (residual registries,
vmap-based batching, Gauss–Newton wrappers, etc.) is owned by the world
model.
Key responsibilities
- Manage the underlying :class:
FactorGraphinstance. - Provide ergonomic helpers to:
• Add variables with automatically assigned :class:
NodeIds. • Add typed factors (e.g. priors, odometry, attachments, voxel terms). • Pack / unpack state vectors for optimization. - Maintain simple bookkeeping structures (e.g. maps from user-facing
handles / indices back to :class:
NodeIds) so that experiments and higher-level layers do not need to manipulate :class:NodeIddirectly. - Maintain a residual-function registry that maps factor-type strings
(e.g.
"odom_se3","voxel_point_obs") to JAX-compatible residuals. - Build unified, vmap-optimized residual and objective functions on demand, caching compiled versions keyed by graph structure.
- Expose convenient optimization entry points (e.g. :meth:
optimize, or :class:optimization.jit_wrappers.JittedGN) that operate directly on the world model.
Typical usage
Experiments and higher layers typically:
1. Construct a :class:`WorldModel`.
2. Add variables & factors according to a scenario.
3. Register residual functions for each factor type of interest.
4. Build a residual or objective from the world model and call into
:mod:`dsg_jit.optimization.solvers` or :mod:`dsg_jit.optimization.jit_wrappers`
to run Gauss–Newton (potentially manifold-aware) or gradient-based
optimization.
5. Decode and interpret the optimized state via the world model’s
convenience accessors, or export it to higher-level scene-graph
structures.
Design goals
- Backend separation: keep :class:
FactorGraphas a minimal, backend-agnostic data structure (variables, factors, connectivity), while :class:WorldModelowns JAX-facing logic such as residual construction, vmap batching, and JIT caching. - Scene-friendly: provide enough structure that scene graphs, voxel modules, and DSG layers can build on top of the world model without duplicating graph or optimization logic.
- Ergonomic but explicit: favor simple, explicit methods
(
add_variable,add_factor,register_residual,optimize) over hidden magic, so that experiments remain easy to debug and extend.
ActiveWindowTemplate(variable_slots, factor_slots)
dataclass
Defines a fixed-capacity active factor graph template for JIT-stable operation. Each variable/factor slot is identified by (type, slot_idx).
FactorSlot(factor_type, slot_idx, factor_id, var_slot_keys)
dataclass
Bookkeeping for a factor slot in the active template.
VarSlot(var_type, slot_idx, node_id, dim)
dataclass
Bookkeeping for a variable slot in the active template.
WorldModel()
dataclass
High-level world model built on top of :class:FactorGraph.
Modes
- Dynamic/unbounded FG (legacy, research mode): Variables and factors can be added/removed dynamically.
- Fixed-capacity active template (real-time / JIT-stable mode): A fixed set of variable/factor slots is preallocated for JIT-compatibility and in-place updates.
In addition to wrapping the core factor graph, this class keeps simple bookkeeping dictionaries that make it easier to build static and dynamic scene graphs on top of DSG-JIT. These maps are deliberately lightweight and optional: if you never pass a name when adding variables, the underlying optimization behavior is unchanged.
Source code in dsg-jit/dsg_jit/world/model.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
add_agent_pose(agent_id, t, value, var_type='pose')
Add (and register) a pose for a particular agent at a timestep.
This convenience helper is meant for dynamic scene graphs where you
track multiple agents over time. It simply delegates to
:meth:add_variable and then records the mapping (agent_id, t).
:param agent_id: String identifier for the agent (e.g. "robot_0").
:param t: Discrete timestep index.
:param value: Initial pose value for this agent at time t.
:param var_type: Underlying variable type to use (defaults to
"pose"; you can change this to "pose_se3" in advanced
use-cases).
:returns: The :class:NodeId of the new agent pose variable.
Source code in dsg-jit/dsg_jit/world/model.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
add_camera_bearings(pose_id, landmark_ids, bearings, weight=None, factor_type='pose_landmark_bearing')
Add one or more camera bearing factors for a single pose.
This is a thin convenience wrapper for camera-like measurements that
observe known landmarks via bearing (direction) only. It assumes that
the underlying factor type is implemented by a residual such as
:func:slam.measurements.pose_landmark_bearing_residual.
Each row of :param:bearings is expected to correspond to one
landmark in :param:landmark_ids. The dimensionality (e.g. 2D angle
or 3D unit vector) is left to the residual function.
:param pose_id: Identifier of the pose variable from which all
bearings are taken.
:param landmark_ids: List of landmark node identifiers, one per row
in bearings.
:param bearings: Array of shape (N, D) containing bearing
measurements in the sensor or camera frame.
:param weight: Optional scalar weight or inverse noise level applied
uniformly to all bearings in this call. If None, the default
inside the residual is used.
:param factor_type: Factor type string to register in the underlying
:class:FactorGraph. Defaults to "pose_landmark_bearing".
:returns: The :class:FactorId of the last factor added. One factor
is added per (pose, landmark) pair.
Source code in dsg-jit/dsg_jit/world/model.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
add_factor(f_type, var_ids, params)
Add a new factor to the underlying factor graph.
This allocates a fresh :class:FactorId, normalizes the input
variable identifiers to :class:NodeId instances, constructs a
:class:core.types.Factor, and registers it in :attr:fg.
:param f_type: String identifying the factor type. This must match a
key in :attr:FactorGraph.residual_fns so that the appropriate
residual function can be looked up during optimization.
:param var_ids: Iterable of variable identifiers (ints or
:class:NodeId instances) that this factor connects.
:param params: Dictionary of factor parameters passed through to the
residual function (e.g. measurements, noise models, weights).
:returns: The :class:FactorId of the newly added factor.
Source code in dsg-jit/dsg_jit/world/model.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
add_imu_preintegration_factor(pose_i, pose_j, delta, weight=None, factor_type='pose_imu_preintegration')
Add an IMU preintegration-style factor between two poses.
This is intended to work with a preintegrated IMU summary (e.g. as
produced by :mod:sensors.imu), where delta contains fields such
as "dR", "dv", "dp", and corresponding covariance or
information terms.
The exact keys expected in delta are left to the residual
implementation for factor_type, but by storing the dictionary
unchanged in params["delta"] we keep this interface flexible.
:param pose_i: NodeId of the starting pose (time :math:t_k).
:param pose_j: NodeId of the ending pose (time :math:t_{k+1}).
:param delta: Dictionary describing the preintegrated IMU increment
between pose_i and pose_j. All arrays should be JAX
arrays or types convertible via :func:jax.numpy.asarray.
:param weight: Optional scalar weight / scaling to apply to the IMU
factor inside the residual.
:param factor_type: Factor type string to register; by default this is
"pose_imu_preintegration".
:returns: The :class:FactorId of the created IMU factor.
Source code in dsg-jit/dsg_jit/world/model.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
add_lidar_ranges(pose_id, landmark_ids, ranges, directions=None, weight=None, factor_type='pose_lidar_range')
Add LiDAR-style range factors for a single pose.
This helper is intended for simple range-only or range-with-direction measurements to known landmarks, coming from a LiDAR or depth sensor.
The interpretation of directions depends on the chosen residual
implementation, but a common convention is that each row is a unit
vector in the sensor frame pointing toward the target.
:param pose_id: Identifier of the pose variable from which ranges
are measured.
:param landmark_ids: List of landmark node identifiers, one per range
sample.
:param ranges: Array of shape (N,) holding range values in meters.
:param directions: Optional array of shape (N, 3) with unit
direction vectors associated with each range measurement.
:param weight: Optional scalar weight applied to all range factors.
:param factor_type: Factor type string to register; by default this is
"pose_lidar_range". The residual function for this type is
expected to consume "range" and optionally "direction" in
params.
:returns: The :class:FactorId of the last factor added.
Source code in dsg-jit/dsg_jit/world/model.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
add_object(center, name=None)
Add an object centroid variable (3D point).
:param center: 3D position of the object centroid.
:param name: Optional semantic name to register in :attr:object_ids.
:returns: The :class:NodeId of the new object variable.
Source code in dsg-jit/dsg_jit/world/model.py
365 366 367 368 369 370 371 372 373 374 375 | |
add_place(center, name=None)
Add a place / waypoint variable (3D point).
:param center: 3D position of the place/waypoint.
:param name: Optional semantic name to register in :attr:place_ids.
:returns: The :class:NodeId of the new place variable.
Source code in dsg-jit/dsg_jit/world/model.py
353 354 355 356 357 358 359 360 361 362 363 | |
add_pose(value, name=None)
Add an SE(3) pose variable.
This is a thin wrapper around :meth:add_variable. If name is
provided, the pose is also registered in :attr:pose_ids, which can
be useful for scene-graph style code that wants stable, human-readable
handles.
:param value: Initial pose value, typically a 6D se(3) vector.
:param name: Optional semantic name used as a key in :attr:pose_ids.
:returns: The :class:NodeId of the newly created pose variable.
Source code in dsg-jit/dsg_jit/world/model.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
add_room(center, name=None)
Add a room center variable (3D point).
:param center: 3D position of the room center.
:param name: Optional semantic name to register in :attr:room_ids.
:returns: The :class:NodeId of the new room variable.
Source code in dsg-jit/dsg_jit/world/model.py
341 342 343 344 345 346 347 348 349 350 351 | |
add_variable(var_type, value)
Add a new variable to the underlying factor graph.
This allocates a fresh :class:NodeId, constructs a
:class:core.types.Variable with the given type and initial value,
registers it in :attr:fg, and returns the newly created id.
:param var_type: String describing the variable type (e.g. "pose",
"room", "place", "object"). This is used by
residual functions and manifold metadata to interpret the state.
:param value: Initial value for the variable, represented as a
1D JAX array. The dimensionality is inferred from
value.shape[0].
:returns: The :class:NodeId of the newly added variable.
Source code in dsg-jit/dsg_jit/world/model.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
build_objective()
Construct a scalar objective f(x) = ||r(x)||^2.
This wraps :meth:build_residual and returns a function
that computes the squared L2 norm of the residual vector.
:return: JIT-compiled objective function f(x).
:rtype: Callable[[jnp.ndarray], jnp.ndarray]
Source code in dsg-jit/dsg_jit/world/model.py
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 | |
build_residual(*, use_type_weights=False, learn_odom=False, learn_voxel_points=False)
Construct a unified residual function for the current world.
This method is the WorldModel-level entry point for building a
JAX-compatible residual function that stacks all factor residuals.
It is intended to subsume the various specialized builders that
previously lived on :class:FactorGraph, such as:
build_residual_function_with_type_weightsbuild_residual_function_se3_odom_param_multibuild_residual_function_voxel_point_param[_multi]
Instead of having separate entry points, this method exposes a single interface whose behavior is controlled by configuration flags and a structured "hyper-parameter" argument passed at call time.
Parameters
use_type_weights : bool, optional Currently unused in this implementation. Reserved for future integration with type-weighted residuals. learn_odom : bool, optional Currently unused in this implementation. Reserved for future integration with learnable odometry parameters. learn_voxel_points : bool, optional Currently unused in this implementation. Reserved for future integration with learnable voxel observation points.
Returns
callable
A JAX-compatible residual function. In the simplest case
(all flags False) the signature is r(x) where x is
a packed state vector.
Source code in dsg-jit/dsg_jit/world/model.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
build_residual_function_se3_odom_param_multi()
Build a residual function with learnable SE(3) odometry.
All factors of type "odom_se3" are treated as depending on a
parameter array theta of shape (K, 6), where K is the
number of odometry factors. Each row of theta represents a
perturbable se(3) measurement.
Returns
(residual_fn, index)
residual_fn(x, theta) and the pack index mapping from
:meth:pack_state.
Source code in dsg-jit/dsg_jit/world/model.py
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 | |
build_residual_function_voxel_point_param()
Build a residual function with a shared voxel observation point.
All factors of type "voxel_point_obs" will use a dynamic
point_world argument passed at call time, rather than a fixed
value stored in the factor params.
Returns
(residual_fn, index)
residual_fn(x, point_world) where point_world has
shape (3,).
Source code in dsg-jit/dsg_jit/world/model.py
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 | |
build_residual_function_voxel_point_param_multi()
Build a residual function with per-factor voxel observation points.
Each "voxel_point_obs" factor consumes a row of the parameter
array theta of shape (K, 3), where K is the number of
such factors.
Returns
(residual_fn, index)
residual_fn(x, theta) where theta has shape (K, 3).
Source code in dsg-jit/dsg_jit/world/model.py
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
build_residual_function_with_type_weights(factor_type_order)
Build a residual function that supports learnable type weights.
The returned function has signature r(x, log_scales) where
log_scales[i] is the log-weight associated with
factor_type_order[i]. Missing types default to unit weight.
This is a WorldModel-based version of the old FactorGraph helper,
implemented in terms of pack_state, unpack_state, and the
WorldModel residual registry.
Source code in dsg-jit/dsg_jit/world/model.py
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 | |
configure_factor_slot(factor_type, slot_idx, var_ids, params, active=True)
Configure a factor slot in the active template: set variable ids, params, and activity.
Source code in dsg-jit/dsg_jit/world/model.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
fixed_lag_marginalize(keep_ids, damping=1e-06)
Disabled: Fixed-lag marginalization is not supported in active template mode. Use bounded active templates for sliding window/fixed-lag smoothing instead.
Source code in dsg-jit/dsg_jit/world/model.py
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |
get_residual(factor_type)
Return the residual function registered for a given factor type.
Parameters
factor_type : str String identifier for the factor type.
Returns
callable or None
The residual function previously registered via
:meth:register_residual, or None if no function is
registered for the requested type.
Source code in dsg-jit/dsg_jit/world/model.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
get_residuals()
Returns the residual registry, all currently registered residuals.
:return: Dict[str, ResidualFn]
Source code in dsg-jit/dsg_jit/world/model.py
729 730 731 732 733 734 | |
get_variable_value(nid)
Return the current value of a variable.
This is a thin convenience wrapper over the underlying
:class:FactorGraph variable storage and is useful when building
dynamic scene graphs that want to query individual nodes.
:param nid: Identifier of the variable. :returns: A JAX array holding the variable's current value.
Source code in dsg-jit/dsg_jit/world/model.py
663 664 665 666 667 668 669 670 671 672 673 | |
init_active_template(template)
Initialize a fixed-capacity active factor graph template for JIT-stable operation. All variables and factors are preallocated; structure is fixed.
Source code in dsg-jit/dsg_jit/world/model.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
list_residual_types()
List all factor types with registered residual functions.
This is a convenience helper for debugging, diagnostics, and tests to verify that the WorldModel has been configured with the expected residuals for the current application.
Returns
list of str Sorted list of factor type strings for which residuals have been registered.
Source code in dsg-jit/dsg_jit/world/model.py
736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
marginalize_variables(marginalized_ids, damping=1e-06)
Disabled: Marginalization is not supported in active template mode. Use bounded active templates for fixed-lag smoothing instead.
Source code in dsg-jit/dsg_jit/world/model.py
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 | |
optimize(lr=0.1, iters=300, method='gd', damping=0.001, max_step_norm=1.0)
Run a local optimizer on the current world state.
This method packs the current variables into a flat state vector,
constructs an appropriate objective or residual function, runs one
of the supported optimizers, and writes the optimized state back
into :attr:fg.variables.
Supported methods:
"gd": vanilla gradient descent on the scalar objective :math:\|r(x)\|^2."newton": damped Newton on the same scalar objective."gn": Gauss--Newton on the stacked residual vector assuming Euclidean variables."manifold_gn": manifold-aware Gauss--Newton that uses :func:slam.manifold.build_manifold_metadatato handle SE(3) and Euclidean blocks differently."gn_jit": JIT-compiled Gauss--Newton using :class:optimization.jit_wrappers.JittedGN.
:param lr: Learning rate for gradient-descent-based methods
(currently used when method == "gd").
:param iters: Maximum number of iterations for the chosen optimizer.
:param method: Name of the optimization method to use. See the list
above for supported values.
:param damping: Damping / regularization parameter used by the
Newton and Gauss--Newton variants.
:param max_step_norm: Maximum allowed step norm for Gauss--Newton
methods; steps larger than this are clamped to improve stability.
:returns: None. The world model is updated in place.
Source code in dsg-jit/dsg_jit/world/model.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
pack_state()
Pack all variable values into a single flat JAX array.
The variables are ordered by sorted :class:NodeId to ensure stable
indexing across calls.
:return: Tuple of (x, index) where x is the concatenated
state vector and index is the mapping produced by
:meth:_build_state_index.
:rtype: Tuple[jnp.ndarray, Dict[NodeId, Tuple[int, int]]]
Source code in dsg-jit/dsg_jit/world/model.py
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 | |
register_residual(factor_type, fn)
Register a residual function for a given factor type.
This is the WorldModel-level registry that associates factor type
strings (e.g. "odom_se3", "voxel_point_obs") with
JAX-compatible residual functions. The registered functions are
consumed by higher-level residual builders such as
:meth:build_residual.
Parameters
factor_type : str
String identifier for the factor type. This must match the
type field stored in :class:Factor instances in the
underlying :class:FactorGraph.
fn : Callable
Residual function implementing the measurement model. The
exact signature is intentionally flexible, but it is expected
to be compatible with the unified residual builder returned by
:meth:build_residual (e.g. it may be vmapped across factors
of a given type).
Source code in dsg-jit/dsg_jit/world/model.py
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |
set_variable_slot(var_type, slot_idx, value)
Set the value of a variable slot in the active template.
Source code in dsg-jit/dsg_jit/world/model.py
253 254 255 256 257 258 259 260 261 262 | |
snapshot_state()
Capture a shallow snapshot of the current world state.
The snapshot maps integer node ids to their current values. This is intentionally simple and serialization-friendly, and is meant to be consumed by higher-level dynamic scene graph structures that want to record the evolution of the world over time.
:returns: A dictionary mapping int(NodeId) to JAX arrays.
Source code in dsg-jit/dsg_jit/world/model.py
675 676 677 678 679 680 681 682 683 684 685 | |
unpack_state(x, index)
Unpack a flat state vector back into per-variable arrays.
:param x: Flattened state vector produced by :meth:pack_state or
produced by an optimizer.
:type x: jnp.ndarray
:param index: Mapping from :class:NodeId to (start, dim) blocks
as returned by :meth:_build_state_index.
:type index: Dict[NodeId, Tuple[int, int]]
:return: Mapping from node id to its corresponding slice of x.
:rtype: Dict[NodeId, jnp.ndarray]
Source code in dsg-jit/dsg_jit/world/model.py
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 | |
unpack_state_inplace(x_opt)
Write the optimized state vector back into the FactorGraph variable table.
Source code in dsg-jit/dsg_jit/world/model.py
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 | |
marginal_prior_residual(stacked, params)
Residual for a dense Gaussian prior induced by marginalization.
This residual encodes a quadratic term of the form
1/2 (x - μ)^T H (x - μ)
via a Cholesky factorization H = L^T L. The parameters are:
mean : μ, a 1D array of the same shape as ``stacked``.
sqrt_info : L, a square matrix such that L^T L ≈ H.
The returned residual is L @ (x - μ), so that the overall contribution to the objective is 1/2 ||L (x - μ)||^2.
Source code in dsg-jit/dsg_jit/world/model.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
world.scene_graph
Dynamic 3D scene graph utilities built on top of the world model.
This module provides a SceneGraphWorld abstraction that organizes
poses, places, rooms, objects, and agents into a dynamic scene graph
backed by the differentiable factor graph.
Conceptually, this layer is responsible for:
• Creating typed nodes:
- Robot / agent poses (SE3)
- Places / topological nodes (1D)
- Rooms / regions
- Objects (points / positions in space)
• Adding semantic and metric relationships between them via factors:
- Pose priors
- SE3 odometry / loop closures
- Pose–place attachments
- Pose–object / object–place relations
• Maintaining lightweight indexing:
- Maps from (agent, time) → pose NodeId
- Collections of place / room / object node ids
- Optional trajectory dictionaries
What it does not do: • It does not implement the optimizer itself. • It does not hard-code SE3 math or Jacobians. • It does not perform rendering or perception.
All numerical optimization is delegated to:
- `world.model.WorldModel` (and its `FactorGraph`)
- `optimization.solvers` (Gauss–Newton / manifold variants)
- `slam.manifold` and `slam.measurements` for geometry and residuals
Typical usage
Experiments in experiments/exp0X_*.py follow a common pattern:
1. Construct a `SceneGraphWorld`.
2. Add a small chain of poses, places, and objects.
3. Attach priors and odometry factors.
4. Optionally attach voxel or observation factors.
5. Optimize via Gauss–Newton (JIT or non-JIT).
6. Inspect the resulting scene graph state.
Design goals
- Ergonomics: hide raw
NodeIdand factor wiring behind friendly helpers like “add pose”, “add agent pose”, “attach place”, etc. - Differentiable backbone: everything created here remains compatible with JAX JIT and automatic differentiation downstream.
- Extensibility: easy to add new relation types and node types without changing the optimizer or lower-level infrastructure.
SceneGraphNoiseConfig(prior_pose_sigma=0.001, odom_se3_sigma=0.05, smooth_pose_sigma=0.5, pose_place_sigma=0.05, object_at_pose_sigma=0.05, pose_landmark_sigma=0.05, pose_landmark_bearing_sigma=0.05, pose_voxel_point_sigma=0.05, voxel_smoothness_sigma=0.1, voxel_point_obs_sigma=0.05)
dataclass
Default noise (standard deviation) per factor type.
These are in the same units as the residuals
- prior / odom / smoothness: R^6 pose (m, m, m, rad, rad, rad)
- pose_place / object_at_pose: R^1 or R^3 (m)
SceneGraphWorld()
World-level dynamic scene graph wrapper that manages typed nodes and semantic relationships, built atop the WorldModel. Provides ergonomic helpers for creating and connecting SE(3) poses, places, rooms, objects, and agents, and maintains convenient indexing for scene-graph experiments.
In addition to delegating numerical optimization to the underlying WorldModel, SceneGraphWorld maintains its own lightweight memory of node states. This persistent cache decouples the scene graph from the FactorGraph so that sliding-window marginalization or variable removal at the optimization level does not cause information loss at the scene-graph level.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
add_agent_pose_landmark_bearing(agent, t, landmark_id, bearing, sigma=None)
Add a bearing-only pose–landmark constraint for an agent at time t.
This wraps :meth:add_pose_landmark_bearing and resolves the pose id
from :attr:pose_trajectory.
:param agent: Agent identifier.
:param t: Timestep index for the pose.
:param landmark_id: Node id of the 3D landmark variable.
:param bearing: Iterable of length 3 giving the bearing vector in the
pose frame (it will be normalized internally).
:param sigma: Optional noise standard deviation. If None, falls back
to :attr:SceneGraphNoiseConfig.pose_landmark_bearing_sigma.
:return: Integer factor id of the created bearing constraint.
:raises KeyError: If no pose has been registered for (agent, t).
Source code in dsg-jit/dsg_jit/world/scene_graph.py
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |
add_agent_pose_landmark_relative(agent, t, landmark_id, measurement, sigma=None)
Add a relative pose–landmark constraint for an agent at time t.
This is a small ergonomic wrapper around
:meth:add_pose_landmark_relative that resolves the pose id using
:attr:pose_trajectory.
:param agent: Agent identifier.
:param t: Timestep index for the pose.
:param landmark_id: Node id of the 3D landmark variable.
:param measurement: Iterable of length 3 giving the expected landmark
position in the pose frame.
:param sigma: Optional noise standard deviation. If None, falls back
to :attr:SceneGraphNoiseConfig.pose_landmark_sigma.
:return: Integer factor id of the created relative landmark constraint.
:raises KeyError: If no pose has been registered for (agent, t).
Source code in dsg-jit/dsg_jit/world/scene_graph.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 | |
add_agent_pose_place_attachment(agent, t, place_id, coord_index=0, sigma=None)
Attach an agent pose at time t to a place node.
This is a higher-level wrapper around :meth:add_place_attachment
which resolves the pose id via :attr:pose_trajectory.
:param agent: Agent identifier.
:param t: Integer timestep index.
:param place_id: Node id of the place variable (1D or 3D).
:param coord_index: Index of the pose coordinate to tie to the place
(typically 0 for x, 1 for y, etc.). Defaults to 0.
:param sigma: Optional noise standard deviation. If None, falls back
to :attr:SceneGraphNoiseConfig.pose_place_sigma.
:return: Integer factor id of the created attachment constraint.
:raises KeyError: If no pose has been registered for (agent, t).
Source code in dsg-jit/dsg_jit/world/scene_graph.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
add_agent_pose_se3(agent, t, value)
Add an SE(3) pose for a given agent at a specific timestep.
:param agent: Agent identifier (for example, a robot name). :param t: Integer timestep index. :param value: Length-6 array-like se(3) vector for the pose. :return: Integer node id of the created pose variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
add_agent_pose_voxel_point(agent, t, voxel_id, point_meas, sigma=None)
Constrain a voxel cell using a point measurement from an agent pose.
This wraps :meth:add_pose_voxel_point and resolves the pose id from
:attr:pose_trajectory.
:param agent: Agent identifier.
:param t: Timestep index for the pose.
:param voxel_id: Node id of the voxel cell variable.
:param point_meas: Iterable of length 3 giving a point in the pose
frame (for example, a back-projected LiDAR or depth sample).
:param sigma: Optional noise standard deviation. If None, falls
back to :attr:SceneGraphNoiseConfig.pose_voxel_point_sigma.
:return: Integer factor id of the created voxel-point constraint.
:raises KeyError: If no pose has been registered for (agent, t).
Source code in dsg-jit/dsg_jit/world/scene_graph.py
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |
add_agent_range_measurement(agent, t, target_nid, measured_range, sigma=None, weight=None)
Add a range-only factor using an agent's pose at a given timestep.
This is a convenience wrapper around :meth:add_range_measurement
that looks up the pose node id from :attr:pose_trajectory using
(agent, t) and then creates a "range" factor to a target node.
:param agent: Agent identifier (for example, a robot name).
:param t: Integer timestep index for the agent pose.
:param target_nid: NodeId of the target variable (for example, place3d,
voxel_cell or object3d).
:param measured_range: Observed distance (same units as the world coordinates).
:param sigma: Optional standard deviation of the measurement noise. If
provided (and weight is None), it is converted to a weight via
:func:slam.measurements.sigma_to_weight.
:param weight: Optional explicit weight. If both sigma and weight
are given, weight takes precedence.
:return: Integer factor id of the created range factor.
:raises KeyError: If no pose has been registered for (agent, t).
Source code in dsg-jit/dsg_jit/world/scene_graph.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
add_agent_temporal_smoothness(agent, t, sigma=None)
Enforce temporal smoothness between successive poses of a given agent.
This enforces a smoothness constraint between the poses at timesteps
t and t+1 for the specified agent, using
:meth:add_temporal_smoothness internally.
:param agent: Agent identifier.
:param t: Timestep index for the first pose in the pair.
:param sigma: Optional standard deviation controlling smoothness. If
None, falls back to :attr:SceneGraphNoiseConfig.smooth_pose_sigma.
:return: Integer factor id of the created smoothness constraint.
:raises KeyError: If either pose (agent, t) or (agent, t+1) has
not been registered.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |
add_landmark3d(xyz)
Add a 3D landmark node (R^3).
:param xyz: Iterable of length 3 giving world coordinates. :return: Integer node id of the created landmark variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 | |
add_named_object3d(name, xyz)
Add a 3D object and register it under a semantic name.
:param name: Identifier for the object (for example, "chair_1").
:param xyz: Iterable of length 3 giving the world-frame position.
:return: Integer node id of the created object variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
463 464 465 466 467 468 469 470 471 472 473 | |
add_object3d(xyz)
Add an object with 3D position (R^3).
:param xyz: Iterable of length 3 giving the object position in world coordinates. :return: Integer node id of the created object variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
add_object_room_edge(object_id, room_id)
Register a semantic edge between an object node and a room node.
This helper is intentionally lightweight: it does not add a numeric factor to the underlying factor graph. Instead it records topological connectivity for visualization and higher-level reasoning, similar to classic dynamic scene-graph frameworks.
:param object_id: Integer node id of the object variable. :param room_id: Integer node id of the room variable. :return: None.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 | |
add_odom_se3_additive(pose_i, pose_j, dx, sigma=None)
Add an additive SE(3) odometry factor in R^6.
The measurement is a translation along the x-axis plus zero rotation.
:param pose_i: Node id of the source pose.
:param pose_j: Node id of the destination pose.
:param dx: Translation along the x-axis in meters.
:param sigma: Optional standard deviation for the odometry noise. If
None, :attr:SceneGraphNoiseConfig.odom_se3_sigma is used.
:return: Integer factor id of the created odometry constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
add_odom_se3_geodesic(pose_i, pose_j, dx, yaw=0.0, sigma=None)
Add a geodesic SE(3) odometry factor.
The measurement is parameterized as translation + yaw in se(3).
:param pose_i: Node id of the source pose.
:param pose_j: Node id of the destination pose.
:param dx: Translation along the x-axis in meters.
:param yaw: Heading change around the z-axis in radians.
:param sigma: Optional standard deviation for the odometry noise. If
None, :attr:SceneGraphNoiseConfig.odom_se3_sigma is used.
:return: Integer factor id of the created odometry constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
add_place1d(x)
Add a 1D place variable.
:param x: Scalar position along a 1D axis (e.g. corridor coordinate). :return: Integer node id of the created place variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
add_place3d(name, xyz)
Add a 3D place node (R^3) with a human-readable name.
This is a semantic helper for dynamic scene-graph style usage.
:param name: Identifier for the place (for example, "place_A").
:param xyz: Iterable of length 3 giving the world-frame position.
:return: Integer node id of the created place variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
add_place_attachment(pose_id, place_id, coord_index=0, sigma=None)
Attach a SE(3) pose to a place node (1D or 3D).
This is a higher-level, dimension-aware wrapper around the
pose_place_attachment residual, and is intended for scene-graph
style experiments where places may be either 1D (topological) or
3D (metric positions).
:param pose_id: Node id of the SE(3) pose variable.
:param place_id: Node id of the place variable. The underlying state
dimension is inferred at runtime from the factor graph (for
example, 1 for place1d or 3 for place3d).
:param coord_index: Index of the pose coordinate to tie to the place
(typically 0 for x, 1 for y, etc.). Defaults to 0.
:param sigma: Optional noise standard deviation. If None, falls
back to :attr:SceneGraphNoiseConfig.pose_place_sigma.
:return: Integer factor id of the created attachment constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 | |
add_pose_landmark_bearing(pose_id, landmark_id, bearing, sigma=None)
Add a bearing-only constraint from pose to landmark.
:param pose_id: Node id of the SE(3) pose variable.
:param landmark_id: Node id of the 3D landmark variable.
:param bearing: Iterable of length 3 giving the bearing vector in the
pose frame (will be normalized internally).
:param sigma: Optional noise standard deviation. If None,
:attr:SceneGraphNoiseConfig.pose_landmark_bearing_sigma is used.
:return: Integer factor id of the created bearing constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 | |
add_pose_landmark_relative(pose_id, landmark_id, measurement, sigma=None)
Add a relative measurement between a pose and a 3D landmark.
The measurement is expressed in the pose frame.
:param pose_id: Node id of the SE(3) pose variable.
:param landmark_id: Node id of the 3D landmark variable.
:param measurement: Iterable of length 3 giving the expected landmark
position in the pose frame.
:param sigma: Optional noise standard deviation. If None,
:attr:SceneGraphNoiseConfig.pose_landmark_sigma is used.
:return: Integer factor id of the created relative landmark constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 | |
add_pose_se3(value)
Add a generic SE(3) pose variable.
:param value: Length-6 array-like se(3) vector [tx, ty, tz, rx, ry, rz]. :return: Integer node id of the created pose variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
352 353 354 355 356 357 358 359 360 361 362 363 364 | |
add_pose_voxel_point(pose_id, voxel_id, point_meas, sigma=None)
Constrain a voxel cell to align with a point measurement seen from a pose.
:param pose_id: Node id of the SE(3) pose variable.
:param voxel_id: Node id of the voxel cell variable.
:param point_meas: Iterable of length 3 giving a point in the pose
frame (for example, a back-projected depth sample).
:param sigma: Optional noise standard deviation. If None,
:attr:SceneGraphNoiseConfig.pose_voxel_point_sigma is used.
:return: Integer factor id of the created voxel-point constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 | |
add_range_measurement(pose_nid, target_nid, measured_range, sigma=None, weight=None)
Add a range-only sensor factor between a pose and a 3D target.
This creates a factor of type "range" whose residual is:
r = ||target - pose|| - measured_range
The underlying residual is implemented in slam.measurements.range_residual.
:param pose_nid: NodeId of the pose (pose_se3) variable.
:param target_nid: NodeId of the target variable (e.g. place3d, voxel_cell, object3d).
:param measured_range: Observed distance (same units as world coordinates).
:param sigma: Optional standard deviation of the measurement noise. If provided,
it will be converted to a weight as 1 / sigma^2.
:param weight: Optional explicit weight. If both sigma and weight are given,
weight takes precedence.
:return: Integer factor id of the created range factor.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | |
add_room(name, center)
Add a 3D room node (R^3 center) with a semantic name.
This is a thin wrapper around a Euclidean variable, but exposes a room-level abstraction for dynamic scene-graph experiments.
:param name: Identifier for the room (for example, "room_A").
:param center: Iterable of length 3 giving the approximate room
centroid in world coordinates.
:return: Integer node id of the created room variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
add_room1d(x)
Add a 1D 'room' variable (just a scalar, wrapped as a length-1 vector).
The room is stored in :attr:room_nodes using an auto-generated
string key of the form "room1d_{k}" where k is the current
number of rooms.
:param x: 1D coordinate, shape (1,) or a scalar float.
:return: Integer node id of the created room variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
add_room_place_edge(room_id, place_id)
Register a semantic edge between a room node and a place node.
This helper is intentionally lightweight: it does not add a numeric factor to the underlying factor graph. Instead it records topological connectivity for visualization and higher-level reasoning, similar to classic dynamic scene-graph frameworks.
:param room_id: Integer node id of the room variable. :param place_id: Integer node id of the place variable. :return: None.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | |
add_temporal_smoothness(pose_id_t, pose_id_t1, sigma=None)
Enforce smoothness between successive poses.
:param pose_id_t: Node id of the pose at time t.
:param pose_id_t1: Node id of the pose at time t+1.
:param sigma: Optional standard deviation of the pose difference; a
larger value gives weaker smoothness. If None,
:attr:SceneGraphNoiseConfig.smooth_pose_sigma is used.
:return: Integer factor id of the created smoothness constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | |
add_voxel_cell(xyz)
Add a voxel cell center in world coordinates (R^3).
:param xyz: Iterable of length 3 giving the voxel center position. :return: Integer node id of the created voxel variable.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 | |
add_voxel_point_observation(voxel_id, point_world, sigma=None)
Add an observation tying a voxel center to a 3D point in world coordinates.
:param voxel_id: Node id of the voxel cell variable.
:param point_world: Iterable of length 3 giving a world-frame point
(for example, from fused depth or a point cloud).
:param sigma: Optional noise standard deviation. If None,
:attr:SceneGraphNoiseConfig.voxel_point_obs_sigma is used.
:return: Integer factor id of the created observation constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 | |
add_voxel_smoothness(voxel_i_id, voxel_j_id, offset, sigma=None)
Enforce grid-like spacing between two voxel centers.
:param voxel_i_id: Node id of the first voxel cell.
:param voxel_j_id: Node id of the second voxel cell.
:param offset: Iterable of length 3 giving the expected vector from
voxel i to voxel j (for example, [dx, 0, 0]).
:param sigma: Optional noise standard deviation. If None,
:attr:SceneGraphNoiseConfig.voxel_smoothness_sigma is used.
:return: Integer factor id of the created smoothness constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 | |
attach_object_to_pose(pose_id, obj_id, offset=(0.0, 0.0, 0.0), sigma=None)
Attach an object to a pose with an optional 3D offset.
:param pose_id: Node id of the SE(3) pose variable.
:param obj_id: Node id of the 3D object variable.
:param offset: Iterable of length 3 giving the offset from the pose
frame to the object in pose coordinates.
:param sigma: Optional noise standard deviation. If None, falls
back to :attr:SceneGraphNoiseConfig.object_at_pose_sigma.
:return: Integer factor id of the created object-at-pose constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
attach_pose_to_place_x(pose_id, place_id)
Attach a pose to a 1D place along the x-coordinate.
This is a low-level helper that assumes a 6D pose and 1D place.
:param pose_id: Node id of the SE(3) pose variable. :param place_id: Node id of the 1D place variable. :return: Integer factor id of the created attachment constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 | |
attach_pose_to_room_x(pose_id, room_id)
Attach a pose to a 1D room along the x-coordinate.
This is analogous to :meth:attach_pose_to_place_x but uses a room
node instead of a place node.
:param pose_id: Node id of the SE(3) pose variable. :param room_id: Node id of the 1D room variable. :return: Integer factor id of the created attachment constraint.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 | |
dump_state()
Return a snapshot of all variable values in the world.
:return: Dictionary mapping integer node ids to JAX arrays of values.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1593 1594 1595 1596 1597 1598 1599 | |
enable_active_template(template)
Enable fixed-capacity active-template mode.
In this mode, SceneGraphWorld retains full persistent memory, but only a bounded active subset is mapped into the WorldModel slots. This enables a single stable JIT compilation and constant-latency solves.
:param template: ActiveWindowTemplate instance (from world.model).
Source code in dsg-jit/dsg_jit/world/scene_graph.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
get_object3d(obj_id)
Return the current 3D position of an object.
:param obj_id: Integer node id of the object variable.
:return: JAX array of shape (3,) giving the object position.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |
get_place(place_id)
Return the current scalar value of a 1D place.
:param place_id: Integer node id of the place variable. :return: Floating-point scalar position.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 | |
get_pose(pose_id)
Return the current SE(3) pose value.
:param pose_id: Integer node id of the pose variable.
:return: JAX array of shape (6,) containing the se(3) vector.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 | |
optimize(method='gn', iters=40)
Run nonlinear optimization over the current factor graph. This optimizes the current WorldModel factor graph (which may be bounded active-template or unbounded, depending on configuration).
:param method: Optimization method name (currently "gn" for
Gauss–Newton).
:param iters: Maximum number of iterations to run.
:return: None. The internal world model state is updated in-place.
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
optimize_active_batch(iters=5, damping=0.001)
Optimize only the currently active bounded FG (active-template mode).
:param iters: An integer representing the maximum number of iterations for an optimization :param damping: The minimum precision for a solve
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 | |
optimize_global_offline(iters=40, damping=0.001)
Full batch optimization over the entire persistent SceneGraph memory.
:param iters: An integer representing the maximum number of iterations for an optimization :param damping: The minimum precision for a solve
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 | |
visualize_web(host='127.0.0.1', port=8000, open_browser=True)
Launch a local Three.js-based 3D viewer for this SceneGraph.
:param host: A string representing the Host IP, is configured for LocalHost by default :param port: An integer representing a target host port to expose the webviewer
Source code in dsg-jit/dsg_jit/world/scene_graph.py
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
SceneNodeState(node_id, var_type, value)
dataclass
Lightweight cache of a scene-graph node's latest value.
This decouples the persistent scene graph from the underlying optimization FactorGraph: even if a variable is marginalized or removed from the FactorGraph (for example, in a sliding-window setup), the SceneGraph can still serve its last optimized value.
world.voxel_grid
Voxel grid utilities for differentiable volumetric scene representations.
This module defines helpers for constructing voxel-level variables and their associated factors on top of the DSG-JIT world model.
Key responsibilities
- Create voxel chains or grids: • 1D voxel chains (for smooth curves or “lines” in space). • Higher-dimensional voxel layouts (as needed by experiments).
-
Register and attach voxel-related factors: • Smoothness factors between neighboring voxels (using
voxel_smoothness_residual). • Point-observation factors tying voxels to measurements in world coordinates (usingvoxel_point_observation_residual). • Optional voxel priors for regularization or supervision. -
Provide convenience routines for: • Initializing voxel positions (e.g. along an axis). • Accessing the optimized voxel centers from the packed state.
Role in the DSG-JIT stack
Voxel grids are a key piece of the volumetric side of the engine. They allow us to:
• Represent surfaces or occupancy with a differentiable structure.
• Run Gauss–Newton over large chains / grids of voxels.
• Jointly optimize voxels with SE3 poses and other scene graph nodes
(hybrid SE3 + voxel experiments and benchmarks).
Integration points
- Uses
world.model.WorldModelto create voxel variables and factors. - Relies on residuals defined in
slam.measurementsfor:- smoothness,
- point observations,
- and priors.
- Works seamlessly with
optimization.solvers.gauss_newton_manifoldand related JIT-compiled solvers.
Design goals
- Scalable: Able to create hundreds or thousands of voxel nodes and factors that still admit fast, JIT-compiled optimization.
- Composable: Plays nicely with SE3 poses, places, and other world entities in a single factor graph.
- Experiment-oriented: Keeps the voxel construction boilerplate out of experiment scripts, making it easier to design new voxel-based learning tasks.
VoxelGridSpec(origin, dims, resolution)
dataclass
Specification for constructing a regular voxel grid.
This lightweight container defines the spatial layout of a voxel grid, including its world-space origin, discrete grid dimensions, and the physical resolution of each voxel cell.
:param origin: A 3-element array giving the world-space center of voxel
coordinate (0, 0, 0). This is the reference point from which all voxel
centers are computed.
:param dims: A tuple (nx, ny, nz) representing the number of voxels
along the x-, y-, and z-axes respectively.
:param resolution: The edge length of each voxel cell in world units.
The spacing between voxel centers is equal to this resolution.
build_voxel_grid(sg, spec)
Construct a regular voxel grid inside the SceneGraphWorld.
This allocates one voxel_cell variable per grid coordinate (ix, iy, iz)
using the voxel resolution and origin defined in spec. Each voxel is
positioned at:
center = origin + [ix * res, iy * res, iz * res]
The resulting mapping enables downstream creation of voxel smoothness constraints and scene-graph integration.
:param sg: The active SceneGraphWorld instance where voxel nodes will be
created. Must expose add_voxel_cell(center) which returns a node ID.
:param spec: Voxel grid specification containing:
- spec.origin: 3D world origin of the grid.
- spec.dims: Tuple (nx, ny, nz) specifying grid dimensions.
- spec.resolution: Edge length of each voxel cell.
:return: A dictionary mapping each grid index (ix, iy, iz) to the
corresponding voxel node ID allocated within the scene graph.
Source code in dsg-jit/dsg_jit/world/voxel_grid.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
connect_grid_neighbors_1d_x(sg, index_to_id, spec, sigma=None)
Connect 3D voxel grid nodes along the +x direction using smoothness factors.
This function iterates over all voxel indices (ix, iy, iz) such that
ix + 1 < nx, and adds a voxel smoothness constraint between each voxel
and its +x neighbor. The enforced residual encourages:
voxel(ix+1, iy, iz) - voxel(ix, iy, iz) ≈ [resolution, 0, 0]
This is sufficient to enforce a 1D chain structure along the x-axis and is used when constructing structured voxel grids for optimization.
:param sg: The active SceneGraphWorld instance to which smoothness
factors will be added. Must expose add_voxel_smoothness(i, j, offset, sigma).
:param index_to_id: Mapping from grid index (ix, iy, iz) to the corresponding
node ID in the scene graph or factor graph.
:param spec: Voxel grid specification containing dimensions and voxel resolution.
Expected to provide:
- spec.dims: Tuple (nx, ny, nz) with number of voxels.
- spec.resolution: Voxel edge length in world units.
:param sigma: Optional noise standard deviation for the smoothness factor.
If None, the default sigma inside sg.add_voxel_smoothness is used.
:return: None. This function mutates the scene graph world in-place by
adding smoothness edges between neighboring x-axis voxels.
Source code in dsg-jit/dsg_jit/world/voxel_grid.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
world.training
High-level training utilities for differentiable scene graph experiments.
This module provides a small training harness that sits on top of:
• `world.model.WorldModel` / `world.scene_graph.SceneGraphWorld`
• JAX-based optimizers and Gauss–Newton solvers
• Residual functions from `slam.measurements`
Its main role is to support meta-learning and hyperparameter learning over the differentiable DSG-JIT engine. Examples include:
• Learning factor-type weights (e.g. odometry vs. observation).
• Learning measurement parameters (odom SE3 chains, voxel obs).
• Running outer-loop gradient descent over:
- log-scale weights,
- observation locations,
- or other “theta” parameters that influence the inner solve.
Typical structure
A typical training loop implemented here follows this pattern:
1. Build a world / scene graph for a given scenario.
2. Build a residual function that depends both on:
- the state x (poses, voxels, etc.), and
- learnable parameters θ (e.g. measurements, log-scales).
3. Run an inner optimization (Gauss–Newton or gradient descent)
to obtain x*(θ).
4. Compute a supervised loss L(x*(θ), target).
5. Differentiate L w.r.t. θ using JAX (`jax.grad` or `jax.value_and_grad`).
6. Update θ with an outer optimizer step.
The DSGTrainer (or equivalent helper) encapsulates this pattern,
exposing step / train_step–style methods that return both the new
parameters and useful diagnostics (loss, gradient norms, etc.).
Design goals
- Keep experiments small: Training logic lives here so individual experiments can focus on constructing the world and defining the supervision signal.
- JAX-first design: Training functions are written to be JIT-able and differentiable, allowing seamless scaling from toy experiments to larger graphs.
- Research-friendly: The code is intentionally lightweight and easy to modify for new research ideas around learnable costs, priors, and structure.
DSGTrainer(wm, factor_type_order, inner_cfg)
dataclass
High-level trainer for differentiable DSG experiments.
This class encapsulates a simple bi-level optimization pattern where: an inner loop solves for the scene graph state x, and an outer loop optimizes meta-parameters such as factor-type weights.
:param wm: World model containing the factor graph and scene graph. :param factor_type_order: Ordered list of factor type names; each entry corresponds to a log-scale entry in the weight vector. :param inner_cfg: Configuration for the inner gradient–descent solver applied to the state.
__post_init__()
Post-initialization hook.
This method caches the underlying factor graph from the world model and builds a residual function that accepts per-factor-type log-scales.
Source code in dsg-jit/dsg_jit/world/training.py
94 95 96 97 98 99 100 101 102 103 104 | |
solve_state(log_scales)
Run the inner optimization to solve for the state vector.
Given a vector of log-scales for factor types, this method performs explicit gradient descent on the objective
0.5 * || r(x, log_scales) ||^2,
where r is the weighted residual function built from the factor graph.
:param log_scales: Array of shape (T,) containing per-factor-type log-scale weights.
:return: Optimized flat state vector x after the inner GD loop.
Source code in dsg-jit/dsg_jit/world/training.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
unpack_state(x)
Unpack a flat state vector into a NodeId-keyed dictionary.
This is a thin wrapper around the factor graph's unpack_state
that uses the index structure implied by the current world model.
:param x: Flat state vector to be unpacked.
:return: Mapping from NodeId to the corresponding slice of x as a JAX array.
Source code in dsg-jit/dsg_jit/world/training.py
153 154 155 156 157 158 159 160 161 162 163 164 | |
InnerGDConfig(learning_rate=0.01, max_iters=40, max_step_norm=1.0)
dataclass
Configuration for the inner gradient–descent solver.
:param learning_rate: Step size used for each inner GD update on the state. :param max_iters: Maximum number of inner GD iterations. :param max_step_norm: Maximum allowed L2 norm of a single GD step; used to clamp overly large updates for numerical stability.
world.visualization
Visualization utilities for DSG-JIT.
This module provides lightweight 2D and 3D rendering tools for visualizing factor graphs, scene graphs, and mixed-level semantic structures. It is designed to support both debugging and demonstration of DSG-JIT’s hierarchical representations, including robot poses, voxel cells, places, rooms, and arbitrary semantic objects.
The visualization pipeline follows three main steps:
-
Exporting graph data
export_factor_graph_for_vis()converts an internalFactorGraphinto color-codedVisNodeandVisEdgelists. Variable types such aspose_se3,voxel_cell,place1d, androom1dare mapped to coarse visualization categories, and heuristic 3D positions are extracted for rendering. -
2D top-down rendering
plot_factor_graph_2d()produces a Matplotlib top-down view (x–y plane) with automatically computed bounds, node type coloring, and optional label rendering. This is especially useful for SE(3) SLAM chains, grid-based voxel fields, and planar semantic graphs. -
Full 3D scene graph rendering
plot_factor_graph_3d()draws a complete 3D view of poses, voxels, places, rooms, and objects. Edges between nodes represent geometric or semantic relationships. Aspect ratios are normalized so spatial structure remains visually meaningful regardless of scale.
These visualizers are intentionally decoupled from the high-level world model
(SceneGraphWorld) so they can be used directly on raw factor graphs produced
by optimization procedures or experiment scripts.
Example usage is provided in:
- experiments/exp17_visual_factor_graph.py (basic 2D + 3D factor graph)
- experiments/exp18_scenegraph_3d.py (HYDRA-style multi-level scene graph)
- experiments/exp18_scenegraph_demo.py (HYDRA-style 2D + 3D scene graph)
- experiments/exp19_dynamic_scene_graph_demo.py (dynamic agent trajectories)
Module contents
VisNode: Lightweight typed node container for visualization.VisEdge: Lightweight edge container (factor connections)._infer_node_type(): Maps variable types → canonical visualization types._extract_position(): Extracts a 3D coordinate from variable states.export_factor_graph_for_vis(): Converts a FactorGraph → vis nodes & edges.plot_factor_graph_2d(): Renders a 2D top-down view of the graph.plot_factor_graph_3d(): Renders a full 3D scene graph with semantic layers.plot_scenegraph_3d(): Renders a scene graph with semantic layers and (optionally) agent trajectories.plot_dynamic_trajectories_3d(): Renders 3D agent trajectories with time-encoded color.
This module is designed to be extendable—for example:
- Additional node types can be added via _infer_node_type.
- SceneGraphWorld can later provide richer semantic annotations.
- Future versions may support interactive or WebGL visualizations.
VisEdge(var_ids, factor_type)
dataclass
Lightweight edge representation for visualization.
VisNode(id, type, position, label)
dataclass
Lightweight node representation for visualization.
export_factor_graph_for_vis(fg)
Export a FactorGraph into a visualization-friendly node/edge list.
This does not require any SceneGraphWorld; it just uses variables/factors.
:param fg: The factor graph to visualize. :return: (nodes, edges) where nodes is a list of VisNode and edges is a list of VisEdge.
Source code in dsg-jit/dsg_jit/world/visualization.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
plot_dynamic_trajectories_3d(dsg, x_opt, index, title='Dynamic 3D Scene Graph', color_by_time=True)
Render 3D agent trajectories with time encoded as color.
This helper is intended for DynamicSceneGraph-style structures where
agents move through time. It treats time as an implicit fourth
dimension and visualizes it via either a color gradient or a solid
color per agent.
:param dsg: Dynamic scene graph object exposing an iterable
agents attribute and a
get_agent_trajectory(agent, x_opt, index) method that returns
an array of shape (T, 6) or (T, 3). Only the translational
components (x, y, z) are visualized.
:param x_opt: Optimized flat state vector used to decode agent poses.
:param index: Mapping from node identifier to slice or (start, dim)
describing how to extract each node’s state from x_opt. This is
passed through to dsg.get_agent_trajectory.
:param title: Optional figure title for the 3D plot.
:param color_by_time: If True, encode time as a colormap gradient
along each trajectory; if False, use a single solid color per
agent.
:return: None. The function creates and displays a Matplotlib 3D figure.
Source code in dsg-jit/dsg_jit/world/visualization.py
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
plot_factor_graph_2d(fg, show_labels=True)
Simple top-down 2D visualization of the factor graph.
- nodes colored by type
- edges drawn between connected variable nodes (projected to x–y)
- dynamic aspect ratio and bounds based on node extents
:param fg: The factor graph to visualize. :param show_labels: Whether to draw node labels.
Source code in dsg-jit/dsg_jit/world/visualization.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
plot_factor_graph_3d(fg, show_labels=True)
3D visualization of the factor graph.
- Nodes plotted as (x, y, z)
- Edges drawn as 3D line segments
- Colors by node type
:param fg: The factor graph to visualize. :param show_labels: Whether to draw node labels in 3D.
Source code in dsg-jit/dsg_jit/world/visualization.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
plot_scenegraph_3d(sg, x_opt=None, index=None, title='Scene Graph 3D', dsg=None)
Render a 3D scene graph with rooms, places, objects, place attachments, and optional agent trajectories.
This function supports two modes:
- If sg exposes a _memory attribute (the SceneGraph memory layer introduced in SceneGraphWorld),
node positions are read from this memory and x_opt and index are ignored.
- If no memory is present, the function falls back to the previous behavior using x_opt and index
to decode node states.
:param sg: Scene-graph world instance. It is expected to expose
attributes such as rooms, places, objects,
place_parents, object_parents, and place_attachments,
following the conventions used by :class:SceneGraphWorld.
:param x_opt: (Optional) Optimized flat state vector (e.g. from
:meth:WorldModel.pack_state), containing the current estimates
of all node states. Not required if sg exposes a _memory layer.
:param index: (Optional) Mapping from node identifier to either a slice or
(start, dim) tuple describing where that node’s state lives
inside x_opt. Not required if sg exposes a _memory layer.
:param title: Optional figure title for the Matplotlib 3D axes.
:param dsg: Optional dynamic scene graph used to overlay agent
trajectories. It should expose an iterable agents attribute
and a get_agent_trajectory(agent, x_opt, index) method that
returns an array of shape (T, 6) or (T, 3).
:return: None. The function creates and displays a Matplotlib 3D figure.
Source code in dsg-jit/dsg_jit/world/visualization.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |
world.dynamic_scene_graph
Dynamic scene-graph utilities built on top of :mod:world.scene_graph.
This module provides a lightweight wrapper around :class:world.scene_graph.SceneGraphWorld
that makes dynamic (time-indexed) scene graphs easier to build and reason about.
The goal is to keep all of the optimization and factor-graph logic in the existing engine, while giving users a small, ergonomic API for working with trajectories and other time-varying entities.
Design goals
- Don't duplicate state: the underlying :class:
SceneGraphWorldand :class:WorldModelremain the single source of truth. - Time-aware helpers: convenience functions for adding agent trajectories, querying poses across time, and wiring odometry factors between consecutive poses.
- Engine-friendly: everything ultimately calls into existing
SceneGraphWorldmethods, so this module is safe to ignore if you want to use the lower-level API directly.
Typical usage
.. code-block:: python
from world.scene_graph import SceneGraphWorld
from world.dynamic_scene_graph import DynamicSceneGraph
import jax.numpy as jnp
sg = SceneGraphWorld()
dsg = DynamicSceneGraph(sg)
agent = "robot0"
# Add a short trajectory
dsg.add_agent_pose(agent, t=0, pose_se3=jnp.zeros(6))
dsg.add_agent_pose(agent, t=1, pose_se3=jnp.array([1.0, 0, 0, 0, 0, 0]))
# Connect poses with odometry in the x-direction
dsg.add_odom_tx(agent, t0=0, t1=1, dx=1.0, weight=10.0)
# Later, after optimization, you can recover the optimized trajectory with
# dsg.get_agent_trajectory(...).
DynamicSceneGraph(world, agents=set())
dataclass
Helper for building dynamic (time-indexed) scene graphs.
This class is a thin façade over :class:world.scene_graph.SceneGraphWorld.
It does not introduce new optimization logic or state; instead it
organizes common patterns for working with agent trajectories and other
dynamic structures.
Parameters
world:
The underlying :class:SceneGraphWorld instance. All variables and
factors are ultimately added to world.wm.
agents:
Optional set of agent identifiers. You usually don't need to pass
this explicitly; agents are registered lazily when you call
:meth:add_agent or :meth:add_agent_pose.
add_agent(agent_id)
Register an agent identifier.
This does not create any variables by itself; it simply tracks the identifier so you can discover which agents exist in the graph.
:param agent_id: Hashable identifier for the agent (for example, "robot0").
:type agent_id: Hashable
:return: The same agent_id that was passed in, for convenience.
:rtype: Hashable
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
add_agent_pose(agent_id, t, pose_se3)
Add an SE(3) pose variable for a given agent and time.
This delegates directly to :meth:SceneGraphWorld.add_agent_pose_se3
and records the agent identifier in :attr:agents.
:param agent_id: Identifier for the agent.
:type agent_id: Hashable
:param t: Discrete time index (for example, frame or step index).
:type t: int
:param pose_se3: 6D se(3) vector [tx, ty, tz, rx, ry, rz].
:type pose_se3: jax.numpy.ndarray
:return: The node identifier of the newly created pose variable.
:rtype: NodeId
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
add_agent_trajectory(agent_id, poses_se3, start_t=0, add_odom=True, default_dx=None, weight=1.0)
Add a contiguous trajectory for one agent and optionally wire odometry.
This is a convenience helper that repeatedly calls :meth:add_agent_pose
and, if add_odom is True, :meth:add_odom_tx between consecutive
time steps.
:param agent_id: Identifier for the agent.
:type agent_id: Hashable
:param poses_se3: Iterable of se(3) pose vectors. The first element is
placed at t = start_t, the next at t = start_t + 1, and so on.
:type poses_se3: Iterable[jax.numpy.ndarray]
:param start_t: Time index to use for the first pose.
:type start_t: int
:param add_odom: If True, automatically connect consecutive poses with
a 1D odometry factor along x via :meth:add_odom_tx.
:type add_odom: bool
:param default_dx: If not None, use this value as the expected
displacement in x between each consecutive pair of poses. If
None and add_odom is True, the displacement is inferred as
poses_se3[k+1][0] - poses_se3[k][0].
:type default_dx: float | None
:param weight: Scalar weight used for each odometry factor when
add_odom is enabled.
:type weight: float
:return: Node identifiers of all created pose variables, in temporal order.
:rtype: list[NodeId]
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
add_odom_tx(agent_id, t0, t1, dx, weight=1.0)
Connect two consecutive poses with a 1D odometry factor in x.
This is a convenience wrapper around
:meth:SceneGraphWorld.add_odom_se3_additive, which interprets dx as a
translation along the x axis and assumes identity rotation.
:param agent_id: Agent identifier.
:type agent_id: Hashable
:param t0: Time index of the from pose.
:type t0: int
:param t1: Time index of the to pose.
:type t1: int
:param dx: Expected displacement in x from pose (agent_id, t0) to
pose (agent_id, t1).
:type dx: float
:param weight: Scalar weight applied to the odometry residual.
:type weight: float
:return: None.
:rtype: None
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
add_range_obs(agent, t, target_nid, measured_range, sigma=0.1)
Add a range measurement from an agent's pose at time t to a target node.
This wraps :meth:SceneGraphWorld.add_range_measurement, using the
pose node from pose_trajectory[(agent, t)].
:param agent: Agent key, e.g. "robot0".
:param t: Integer time step.
:param target_nid: NodeId of the target (place3d, voxel_cell, object3d, etc.).
:param measured_range: Observed distance.
:param sigma: Optional measurement noise standard deviation.
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
all_pose_time_keys()
Return all (agent, t) keys present in the underlying world.
This is mainly useful for debugging or for building custom visualizations and exporters.
:return: All time-index keys found in
:attr:SceneGraphWorld.pose_trajectory.
:rtype: list[TimeKey]
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
343 344 345 346 347 348 349 350 351 352 353 354 | |
get_agent_pose_nodes(agent_id)
Return the sequence of pose node IDs for an agent, ordered by time.
:param agent_id: Agent identifier. :type agent_id: Hashable :return: Pose node IDs for the given agent, sorted by their time index. :rtype: list[NodeId]
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
271 272 273 274 275 276 277 278 279 280 281 | |
get_agent_times(agent_id)
Return the sorted list of time indices for which this agent has poses.
:param agent_id: Agent identifier.
:type agent_id: Hashable
:return: Sorted time indices where (agent_id, t) exists in
:attr:SceneGraphWorld.pose_trajectory.
:rtype: list[int]
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
258 259 260 261 262 263 264 265 266 267 268 269 | |
get_agent_trajectory(agent_id, x_opt, index)
Extract an optimized trajectory for one agent from a flat state vector.
:param agent_id: Agent identifier.
:type agent_id: Hashable
:param x_opt: Optimized flat state vector produced by one of the
Gauss–Newton solvers, such as
:func:optimization.solvers.gauss_newton_manifold.
:type x_opt: jax.numpy.ndarray
:param index: Mapping from :class:NodeId to (start, dim) tuples as
returned by :meth:world.model.WorldModel.pack_state.
:type index: Mapping[NodeId, Tuple[int, int]]
:return: Array of shape (T, 6) containing the se(3) vectors for each
time step in chronological order.
:rtype: jax.numpy.ndarray
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
get_all_trajectories(x_opt, index)
Extract trajectories for all known agents from an optimized state.
This is a convenience wrapper around :meth:get_agent_trajectory that
iterates over :attr:agents and returns a mapping from agent identifier
to a (T_i, 6) array of se(3) poses.
:param x_opt: Optimized flat state vector produced by one of the
Gauss–Newton solvers.
:type x_opt: jax.numpy.ndarray
:param index: Mapping from :class:NodeId to (start, dim) tuples as
returned by :meth:world.model.WorldModel.pack_state.
:type index: Mapping[NodeId, Tuple[int, int]]
:return: Dictionary mapping each agent identifier to its optimized
trajectory as an array of shape (T_i, 6).
:rtype: dict[Hashable, jax.numpy.ndarray]
Source code in dsg-jit/dsg_jit/world/dynamic_scene_graph.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |