Skip to content

About

Swift Binding for MuJoCo: https://mujoco.org/

Topics

Resources

Stars

22 stars

Watchers

1 watching

Forks

Repository files navigation

1mcuci App Download Online 1mcuci Mp3 Install And Unlock Page Official Provided

1mcuci malaysia s top online casino and sports betting, mycuci apps on google play, muat turun aplikasi 1m cuci untuk android atau ios akses meja live slot dan sportsbook dengan touch n go grabpay boost dan fpx 1mcuci App Download Slots Malaysia Aplikasi Mycuci Provides Dan Apk di mana undang.

1mcuci android app download, 1mcuci app mobile casino gaming at your fingertips, 1mcuci app download official android ios installation, app download, android app download the 1mcuci apk 1mcuci App Download Online Apps Android Download The Official Millions Website for android and install it effortlessly the lightweight file size won t eat into your phone s storage.

Mycuci Apps Trusted Online Live Music Downloader Anytime Betting

1mcuci brings the full casino experience to your phone play slots live casino and sports betting anytime anywhere, yes the 1mcuci mobile app for android and ios is safe to download we strongly Mycuci Apps Mp3 Your Mycuci Provides Fast Eligible recommend downloading the official app only from the 1mcuci website or via the links provided on our download page.

Music downloader mp3 download apps on google play, 1mcuci malaysia s top online betting casino and slots, 1m cuci aplikasi mobile live casino untuk malaysia, download the official 1mcuci app for android and ios experience fast payouts secure login and a premium casino experience on your mobile device in 1mcuci Android Music And Yes The Enjoy Follow Page malaysia.

1mcuci Malaysia Slots Top And Install And Muat 1mcuci

Music downloader download millions of songs with the best free mp3 downloader and music player enjoy crystal clear audio 1mcuci App Untuk Untuk And Android App Download Mycuci Endless with the premium player and explore endless tracks with a super fast free downloader, mycuci provides professional laundry and maid services.

1m Cuci Live Top Download The Official Professional Provided Our Get the official 1mcuci app for your mobile device follow our secure guide for 1mcuci apk download on android and ios to enjoy a seamless casino experience, 1mcuci app download official trusted online casino app malaysia, install and unlock the app by following the instructions on the official download page complete eligible activities and visit the quest or rewards section to check available mobile rewards and their requirements.

download the official Mycuci Apps 1mcuci Mycuci 1mcuci Brings The Super Complete Safe 1mcuci android app enjoy fast seamless access to sports casino games right from your phone download now.

macos-spmmacos-bazelubuntu-spmubuntu-bazeldocumentation

This is a Swift binding for MuJoCo physics simulation library.

MuJoCo is a very accurate CPU-based physics simulation library. Since its acquisition by DeepMind, MuJoCo has been more readily available broadly.

MuJoCo is at the heart of physics simulation in the realm of deep reinforcement learning. In OpenAI Gym, there are many diverse environments simulated with MuJoCo.

Up until now, I only dipped a bit into DRL with https://github.com/liuliu/s4nnc/tree/main/examples. OpenAI Gym is OK for these simple mechanisms and I don't mind to wait a few minutes more. But most recently, I grown interests in more serious use of DRL / PPO under Sim2Real banner. For these, it is popular to either use Isaac Gym or exploiting multi-core for environment runs. For later, doing it with multiprocess package of Python is awkward but the preferred way.

If we can run MuJoCo from Swift, we can avoid the trip into Python entirely and simply use DispatchQueue.concurrentPerform for environment runs.

Installation

MuJoCo for Swift can be installed through either Swift Package Manager or Bazel.

Install with Swift Package Manager

You can add MuJoCo for Swift in your project from here:

.package(name:"MuJoCo",url:"https://github.com/liuliu/swift-mujoco.git",from:"2.3.0")

Install with Bazel

You can simply add MuJoCo for Swift as a dependency in WORKSPACE:

git_repository( name="swift-mujoco", commit="3dfc5a10f3d09f96432efc7804b0aedfa866d0e3", remote="https://github.com/liuliu/swift-mujoco.git", shallow_since="1667838646 -0500" ) load("@swift-mujoco//:deps.bzl", "swift_mujoco_deps") swift_mujoco_deps()

