Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mujoco Py
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Hollenstein
Mujoco Py
Commits
f66788ac
Unverified
Commit
f66788ac
authored
5 years ago
by
Million Integrals
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add option to override the mujoco error callback. (#434)
Mujoco 2.0.2.3
parent
320f195e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mujoco_py/cymj.pyx
+31
-0
31 additions, 0 deletions
mujoco_py/cymj.pyx
mujoco_py/tests/test_cymj.py
+15
-1
15 additions, 1 deletion
mujoco_py/tests/test_cymj.py
mujoco_py/version.py
+1
-1
1 addition, 1 deletion
mujoco_py/version.py
with
47 additions
and
2 deletions
mujoco_py/cymj.pyx
+
31
−
0
View file @
f66788ac
...
...
@@ -53,6 +53,7 @@ cdef extern from "gl/glshim.h":
# This is the python callback function. We save it in the global() context
# so we can access it from a C wrapper function (c_warning_callback)
cdef
object
py_warning_callback
cdef
object
py_error_callback
# This is the saved exception. Because the C callback can not propagate
# exceptions, this must be set to None before calling into MuJoCo, and then
# inspected afterwards.
...
...
@@ -99,6 +100,36 @@ def get_warning_callback():
return
py_warning_callback
cdef
void
c_error_callback
(
const
char
*
msg
)
with
gil
:
'''
Wraps the error callback so that we can pass a python function to the callback.
MuJoCo error handlers are expected to terminate the program and never return.
'''
global
py_error_callback
(
<
object
>
py_error_callback
)(
msg
)
def
set_error_callback
(
err_callback
):
'''
Set a user-defined error callback. It should take in a string message
(the warning string) and terminate the program.
See c_warning_callback, which is the C wrapper to the user defined function
'''
global
py_error_callback
global
mju_user_error
py_error_callback
=
err_callback
mju_user_error
=
c_error_callback
def
get_error_callback
():
'''
Returns the user-defined warning callback, for use in e.g. a context
manager.
'''
global
py_error_callback
return
py_error_callback
class
wrap_mujoco_warning
(
object
):
'''
Class to wrap capturing exceptions raised during warning callbacks.
...
...
This diff is collapsed.
Click to expand it.
mujoco_py/tests/test_cymj.py
+
15
−
1
View file @
f66788ac
...
...
@@ -14,7 +14,7 @@ from mujoco_py import (MjSim, load_model_from_xml,
load_model_from_path
,
MjSimState
,
ignore_mujoco_warnings
,
load_model_from_mjb
)
from
mujoco_py
import
const
,
cymj
from
mujoco_py
import
const
,
cymj
,
functions
from
mujoco_py.tests.utils
import
compare_imgs
...
...
@@ -334,6 +334,20 @@ def test_mj_warning_raises():
sim
.
step
()
def
test_mj_error_called
():
error_message
=
None
def
error_callback
(
msg
):
nonlocal
error_message
error_message
=
msg
.
decode
()
cymj
.
set_error_callback
(
error_callback
)
functions
.
mju_error
(
"
error
"
)
assert
error_message
==
"
error
"
def
test_ignore_mujoco_warnings
():
# Two boxes on a plane need more than 1 contact (nconmax)
xml
=
'''
...
...
This diff is collapsed.
Click to expand it.
mujoco_py/version.py
+
1
−
1
View file @
f66788ac
__all__
=
[
'
__version__
'
,
'
get_version
'
]
version_info
=
(
2
,
0
,
2
,
2
)
version_info
=
(
2
,
0
,
2
,
3
)
# format:
# ('mujoco_major', 'mujoco_minor', 'mujoco_py_major', 'mujoco_py_minor')
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment