Karana.KUtils.Sim#

Sim class and associated classes/functions.

Attributes#

bc

Classes#

PrefabRoot

Prefab to act as the virtual root of the Prefab hierarchy.

Sim

Simulation class.

SimDS

DataStruct representation of a simulation.

Module Contents#

Karana.KUtils.Sim.bc#
class Karana.KUtils.Sim.PrefabRoot(name: str, config: ConfigType, context: ContextType, params: ParamsType, parent_prefab: Prefab[Any, Any, Any] | None = None)[source]#

Bases: Karana.KUtils.Prefab.Prefab[Karana.KUtils.Prefab.Config, Karana.KUtils.Prefab.Context, Karana.KUtils.Prefab.Params]

Prefab to act as the virtual root of the Prefab hierarchy.

class Karana.KUtils.Sim.Sim[source]#
class Karana.KUtils.Sim.Sim(mb_ds: Karana.Dynamics.SOADyn_types.SubGraphDS | None, sp_ds: Karana.Dynamics.SOADyn_types.StatePropagatorDS | None)
class Karana.KUtils.Sim.Sim(mb: Karana.Dynamics.Multibody, sp: Karana.Dynamics.StatePropagator)

Bases: Karana.Core.BaseWithVars

Simulation class.

This class helps one easily setup a simulation complete with a Multibody and StatePropagator.

It contains helper methods to do common tasks like setup graphics or the GUI.

prefab_root#
classmethod fromDS(sim_ds: SimDS) Sim[source]#

Create a Sim instance from its associated DataStruct.

Parameters:

sim_ds (SimDS) – The DataStruct to create the Sim from.

Returns:

A new instance of Sim created from the provided DataStruct.

Return type:

Sim

toDS() SimDS[source]#

Convert this Sim into a SimDS.

Returns:

A DataStruct representation of this simulation.

Return type:

SimDS

classmethod fromBasicPrefabDS(basic_prefab_ds: Karana.KUtils.BasicPrefab.BasicPrefabDS[Karana.KUtils.BasicPrefab.ExtraInfoType]) tuple[Sim, Karana.KUtils.BasicPrefab.BasicPrefab[Karana.KUtils.BasicPrefab.ExtraInfoType]][source]#

Create a Sim instance from its associated DataStruct.

Parameters:

basic_prefab_ds (BasicPrefabDS) – The BasicPrefabDS to create a Simulation from.

Returns:

A new instance of Sim created from the provided BasicPrefabDS, and the associated BasicPrefab.

Return type:

tuple[Sim, BasicPrefab[ExtraInfoType]]

setupGraphics(*, port: int = 29523, axes: float = 1.0, client_type: Literal['auto', 'electron', 'notebook', 'webbrowser', 'selenium'] | None = 'auto', origin_frame: Karana.Frame.Frame | None = None, wait_for_clients: int = 0, wait_for_clients_timeout: float = 0.0, stick_parts: Literal['auto', 'always', 'never'] = 'auto') tuple[Callable[[], None], Karana.Scene.WebScene][source]#

Set up the graphics for this simulation.

Parameters:
  • port (int = 29523) – Port to bind the WebUI server to. Use 0 to request an arbitrary unused port.

  • axes (float = 1.0) – Length of axes visualization on root frame.

  • client_type (Literal["auto", "electron", "notebook", "webbrowser", "selenium"] | None) –

    Policy for launching a client.

    ”auto”: pick the best option for the environment and OS “electron”: always launch the electron client “notebook”: always open an IFrame in IPython “webbrowser”: always open a browser tab “selenium”: always open a chrome driver using selenium None: don’t automatically open a client

    Defaults to “auto”.

  • origin_frame (Optional[Frame] = None) – Frame to use as the world origin for the graphics scene. If None, use the Multibody’s virtualRoot.

  • wait_for_clients (int = 0) – Number of client connections to wait for before continuing.

  • wait_for_clients_timeout (float = 0.0) – Number of seconds to wait before raising an error if wait_for_clients is positive.

  • stick_parts (Literal["auto", "always", "never"] = "auto") –

    Policy for creating stick parts. Defaults to “auto”.

    ”auto”: create stick parts if the ProxyScene is empty “always”: unconditionally create stick parts “never”: unconditionally don’t create stick parts

