Skip to content

Commit 4940f11

Browse files
committed
Add precompilation
1 parent 7d9460c commit 4940f11

File tree

7 files changed

+116
-2
lines changed

7 files changed

+116
-2
lines changed

DojoEnvironments/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ version = "0.6.0"
66
[deps]
77
Dojo = "ac60b53e-8d92-4c83-b960-e78698fa1916"
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
9+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
910
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1011

1112
[compat]
1213
Dojo = "0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.7.0"
14+
PrecompileTools = "1.0, 1.2"
1315
julia = "1.6, 1.9"

DojoEnvironments/src/DojoEnvironments.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ using Random
66
using Dojo
77
import Dojo: string_to_symbol, add_limits, RotX, RotY, RotZ, rotation_vector, SVector
88

9+
using PrecompileTools
10+
911
include("mechanisms.jl")
1012
include("environments.jl")
1113
include("utilities.jl")
1214
include("mechanisms/include.jl")
1315
include("environments/include.jl")
1416

17+
# Precompilation
18+
include("precompile.jl")
19+
1520
# Mechanism
1621
export
1722
get_mechanism,

DojoEnvironments/src/precompile.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@setup_workload begin
2+
mechanisms = [
3+
:ant,
4+
:atlas,
5+
:block,
6+
:block2d,
7+
:cartpole,
8+
:dzhanibekov,
9+
:exoskeleton,
10+
:fourbar,
11+
:halfcheetah,
12+
:hopper,
13+
:humanoid,
14+
:npendulum,
15+
:nslider,
16+
:panda,
17+
:pendulum,
18+
:quadrotor,
19+
:quadruped,
20+
:raiberthopper,
21+
:slider,
22+
:snake,
23+
:sphere,
24+
:tippetop,
25+
:twister,
26+
:uuv,
27+
:walker,
28+
:youbot,
29+
]
30+
31+
environments = [
32+
:ant_ars,
33+
:cartpole_dqn,
34+
:pendulum,
35+
:quadruped_waypoint,
36+
:quadruped_sampling,
37+
:quadrotor_waypoint,
38+
:uuv_waypoint,
39+
:youbot_waypoint,
40+
]
41+
42+
@compile_workload begin
43+
# Simulate all mechanisms
44+
for name in mechanisms
45+
mech = get_mechanism(name)
46+
initialize!(mech, name)
47+
simulate!(mech, mech.timestep * 2)
48+
end
49+
50+
# Simulate all environments
51+
for name in environments
52+
env = get_environment(name; horizon=2)
53+
x = get_state(env)
54+
u = DojoEnvironments.input_map(env, nothing)
55+
set_input!(env, nothing)
56+
step!(env, x)
57+
step!(env, x, u)
58+
simulate!(env)
59+
end
60+
end
61+
end

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1717
MeshCat = "283c5d60-a78f-5afe-a0af-af636b173e11"
1818
Meshing = "e6723b4c-ebff-59f1-b4b7-d97aa5274f73"
1919
Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029"
20+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
2021
Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
2122
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2223
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -36,6 +37,7 @@ LightXML = "<0.9.0, 0.9.0"
3637
MeshCat = "<0.16.0, 0.16.1"
3738
Meshing = "<0.6.0, 0.6.0"
3839
Polyhedra = "<0.7.6, 0.7.6"
40+
PrecompileTools = "1.0, 1.2"
3941
Quaternions = "0.5.2, 0.7.0, 0.7.6"
4042
StaticArrays = "1.2, 1.9"
4143
julia = "1.6, 1.10"

examples/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1717
[compat]
1818
ClosedIntervals = "<0.3.1, 0.3.1"
1919
ControlSystemsBase = "1.0, 1.10"
20-
Dojo = "<0.7.3, 0.7.3"
21-
DojoEnvironments = "<0.5.3, 0.5.3"
20+
Dojo = "<0.7.4, 0.7.4"
21+
DojoEnvironments = "<0.6.0, 0.6.0"
2222
Flux = "<0.13.17, 0.13.17"
2323
ForwardDiff = "<0.10.36, 0.10.36"
2424
JLD2 = "<0.4.46, 0.4.46"

src/Dojo.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using GraphBasedSystems
3030
using CoordinateTransformations
3131

3232
using DocStringExtensions
33+
using PrecompileTools
3334

3435
# Utilities
3536
include(joinpath("utilities", "methods.jl"))
@@ -147,6 +148,9 @@ include(joinpath("gradients", "state.jl"))
147148
include(joinpath("gradients", "data.jl"))
148149
include(joinpath("gradients", "utilities.jl"))
149150

151+
# Precompilation
152+
include("precompile.jl")
153+
150154

151155
# Bodies
152156
export

src/precompile.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@setup_workload begin
2+
@compile_workload begin
3+
# One full simulation
4+
origin = Origin()
5+
body = Cylinder(0.1, 1, 1)
6+
joint = JointConstraint(Revolute(origin, body, [1;0;0]; child_vertex=[0;0;1/2]))
7+
mechanism = Mechanism(origin, [body], [joint])
8+
controller!(mechanism, k) = set_input!(joint, [0])
9+
set_minimal_coordinates!(mechanism, joint, [pi/4])
10+
set_minimal_velocities!(mechanism, joint, [0.2])
11+
storage = simulate!(mechanism, mechanism.timestep * 2, controller!, record=true)
12+
13+
# Common shapes
14+
mesh = Mesh("", 1, rand(3,3))
15+
box = Box(1,1,1,1.0)
16+
capsule = Capsule(1,1,1.0)
17+
cylinder = Cylinder(1, 1, 1.0)
18+
sphere = Sphere(1,1.0)
19+
pyramid = Pyramid(1,1,1.0)
20+
21+
# Common joints
22+
joint_axis = [1;0;0]
23+
JointConstraint(Floating(origin, mesh))
24+
JointConstraint(Fixed(origin, box))
25+
JointConstraint(Prismatic(origin, capsule, joint_axis))
26+
JointConstraint(Planar(origin, cylinder, joint_axis))
27+
JointConstraint(FixedOrientation(origin, sphere))
28+
JointConstraint(Revolute(origin, pyramid, joint_axis))
29+
JointConstraint(Cylindrical(origin, mesh, joint_axis))
30+
JointConstraint(PlanarAxis(origin, box, joint_axis))
31+
JointConstraint(FreeRevolute(origin, capsule, joint_axis))
32+
JointConstraint(Orbital(origin, cylinder, joint_axis))
33+
JointConstraint(PrismaticOrbital(origin, sphere, joint_axis))
34+
JointConstraint(PlanarOrbital(origin, pyramid, joint_axis))
35+
JointConstraint(FreeOrbital(origin, mesh, joint_axis))
36+
JointConstraint(Spherical(origin, box))
37+
JointConstraint(CylindricalFree(origin, capsule, joint_axis))
38+
JointConstraint(PlanarFree(origin, cylinder, joint_axis))
39+
end
40+
end

0 commit comments

Comments
 (0)