jaxsim 0.4.3.dev131__py3-none-any.whl → 0.4.3.dev136__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
jaxsim/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.4.3.dev131'
16
- __version_tuple__ = version_tuple = (0, 4, 3, 'dev131')
15
+ __version__ = version = '0.4.3.dev136'
16
+ __version_tuple__ = version_tuple = (0, 4, 3, 'dev136')
@@ -1,12 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import dataclasses
4
+ from collections.abc import Callable
4
5
  from typing import Any
5
6
 
6
7
  import jax
7
8
  import jax.numpy as jnp
8
9
  import jax_dataclasses
9
- import jaxopt
10
+ import optax
10
11
 
11
12
  import jaxsim.api as js
12
13
  import jaxsim.typing as jtp
@@ -297,24 +298,71 @@ class RelaxedRigidContacts(ContactModel):
297
298
  A = G + R
298
299
  b = CW_al_free_WC - a_ref
299
300
 
300
- objective = lambda x: jnp.sum(jnp.square(A @ x + b))
301
+ objective = lambda x, A, b: jnp.sum(jnp.square(A @ x + b))
301
302
 
302
- # Compute the 3D linear force in C[W] frame
303
- opt = jaxopt.LBFGS(
304
- fun=objective,
305
- maxiter=self.parameters.max_iterations,
306
- tol=self.parameters.tolerance,
307
- maxls=30,
308
- history_size=10,
309
- max_stepsize=100.0,
310
- )
303
+ def run_optimization(
304
+ init_params: jtp.Array,
305
+ fun: Callable,
306
+ opt: optax.GradientTransformation,
307
+ maxiter: jtp.Int,
308
+ tol: jtp.Float,
309
+ **kwargs,
310
+ ):
311
+ value_and_grad_fn = optax.value_and_grad_from_state(fun)
312
+
313
+ def step(carry):
314
+ params, state = carry
315
+ value, grad = value_and_grad_fn(
316
+ params,
317
+ state=state,
318
+ A=A,
319
+ b=b,
320
+ )
321
+ updates, state = opt.update(
322
+ updates=grad,
323
+ state=state,
324
+ params=params,
325
+ value=value,
326
+ grad=grad,
327
+ value_fn=fun,
328
+ A=A,
329
+ b=b,
330
+ )
331
+ params = optax.apply_updates(params, updates)
332
+ return params, state
333
+
334
+ def continuing_criterion(carry):
335
+ _, state = carry
336
+ iter_num = optax.tree_utils.tree_get(state, "count")
337
+ grad = optax.tree_utils.tree_get(state, "grad")
338
+ err = optax.tree_utils.tree_l2_norm(grad)
339
+ return (iter_num == 0) | ((iter_num < maxiter) & (err >= tol))
340
+
341
+ init_carry = (init_params, opt.init(init_params))
342
+ final_params, final_state = jax.lax.while_loop(
343
+ continuing_criterion, step, init_carry
344
+ )
345
+ return final_params, final_state
311
346
 
312
347
  init_params = (
313
348
  K[:, jnp.newaxis] * jnp.zeros_like(position).at[:, 2].set(δ)
314
349
  + D[:, jnp.newaxis] * velocity
315
350
  ).flatten()
316
351
 
317
- CW_f_Ci = opt.run(init_params=init_params).params.reshape(-1, 3)
352
+ # Compute the 3D linear force in C[W] frame
353
+ CW_f_Ci, _ = run_optimization(
354
+ init_params=init_params,
355
+ A=A,
356
+ b=b,
357
+ maxiter=self.parameters.max_iterations,
358
+ opt=optax.lbfgs(
359
+ memory_size=10,
360
+ ),
361
+ fun=objective,
362
+ tol=self.parameters.tolerance,
363
+ )
364
+
365
+ CW_f_Ci = CW_f_Ci.reshape((-1, 3))
318
366
 
319
367
  def mixed_to_inertial(W_H_C: jax.Array, CW_fl: jax.Array) -> jax.Array:
320
368
  W_Xf_CW = Adjoint.from_transform(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jaxsim
3
- Version: 0.4.3.dev131
3
+ Version: 0.4.3.dev136
4
4
  Summary: A differentiable physics engine and multibody dynamics library for control and robot learning.
5
5
  Author-email: Diego Ferigo <dgferigo@gmail.com>
6
6
  Maintainer-email: Diego Ferigo <dgferigo@gmail.com>, Filippo Luca Ferretti <filippo.ferretti@iit.it>
@@ -61,11 +61,11 @@ Description-Content-Type: text/markdown
61
61
  License-File: LICENSE
62
62
  Requires-Dist: coloredlogs
63
63
  Requires-Dist: jax>=0.4.26
64
- Requires-Dist: jaxopt>=0.8.0
65
64
  Requires-Dist: jaxlib>=0.4.26
66
65
  Requires-Dist: jaxlie>=1.3.0
67
66
  Requires-Dist: jax-dataclasses>=1.4.0
68
67
  Requires-Dist: pptree
68
+ Requires-Dist: optax>=0.2.3
69
69
  Requires-Dist: qpax
70
70
  Requires-Dist: rod>=0.3.3
71
71
  Requires-Dist: typing-extensions; python_version < "3.12"
@@ -1,5 +1,5 @@
1
1
  jaxsim/__init__.py,sha256=bSbpggIz5aG6QuGZLa0V2EfHjAOeucMxi-vIYxzLmN8,2788
2
- jaxsim/_version.py,sha256=UbsFN1bJc2-jJGijrW0gxKVeG0o0ZDEPctiJcpjtvkw,428
2
+ jaxsim/_version.py,sha256=4S1FUxezMZMOUM_n7Kp3QwzUiVJuNKaG0hA-cdXS2Jo,428
3
3
  jaxsim/exceptions.py,sha256=8_h8iqL8DgNR754dR8SZiQ7361GR5V1sUk3ZuZCHw1Q,2069
4
4
  jaxsim/logging.py,sha256=STI-D_upXZYX-ZezLrlJJ0UlD5YspST0vZ_DcIwkzO4,1553
5
5
  jaxsim/typing.py,sha256=2HXy9hgazPXjofi1vLQ09ZubPtgVmg80U9NKmZ6NYiI,761
@@ -54,7 +54,7 @@ jaxsim/rbda/rnea.py,sha256=CLfqs9XFVaD-hvkLABshDAfdw5bm_AMV3UVAQ_IvURQ,7542
54
54
  jaxsim/rbda/utils.py,sha256=eeT21Y4DiiyhrdF0lUE_VvRuwru5-rR7yOlOlWzCCWE,5381
55
55
  jaxsim/rbda/contacts/__init__.py,sha256=0UnO9ZR3BwdjQa276jOFbPi90pporr32LSc0qa9UUm4,369
56
56
  jaxsim/rbda/contacts/common.py,sha256=-eM8d1kvJ2E_2_kAgZJk4s3x8vDZHNSyOAinwPmRmEk,3469
57
- jaxsim/rbda/contacts/relaxed_rigid.py,sha256=aXWgChShcnJFZkE-1NIqaFQ2O2qC-xJt8iCZHft54Sk,14106
57
+ jaxsim/rbda/contacts/relaxed_rigid.py,sha256=8kytUPYUmYXVrPEoHbCduFp5KOmOFPK4Vmqv3KhDqy8,15738
58
58
  jaxsim/rbda/contacts/rigid.py,sha256=6cU8kM8LMjEFbt8dtSg5nnz_uh4aD50sKw_svCzYUms,15633
59
59
  jaxsim/rbda/contacts/soft.py,sha256=NzzCYw5rvK8Fx_qH3fiMzPgey-KoxmRe9xkF3fluidE,18866
60
60
  jaxsim/terrain/__init__.py,sha256=f7lVX-iNpH_wkkjef9Qpjh19TTAUOQw76EiLYJDVizc,78
@@ -63,8 +63,8 @@ jaxsim/utils/__init__.py,sha256=Y5zyoRevl3EMVQadhZ4EtSwTEkDt2vcnFoRhPJjKTZ0,215
63
63
  jaxsim/utils/jaxsim_dataclass.py,sha256=TGmTQV2Lq7Q-2nLoAEaeNtkPa_qj0IKkdBm4COj46Os,11312
64
64
  jaxsim/utils/tracing.py,sha256=KDMoyVPlu2NJvFkhtZwq5AkqMMgajt3munvJom-vEjQ,650
65
65
  jaxsim/utils/wrappers.py,sha256=Fh82ZcaFi5fUnByyFLnmumaobsu1hJIvFdopUVzJ1ps,4052
66
- jaxsim-0.4.3.dev131.dist-info/LICENSE,sha256=eaYdFmdeMbiIoIiPzEK0MjP1S9wtFXjXNR5er49uLR0,1546
67
- jaxsim-0.4.3.dev131.dist-info/METADATA,sha256=V2ESbchw9Z7RqGlZ06BsnTE8Qv3YKXW_9Q3nKIfb4aE,17277
68
- jaxsim-0.4.3.dev131.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
69
- jaxsim-0.4.3.dev131.dist-info/top_level.txt,sha256=LxGMA8FLtXjQ6oI7N5gd_R_oSUHxpXxUEOfT1xS_ni0,7
70
- jaxsim-0.4.3.dev131.dist-info/RECORD,,
66
+ jaxsim-0.4.3.dev136.dist-info/LICENSE,sha256=eaYdFmdeMbiIoIiPzEK0MjP1S9wtFXjXNR5er49uLR0,1546
67
+ jaxsim-0.4.3.dev136.dist-info/METADATA,sha256=s2BueAYAMMILvoVvGMBl4M-3O3W0g8Zu9xo3t21ZpRU,17276
68
+ jaxsim-0.4.3.dev136.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
69
+ jaxsim-0.4.3.dev136.dist-info/top_level.txt,sha256=LxGMA8FLtXjQ6oI7N5gd_R_oSUHxpXxUEOfT1xS_ni0,7
70
+ jaxsim-0.4.3.dev136.dist-info/RECORD,,