Returns:

A tuple containing the a cleanup callable and the graphics scene.

Return type:

tuple[Callable, WebScene]

setupGui(port=29534, client_type: Literal['auto', 'electron', 'notebook', 'webbrowser', 'selenium'] | None = 'auto', wait_for_clients: int = 0, wait_for_clients_timeout: float = 0.0, stick_parts: Literal['auto', 'always', 'never'] = 'auto', stick_parts_config: Karana.Dynamics.StickPartsConfig | None = None, name_to_label_map: dict[str, str] | None = None, time_display_period: float | None = 0.01, graphics_origin_frame: Karana.Frame.Frame | None = None) Karana.Dynamics.SOADyn_types.MultibodyWebUI[source]#

Create the GUI for this multibody system.

Parameters:
  • self (Sim) – The Sim instance

  • port (int) – Port to bind the WebUI server to. Use 0 to request an arbitrary unused port. Defaults to 29534.

  • client_type (Literal["auto", "electron", "notebook", "webbrowser", "selenium"] | None) –

    Policy for launching a client.

    ”auto”: pick the best option for the environment and OS “electron”: always launch the electron client “notebook”: always open an IFrame in IPython “webbrowser”: always open a browser tab “selenium”: always open a chrome driver using selenium None: don’t automatically open a client

    Defaults to “auto”.

  • wait_for_clients (int) – Number of client connections to wait for before continuing. Defaults to 0.

  • wait_for_clients_timeout (float) – Number of seconds to wait before raising an error if wait_for_clients is positive. Defaults to 0.

  • graphics_origin_frame (Optional[Frame]) – If given, and the GUI needs to setup graphics, use this as the origin frame instead of the multibody virtual root.

  • stick_parts (Literal["auto", "always", "never"] = "auto") –

    Policy for creating stick parts. Defaults to “auto”.

    ”auto”: create stick parts if the ProxyScene is empty “always”: unconditionally create stick parts “never”: unconditionally don’t create stick parts

  • stick_parts_config (StickPartsConfig | None) – Configuration parameters for the stick parts.

  • name_to_label_map (dict[str, str] | None) – Dictionary defining the labels to use for each body in the visjs graphs display

  • time_display_period (float | None) – If not None and sp is given, add a time display refreshing with this period in simulation time. Defaults to 0.01.

class Karana.KUtils.Sim.SimDS(/, **data: Any)[source]#

Bases: Karana.KUtils.DataStruct.DataStruct

DataStruct representation of a simulation.

Parameters:
  • sp_ds (StatePropagatorDS) – The StatePropagator DataStruct.

  • mb_ds (SubGraphDS) – The Multibody DataStruct.

  • setup_graphics (GuiSetupDS | GraphicsSetupDS | None) – The GUI or graphics setup DataStruct.

  • collision (list[SerializeAsAny[CollisionSceneDS[CollisionSceneType]]] = [] # pyright: ignore) – The CollisionScene DataStructs.

  • prefabs (list[SerializeAsAny[PrefabDS[ConfigType, ContextType, ParamsType]]] # pyright: ignore) – The Prefab DataStructs.

sp_ds: Karana.Dynamics.SOADyn_types.StatePropagatorDS#
mb_ds: Karana.Dynamics.SOADyn_types.SubGraphDS#
setup_graphics: Karana.Dynamics.SOADyn_types.GuiSetupDS | Karana.Dynamics.SOADyn_types.GraphicsSetupDS | None = None#
collision: list[pydantic.SerializeAsAny[Karana.Scene.Scene_types.CollisionSceneDS[Karana.Scene.Scene_types.CollisionSceneType]]] = []#
prefabs: list[pydantic.SerializeAsAny[Karana.KUtils.Prefab.PrefabDS[Karana.KUtils.Prefab.ConfigType, Karana.KUtils.Prefab.ContextType, Karana.KUtils.Prefab.ParamsType]]]#
toSim() Sim[source]#

Create a simulation from this SimDS.

Returns:

The Sim created from this SimDS.

Return type:

Sim