pylinkage.bridge package

Submodules

pylinkage.bridge.solver_conversion module

Conversion between Linkage objects and SolverData arrays.

This module provides the bridge between the user-friendly Linkage/Component API and the numba-optimized numeric arrays used by the solver.

This bridge module exists to keep the solver module pure (only numpy/numba dependencies) while allowing conversion from Python objects when needed.

pylinkage.bridge.solver_conversion.linkage_to_solver_data(linkage: Any) SolverData

Convert a Linkage object to numba-compatible SolverData.

Extracts all joint positions, constraints, and topology into contiguous numpy arrays for efficient numba processing.

Works with:

  • simulation.Linkage (component/actuator/dyad API)

  • mechanism.Mechanism (Links + Joints model — dispatched separately)

  • any container with a .joints or .components attribute that can be classified through pylinkage._compat

Parameters:

linkage – The linkage to convert.

Returns:

SolverData containing all numeric arrays needed for simulation.

pylinkage.bridge.solver_conversion.solver_data_to_linkage(data: SolverData, linkage: Any) None

Update linkage joint positions and velocities from solver data.

Synchronizes the numeric positions and velocities back to the Component objects after simulation.

Parameters:
  • data – SolverData containing updated positions and optionally velocities.

  • linkage – Linkage to update.

pylinkage.bridge.solver_conversion.update_solver_constraints(data: SolverData, linkage: Any) None

Update solver constraints from linkage.

Call after modifying joint constraints via set_constraints() to keep the solver data in sync.

Parameters:
  • data – SolverData to update.

  • linkage – Linkage containing updated constraints.

pylinkage.bridge.solver_conversion.update_solver_positions(data: SolverData, linkage: Any) None

Update solver positions from linkage.

Call after modifying joint positions via set_coord() to keep the solver data in sync.

Parameters:
  • data – SolverData to update.

  • linkage – Linkage containing updated positions.

Module contents

Bridge module for converting between high-level and low-level representations.

This module provides conversion functions that bridge: - Linkage (Python objects) ↔ SolverData (numpy arrays)

The bridge module sits at a higher abstraction level than both the solver (which is pure numerics) and the linkage module (which is the user API). This separation keeps the solver free of Python object dependencies for maximum performance.

Typical usage:
>>> from pylinkage import Linkage
>>> from pylinkage.bridge import linkage_to_solver_data
>>> from pylinkage.solver import simulate
>>>
>>> linkage = create_my_linkage()
>>> data = linkage_to_solver_data(linkage)
>>> trajectory = simulate(
...     data.positions, data.constraints, data.joint_types,
...     data.parent_indices, data.constraint_offsets,
...     data.solve_order, iterations=1000, dt=1.0
... )
pylinkage.bridge.linkage_to_solver_data(linkage: Any) SolverData

Convert a Linkage object to numba-compatible SolverData.

Extracts all joint positions, constraints, and topology into contiguous numpy arrays for efficient numba processing.

Works with:

  • simulation.Linkage (component/actuator/dyad API)

  • mechanism.Mechanism (Links + Joints model — dispatched separately)

  • any container with a .joints or .components attribute that can be classified through pylinkage._compat

Parameters:

linkage – The linkage to convert.

Returns:

SolverData containing all numeric arrays needed for simulation.

pylinkage.bridge.solver_data_to_linkage(data: SolverData, linkage: Any) None

Update linkage joint positions and velocities from solver data.

Synchronizes the numeric positions and velocities back to the Component objects after simulation.

Parameters:
  • data – SolverData containing updated positions and optionally velocities.

  • linkage – Linkage to update.

pylinkage.bridge.update_solver_constraints(data: SolverData, linkage: Any) None

Update solver constraints from linkage.

Call after modifying joint constraints via set_constraints() to keep the solver data in sync.

Parameters:
  • data – SolverData to update.

  • linkage – Linkage containing updated constraints.

pylinkage.bridge.update_solver_positions(data: SolverData, linkage: Any) None

Update solver positions from linkage.

Call after modifying joint positions via set_coord() to keep the solver data in sync.

Parameters:
  • data – SolverData to update.

  • linkage – Linkage containing updated positions.