Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2000 committed May 30, 2024
1 parent 5fab334 commit 4b10225
Show file tree
Hide file tree
Showing 12 changed files with 569 additions and 177 deletions.
8 changes: 4 additions & 4 deletions docs/build/doctrees/nbsphinx/examples/multiagent_envs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-30T01:14:11.832284Z",
"iopub.status.busy": "2024-05-30T01:14:11.832192Z",
"iopub.status.idle": "2024-05-30T01:14:11.836625Z",
"shell.execute_reply": "2024-05-30T01:14:11.836368Z"
"iopub.execute_input": "2024-05-30T02:22:13.170922Z",
"iopub.status.busy": "2024-05-30T02:22:13.170812Z",
"iopub.status.idle": "2024-05-30T02:22:13.176020Z",
"shell.execute_reply": "2024-05-30T02:22:13.175728Z"
}
},
"outputs": [],
Expand Down
8 changes: 4 additions & 4 deletions docs/build/doctrees/nbsphinx/examples/rllib_training.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-30T01:14:13.120944Z",
"iopub.status.busy": "2024-05-30T01:14:13.120825Z",
"iopub.status.idle": "2024-05-30T01:14:13.125502Z",
"shell.execute_reply": "2024-05-30T01:14:13.125218Z"
"iopub.execute_input": "2024-05-30T02:22:14.311233Z",
"iopub.status.busy": "2024-05-30T02:22:14.311148Z",
"iopub.status.idle": "2024-05-30T02:22:14.316857Z",
"shell.execute_reply": "2024-05-30T02:22:14.316565Z"
}
},
"outputs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-30T01:14:14.275239Z",
"iopub.status.busy": "2024-05-30T01:14:14.275138Z",
"iopub.status.idle": "2024-05-30T01:14:14.279420Z",
"shell.execute_reply": "2024-05-30T01:14:14.279142Z"
"iopub.execute_input": "2024-05-30T02:22:15.389648Z",
"iopub.status.busy": "2024-05-30T02:22:15.389566Z",
"iopub.status.idle": "2024-05-30T02:22:15.394202Z",
"shell.execute_reply": "2024-05-30T02:22:15.393962Z"
}
},
"outputs": [
Expand Down
609 changes: 528 additions & 81 deletions docs/build/doctrees/nbsphinx/examples/simple_environment.ipynb

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,6 @@ def run(self, source_dir=None):
nb_cache = (
self.nb_cache_dir / self.base_doc_dir / index_path / notebook.name
)

print()
print(notebook.resolve())
print("cache at", nb_cache.resolve(), nb_cache.is_file())

if (
self.nb_cache_dir is not None
and nb_cache.is_file()
Expand All @@ -305,13 +300,11 @@ def run(self, source_dir=None):
).__repr__()
)
):
print("COPYING CACHE")
shutil.copy(
nb_cache,
self.base_doc_dir / index_path / notebook.name,
)
else:
print("COPYING NOTEBOOK")
shutil.copy(notebook, self.base_doc_dir / index_path / notebook.name)

# Recursively go through all directories in source, documenting what is available.
Expand Down
72 changes: 4 additions & 68 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BSK-RL: Environments Spacecraft Planning and Scheduling
=======================================================
BSK-RL: Environments for Spacecraft Planning and Scheduling
===========================================================

.. toctree::
:hidden:
Expand Down Expand Up @@ -58,72 +58,8 @@ Complete installation instructions and common troubleshooting tips can be found
Construct an Environment
^^^^^^^^^^^^^^^^^^^^^^^^

A more detailed tutorial can be found at :doc:`examples/simple_environment`. To construct
an environment

#. Import the necessary modules.

.. code-block:: python
import gymnasium as gym
import bsk_rl
from bsk_rl import act, obs, scene, sats
#. Describe the satellite's actions and observations.

.. code-block:: python
class MyImagingSatellite(sats.Satellite):
observation_spec = [
obs.SatProperties(
dict(prop="storage_level_fraction"),
dict(prop="battery_charge_fraction")
),
obs.Eclipse(),
obs.OpportunityProperties(
dict(prop="opportunity_open"),
dict(prop="opportunity_close"),
n_ahead_observe=2,
type="ground_station",
),
]
action_spec = [
act.Scan(duration=60.0),
act.Charge(duration=120.0),
act.Downlink(duration=60.0),
]
#. Make the environment. Pass specific and randomized configurations to the satellite.