MuJoCo for Swift should work on macOS, Linux and iOS. The GLContext is only available on macOS and Linux.

Automatic Interface Generation

Struct

A mixed strategy was used for MuJoCo interface generation. MuJoCo's API heavily leans towards exposed public C structs. MuJoCo for Swift has to expose these C structs. Wrappers for these C structs are manually created with following principles:

  • If possible, simply typealias to its C struct;
  • If not, refer a public struct with C struct interior, keeping the memory layout exactly the same (can better expose certain properties, more on that later);
  • If there are associated heap data, typically, with mj_deleteXXX methods. These are public struct with a final class Storage interior to track lifetime.

Which out of the three implemented was tracked in Sources/codegen/functionExtension.swift. We later generated Sources/MjObject+Extensions.swift to encode above strategies into Swift protocol. All MjStruct conforms to this protocol which provides associated type of the underlying C struct, as well as the memory access method withCTypeUnsafeMutablePointer(to:).

MuJoCo's C headers are parsed and used to generate properties on structs and functions on structs. These are XX+Extensions.swift and XX+Functions.swift files. All accessors are generated for public C structs from MuJoCo.

They can be reproduced with:

bazel run Sources:codegen -- ~/workspace/swift-mujoco/Sources/ ~/workspace/mujoco/include/mujoco/*.h

Extra care was taken to make sure comments are properly parsed and added to these extensions. https://liuliu.github.io/swift-mujoco is the documentation generated based on these comments.

MjArray<T> is the array type that exposes static or dynamic arrays within a C struct. It retains the underlying storage to make sure the access is safe. It also conforms to set of protocols such that for inout parameters and other array parameters, you can either pass vanilla array or MjArray<T> (or MjTuple, through .tuple()) and expect it just works.

Enum

enum are parsed and generated in Mjt.swift file. Because there is no type annotation, we do our best to infer which int type are enums from comment. MjtEnableBit, MjtDisableBit, MjtCatBit and MjtPertBit are special handled to be OptionSet.

Functions

C functions are not scoped to a particular object. We have to infer these. First, we try to infer which group of APIs it belongs to with the prefix: mj_ matches mjXX structs, mjv_ matches mjvXX structs. We prefer the first parameter, otherwise the last parameter (as it is often used as write to). If no suitable object to be found, it is a free function.

The interface generation process also treats const annotation seriously. Without const, these methods are annotated with mutating. If the parameter is a pointer without const, it is annotated with inout.

Not all functions are automatically generated, some of these are manually implemented because:

  • The C API can be better refactored to Swift API. For example, mj_loadXML can be better translated with throws for errors;
  • Some parameters can be nil, but during automatic interface generation, we assumed all parameters to be non-nil.

MjUI

Whenever possible, we lean towards automatic interface generation. That's why we kept certain APIs in a way that look weird. MjUI has many quirks that at odds with this philosophy. In particular, MjuiDef automatically associated the UI control with the underlying storage pdata. Because pdata is a pointer, it has no regards to the underlying storage lifetime. A set of property wrappers: MjuiDefState, MjuiDefStateMap are introduced to solve this issue. Although users are still responsible to make sure the underlying storage lifetime longer than MjUI itself, you don't need to deal with raw pdata. A MjuiDefObjectMapper is introduced to facilitate direct mapping between an MjStruct and a MjuiDef. You need to pay extra attention because there is no guarantee on underlying MjStruct lifetime with MjuiDefObjectMapper. A recommended way is to group them both under a final class to make sure their lifetime is in sync.

Constants

Only constants related to MjUI are ported over so far.

Callbacks

Callbacks can be found under Mjcb. These are manually ported callbacks but does support Swift closures (i.e. captures).

Reflection

CustomReflectable protocol conformance is implemented for MjStruct. These should contain all the fields in C structs with very few exceptions (buffer and stack in MjData, buffer in MjModel and userdata in MjUI).

String

MuJoCo leans heavily on static allocated strings. To make interaction easier, these are exposed as ordinary Swift strings. The back-and-forth copying can be expensive. Because static allocated strings have hard limit, there is a silent truncation if such limit reached.

GLContext

A GLContext object is introduced to delegate GLFW interactions. Functionalities from uitools.cc in ./sample/ of MuJoCo were added to make interactions with MjUI easier. This object is a bit overreaching as it provides access to clipboard, timing and drag & drop functions.

Examples

Both Examples/simulate and Examples/ant should provide good starting points to learn about the APIs. To run:

bazel run Examples:ant bazel run --compilation_mode=opt Examples:simulate -- ~/workspace/swift-mujoco/Examples/assets/ant.xml

Visit documentation at: https://liuliu.github.io/swift-mujoco. These should be kept up-to-date with main branch.

Appendix

List of Supported MuJoCo C APIs

mj_defaultVFSmj_addFileVFSmj_makeEmptyFileVFSmj_findFileVFSmj_deleteFileVFSmj_deleteVFSmj_loadXMLmj_defaultLROptmj_defaultSolRefImpmj_defaultOptionmj_defaultVisualmj_loadModelmj_deleteModelmj_makeDatamj_deleteDatamjv_defaultCameramjv_defaultPerturbmjv_defaultOptionmjv_defaultFiguremjv_defaultScenemjv_updateScenemjv_freeScenemjr_defaultContextmjr_freeContextmjui_themeSpacingmjui_themeColormjui_addmjui_addToSectionmjui_eventmjr_readPixelsmjr_drawPixelsmj_setLengthRangemjr_findRectmj_copyModelmj_saveModelmj_sizeModelmj_copyDatamj_stackAllocmj_saveLastXMLmj_freeLastXMLmj_printSchemamj_stepmj_step1mj_step2mj_forwardmj_inversemj_forwardSkipmj_inverseSkipmj_resetDatamj_resetDataDebugmj_resetDataKeyframemj_setConstmj_printFormattedModelmj_printModelmj_printFormattedDatamj_printDatamju_printMatmju_printMatSparsemj_fwdPositionmj_fwdVelocitymj_fwdActuationmj_fwdAccelerationmj_fwdConstraintmj_Eulermj_RungeKuttamj_invPositionmj_invVelocitymj_invConstraintmj_compareFwdInvmj_sensorPosmj_sensorVelmj_sensorAccmj_energyPosmj_energyVelmj_checkPosmj_checkVelmj_checkAccmj_kinematicsmj_comPosmj_camlightmj_tendonmj_transmissionmj_crbmj_factorMmj_solveMmj_solveM2mj_comVelmj_passivemj_subtreeVelmj_rnemj_rnePostConstraintmj_collisionmj_makeConstraintmj_projectConstraintmj_referenceConstraintmj_constraintUpdatemj_addContactmj_isPyramidalmj_isSparsemj_isDualmj_mulJacVecmj_mulJacTVecmj_jacmj_jacBodymj_jacBodyCommj_jacGeommj_jacSitemj_jacPointAxismj_name2idmj_id2namemj_fullMmj_mulMmj_mulM2mj_addMmj_applyFTmj_objectVelocitymj_objectAccelerationmj_contactForcemj_differentiatePosmj_integratePosmj_normalizeQuatmj_local2Globalmj_getTotalmassmj_setTotalmassmj_versionmj_versionStringmj_raymj_rayHfieldmj_rayMeshmjd_transitionFDmju_rayGeommju_raySkinmjv_room2modelmjv_model2roommjv_cameraInModelmjv_cameraInRoommjv_frustumHeightmjv_alignToCameramjv_moveCameramjv_movePerturbmjv_moveModelmjv_initPerturbmjv_applyPerturbPosemjv_applyPerturbForcemjv_averageCameramjv_selectmjv_initGeommjv_makeConnectormjv_makeScenemjv_addGeomsmjv_makeLightsmjv_updateCameramjv_updateSkinmjr_makeContextmjr_changeFontmjr_addAuxmjr_uploadTexturemjr_uploadMeshmjr_uploadHFieldmjr_restoreBuffermjr_setBuffermjr_blitBuffermjr_setAuxmjr_blitAuxmjr_textmjr_overlaymjr_maxViewportmjr_rectanglemjr_labelmjr_figuremjr_rendermjui_resizemjui_updatemjui_rendermju_errormju_error_imju_error_smju_warningmju_warning_imju_warning_smju_clearHandlersmj_warningmju_writeLogmju_type2Strmju_warningText

About

Swift Binding for MuJoCo: https://mujoco.org/

Topics

Resources

Stars

22 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages