-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from aidotse/faster-than-real-time
Faster than real time execution
- Loading branch information
Showing
6 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Simple test of modifying rate of time passing""" | ||
|
||
import asyncio | ||
import pytest | ||
import pykep as pk | ||
|
||
import paseos | ||
from paseos import ActorBuilder, SpacecraftActor, load_default_cfg | ||
|
||
|
||
async def wait_for_activity(sim): | ||
while sim._is_running_activity is True: | ||
await asyncio.sleep(0.1) | ||
|
||
|
||
# tell pytest to create an event loop and execute the tests using the event loop | ||
@pytest.mark.asyncio | ||
async def test_activity(): | ||
"""Test to see if twice as much power is consumed given the higher than real-time multiplier""" | ||
# Define central body | ||
earth = pk.planet.jpl_lp("earth") | ||
|
||
# Define local actor | ||
sat1 = ActorBuilder.get_actor_scaffold("sat1", SpacecraftActor, pk.epoch(0)) | ||
ActorBuilder.set_orbit(sat1, [10000000, 0, 0], [0, 8000.0, 0], pk.epoch(0), earth) | ||
ActorBuilder.set_power_devices(sat1, 500, 10000, 1) | ||
# init simulation | ||
|
||
cfg = load_default_cfg() # loading cfg to modify defaults | ||
cfg.sim.time_multiplier = 10 | ||
sim = paseos.init_sim(sat1, cfg) | ||
|
||
# Initial power is 500 | ||
assert sat1.battery_level_in_Ws == 500 | ||
|
||
# Out test case is a function that increments a value, genius. | ||
# (needs a list to increase the actual value by reference and not create a copy) | ||
test_val = [0] | ||
|
||
async def func(args): | ||
for _ in range(10): | ||
args[0][0] += 1 | ||
await asyncio.sleep(0.2) | ||
|
||
# Register an activity that draws 10 watt per second | ||
sim.register_activity( | ||
"Testing", activity_function=func, power_consumption_in_watt=10 | ||
) | ||
|
||
# Run the activity | ||
sim.perform_activity("Testing", activity_func_args=[test_val]) | ||
await wait_for_activity(sim) | ||
|
||
# Check activity result | ||
assert test_val[0] == 10 | ||
|
||
# Check power was depleted as expected | ||
# Activity should run roughly 2s | ||
# We charge 1W per second | ||
# 1s real time equals 10s simulation | ||
# And discharge 10W per second | ||
# So should be roughly 200W - 20W consumed from starting 500 | ||
assert sat1.battery_level_in_Ws > 315 and sat1.battery_level_in_Ws < 325 |