.. code-block:: python
env = gym.make(
"SatelliteTasking-v1",
satellites=MyImagingSatellite(
name="EO1",
sat_args=dict(
imageAttErrorRequirement=0.05,
imageRateErrorRequirement=0.05,
dataStorageCapacity=3.0,
storageInit=lambda: np.random.uniform(0.5, 2.5),
)),
scenario=scene.UniformNadirScanning(value_per_second=1/10000.0),
time_limit=10000.0,
failure_penalty=-1.0,
log_level="INFO",
)
#. Step through the environment with random actions.

.. code-block:: python
obs, info = env.reset()
terminated = False
truncated = False
while not (terminated or truncated):
action = env.action_space.sample()
observation, reward, terminated, truncated, info = env.step(action)
A quick but comprehensive tutorial can be found at :doc:`examples/simple_environment`.


Acknowledgements
----------------
Expand Down
33 changes: 25 additions & 8 deletions examples/simple_environment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
" obs.Eclipse(),\n",
" ]\n",
" action_spec = [\n",
" act.Scan(duration=60.0),\n",
" act.Charge(duration=120.0),\n",
" act.Scan(duration=60.0), # Scan for 1 minute\n",
" act.Charge(duration=600.0), # Charge for 10 minutes\n",
" ]\n",
" dyn_type = dyn.ContinuousImagingDynModel\n",
" fsw_type = fsw.ContinuousImagingFSWModel"
Expand Down Expand Up @@ -100,9 +100,9 @@
"\n",
"# Set some parameters as constants\n",
"sat_args[\"imageAttErrorRequirement\"] = 0.05\n",
"# sat_args[\"imageRateErrorRequirement\"] = 0.01\n",
"sat_args[\"dataStorageCapacity\"] = 1e10\n",
"sat_args[\"instrumentBaudRate\"] = 1e7\n",
"sat_args[\"storedCharge_Init\"] = 50000.0\n",
"\n",
"# Randomize the initial storage level on every reset\n",
"sat_args[\"storageInit\"] = lambda: np.random.uniform(0.25, 0.75) * 1e10\n",
Expand Down Expand Up @@ -134,6 +134,7 @@
" satellite=sat,\n",
" scenario=scene.UniformNadirScanning(),\n",
" rewarder=data.ScanningTimeReward(),\n",
" time_limit=5700.0, # approximately 1 orbit\n",
" log_level=\"INFO\",\n",
")"
]
Expand All @@ -153,15 +154,17 @@
"metadata": {},
"outputs": [],
"source": [
"observation, info = env.reset(seed=0)"
"observation, info = env.reset(seed=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we take the scan action (`action=0`) a few times. This allows for the satellite to\n",
"settle in the pointing mode to satisfy imaging conditions."
"settle its attitude in the nadir pointing mode to satisfy imaging conditions. Note that \n",
"the logs show little or no data accumulated in the first two steps as it settles, but\n",
"achieves 60 reward (corresponding to 60 seconds of imaging) by the third step."
]
},
{
Expand All @@ -180,7 +183,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the logs show little or no \n"
"The observation reflects the increase in stored data. The first element, corresponding\n",
"to `storage_level_fraction`, starts at a random value set by the `storageInit` function\n",
"in `sat_args` and increases based on the time spent imaging.\n",
"\n",
"Finally, the charging mode is tasked repeatedly in 10-minute increments until the\n",
"environment time limit is reached."
]
},
{
Expand All @@ -189,8 +197,17 @@
"metadata": {},
"outputs": [],
"source": [
"observation, reward, terminated, truncated, info = env.step(action=1)\n",
"diff = True"
"while not truncated:\n",
" observation, reward, terminated, truncated, info = env.step(action=1)\n",
" print(f\"Charge level: {observation[1]:.3f} ({env.unwrapped.simulator.sim_time:.1f} seconds)\\n\\tEclipse: start: {observation[2]:.1f} end: {observation[3]:.1f}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is observed that the battery decrease while the satellite is in eclipse, but once the\n",
"satellite is out of eclipse, the battery quickly increases to full charge."
]
}
],
Expand Down
1 change: 0 additions & 1 deletion src/bsk_rl/_default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ See the :ref:`examples` for more information on environment configuration argume
data/index
comm/index
sim/index
train/index
utils/index
Empty file removed src/bsk_rl/train/mcts_learn
Empty file.
Empty file removed src/bsk_rl/train/rllib
Empty file.
Empty file removed src/bsk_rl/train/shields
Empty file.
Empty file removed src/bsk_rl/train/todo
Empty file.

0 comments on commit 4b10225

Please sign in to comment.