Skip to content

Commit

Permalink
Add precompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
janbruedigam committed Mar 20, 2024
1 parent 7d9460c commit 4940f11
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 2 deletions.
2 changes: 2 additions & 0 deletions DojoEnvironments/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ version = "0.6.0"
[deps]
Dojo = "ac60b53e-8d92-4c83-b960-e78698fa1916"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
Dojo = "0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.7.0"
PrecompileTools = "1.0, 1.2"
julia = "1.6, 1.9"
5 changes: 5 additions & 0 deletions DojoEnvironments/src/DojoEnvironments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ using Random
using Dojo
import Dojo: string_to_symbol, add_limits, RotX, RotY, RotZ, rotation_vector, SVector

using PrecompileTools

include("mechanisms.jl")
include("environments.jl")
include("utilities.jl")
include("mechanisms/include.jl")
include("environments/include.jl")

# Precompilation
include("precompile.jl")

# Mechanism
export
get_mechanism,
Expand Down
61 changes: 61 additions & 0 deletions DojoEnvironments/src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@setup_workload begin
mechanisms = [
:ant,
:atlas,
:block,
:block2d,
:cartpole,
:dzhanibekov,
:exoskeleton,
:fourbar,
:halfcheetah,
:hopper,
:humanoid,
:npendulum,
:nslider,
:panda,
:pendulum,
:quadrotor,
:quadruped,
:raiberthopper,
:slider,
:snake,
:sphere,
:tippetop,
:twister,
:uuv,
:walker,
:youbot,
]

environments = [
:ant_ars,
:cartpole_dqn,
:pendulum,
:quadruped_waypoint,
:quadruped_sampling,
:quadrotor_waypoint,
:uuv_waypoint,
:youbot_waypoint,
]

@compile_workload begin
# Simulate all mechanisms
for name in mechanisms
mech = get_mechanism(name)
initialize!(mech, name)
simulate!(mech, mech.timestep * 2)
end

# Simulate all environments
for name in environments
env = get_environment(name; horizon=2)
x = get_state(env)
u = DojoEnvironments.input_map(env, nothing)
set_input!(env, nothing)
step!(env, x)
step!(env, x, u)
simulate!(env)
end
end
end
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MeshCat = "283c5d60-a78f-5afe-a0af-af636b173e11"
Meshing = "e6723b4c-ebff-59f1-b4b7-d97aa5274f73"
Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand All @@ -36,6 +37,7 @@ LightXML = "<0.9.0, 0.9.0"
MeshCat = "<0.16.0, 0.16.1"
Meshing = "<0.6.0, 0.6.0"
Polyhedra = "<0.7.6, 0.7.6"
PrecompileTools = "1.0, 1.2"
Quaternions = "0.5.2, 0.7.0, 0.7.6"
StaticArrays = "1.2, 1.9"
julia = "1.6, 1.10"
4 changes: 2 additions & 2 deletions examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
ClosedIntervals = "<0.3.1, 0.3.1"
ControlSystemsBase = "1.0, 1.10"
Dojo = "<0.7.3, 0.7.3"
DojoEnvironments = "<0.5.3, 0.5.3"
Dojo = "<0.7.4, 0.7.4"
DojoEnvironments = "<0.6.0, 0.6.0"
Flux = "<0.13.17, 0.13.17"
ForwardDiff = "<0.10.36, 0.10.36"
JLD2 = "<0.4.46, 0.4.46"
Expand Down
4 changes: 4 additions & 0 deletions src/Dojo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using GraphBasedSystems
using CoordinateTransformations

using DocStringExtensions
using PrecompileTools

# Utilities
include(joinpath("utilities", "methods.jl"))
Expand Down Expand Up @@ -147,6 +148,9 @@ include(joinpath("gradients", "state.jl"))
include(joinpath("gradients", "data.jl"))
include(joinpath("gradients", "utilities.jl"))

# Precompilation
include("precompile.jl")


# Bodies
export
Expand Down
40 changes: 40 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@setup_workload begin
@compile_workload begin
# One full simulation
origin = Origin()
body = Cylinder(0.1, 1, 1)
joint = JointConstraint(Revolute(origin, body, [1;0;0]; child_vertex=[0;0;1/2]))
mechanism = Mechanism(origin, [body], [joint])
controller!(mechanism, k) = set_input!(joint, [0])
set_minimal_coordinates!(mechanism, joint, [pi/4])
set_minimal_velocities!(mechanism, joint, [0.2])
storage = simulate!(mechanism, mechanism.timestep * 2, controller!, record=true)

# Common shapes
mesh = Mesh("", 1, rand(3,3))
box = Box(1,1,1,1.0)
capsule = Capsule(1,1,1.0)
cylinder = Cylinder(1, 1, 1.0)
sphere = Sphere(1,1.0)
pyramid = Pyramid(1,1,1.0)

# Common joints
joint_axis = [1;0;0]
JointConstraint(Floating(origin, mesh))
JointConstraint(Fixed(origin, box))
JointConstraint(Prismatic(origin, capsule, joint_axis))
JointConstraint(Planar(origin, cylinder, joint_axis))
JointConstraint(FixedOrientation(origin, sphere))
JointConstraint(Revolute(origin, pyramid, joint_axis))
JointConstraint(Cylindrical(origin, mesh, joint_axis))
JointConstraint(PlanarAxis(origin, box, joint_axis))
JointConstraint(FreeRevolute(origin, capsule, joint_axis))
JointConstraint(Orbital(origin, cylinder, joint_axis))
JointConstraint(PrismaticOrbital(origin, sphere, joint_axis))
JointConstraint(PlanarOrbital(origin, pyramid, joint_axis))
JointConstraint(FreeOrbital(origin, mesh, joint_axis))
JointConstraint(Spherical(origin, box))
JointConstraint(CylindricalFree(origin, capsule, joint_axis))
JointConstraint(PlanarFree(origin, cylinder, joint_axis))
end
end

0 comments on commit 4940f11

Please sign in to comment.