Skip to content

Commit ad64ae3

Browse files
committed
Update readme and the machine clock docs
1 parent 8cfd03e commit ad64ae3

File tree

2 files changed

+28
-78
lines changed

2 files changed

+28
-78
lines changed

README.md

Lines changed: 13 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -13,103 +13,38 @@ A Julia package for scheduling tasks in simulation environments with precise tim
1313
```julia
1414
using EnvironmentEngine
1515

16-
# Schedule a task every 20ms
17-
every(20ms) do dt
18-
println("Task executed")
19-
end
20-
21-
# Process scheduled jobs
22-
update!()
23-
```
24-
25-
This will schedule a task to run every 20 milliseconds. Whenever `update!` is called, `EnvironmentEngine` will sync the clock with the real time and execute the scheduled tasks. A common pattern is the following:
26-
27-
```julia
28-
using EnvironmentEngine
29-
30-
# Schedule a task every 200ms
16+
# Schedule a task every 200 milliseconds
3117
every(200ms) do dt
3218
println("Task executed at $(now(global_clock()))")
3319
end
3420

35-
# Process scheduled jobs
36-
for_next(5s) do
21+
# Run the scheduler for 1 second
22+
for_next(1s) do
3723
update!()
3824
end
3925
```
4026

41-
## Features
42-
43-
- **Timed Jobs**: Execute tasks at regular intervals
44-
- **ASAP Jobs**: Execute tasks as soon as possible
45-
- **Event Jobs**: Execute tasks when data arrives on channels
46-
- **Multiple Clocks**: Machine time or controllable virtual time
47-
- **Flexible Scheduling**: Global or custom schedulers
48-
4927
## Installation
5028

5129
```julia
5230
using Pkg
5331
Pkg.add("EnvironmentEngine")
5432
```
5533

56-
## Basic Example
57-
58-
```julia
59-
using EnvironmentEngine
60-
61-
# Schedule different types of jobs
62-
every(3ms) do dt
63-
println("Timed job: $(now(global_clock()))")
64-
# Irregularly send events
65-
if rand() < 0.5
66-
put!(events, "Event $(rand())")
67-
end
68-
end
69-
70-
# Run this as often and soon as possible
71-
every(asap) do
72-
println("ASAP job executed")
73-
end
74-
75-
# Create a channel for event-driven jobs
76-
events = Channel{String}(Inf)
77-
78-
# Run this when an event is received
79-
every(events) do event
80-
println("Event received: $event")
81-
end
82-
83-
# Simulate time progression
84-
for_next(20ms) do
85-
update!()
86-
end
87-
```
88-
89-
## Clock Types
90-
91-
### Machine Clock
92-
Uses system time:
93-
94-
```julia
95-
clock = MachineClock()
96-
println(now(clock)) # Current system time
97-
```
98-
99-
### Virtual Clock
100-
Controlled time for simulations:
34+
## Features
10135

102-
```julia
103-
clock = VirtualClock()
104-
set_time!(clock, 0.0s)
105-
advance_time!(clock, 50ms)
106-
println(now(clock)) # 0.05 s
107-
```
36+
- **Timed Jobs**: Execute tasks at regular intervals
37+
- **ASAP Jobs**: Execute tasks as soon as possible
38+
- **Event Jobs**: Execute tasks when data arrives on channels
39+
- **Multiple Clocks**: Machine time or controllable virtual time
40+
- **Flexible Scheduling**: Global or custom schedulers
41+
- **Multi-threading**: Parallel job execution
10842

10943
## Documentation
11044

111-
- [Getting Started](https://lazydynamics.github.io/EnvironmentEngine.jl/dev/getting_started/) - Quick setup and basic examples
112-
- [API Reference](https://lazydynamics.github.io/EnvironmentEngine.jl/dev/api/) - Complete function documentation
45+
- [Getting Started](https://lazydynamics.github.io/EnvironmentEngine.jl/dev/) - Quick setup and basic examples
46+
- [Tutorials](https://lazydynamics.github.io/EnvironmentEngine.jl/dev/tutorials/) - Step-by-step learning guide
47+
- [API Reference](https://lazydynamics.github.io/EnvironmentEngine.jl/dev/user_guide/api_reference/) - Complete function documentation
11348

11449
## License
11550

docs/src/tutorials/clocks_and_time.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ When created, the `MachineClock` is paused by default, and can be resumed and pa
3535
EnvironmentEngine.MachineClock
3636
```
3737

38+
#### Stretch Factor
39+
The `MachineClock` has a stretch factor, which is a factor by which the time is stretched. This is useful for building real-time applications, where the time is stretched to make the simulation run faster or slower than the real time. The stretch factor is set to 1.0 by default. If the stretch factor is greater than 1.0, the time will progress faster than the real time. For example, if the stretch factor is 2.0, the time will progress twice as fast as real time. You can set the stretch factor when creating the clock:
40+
41+
```@example clocks-machine-fast
42+
using EnvironmentEngine
43+
44+
clock = MachineClock(stretch_factor = 2.0)
45+
resume!(clock)
46+
sleep(1.0)
47+
pause!(clock)
48+
println(now(clock)) # Current system time, 2.0 seconds
49+
```
50+
51+
This is especially useful for debugging, and when you want to test if your agent has more/less computational resources available than on the machine you are running the simulation on.
52+
3853
**Use MachineClock when:**
3954
- Building real-time applications
4055
- You want to sync with wall clock time

0 commit comments

Comments
 (0)