|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Broadcast Communication\n", |
| 8 | + "\n", |
| 9 | + "By default, communication occurs between all satellites that are specified by the communication\n", |
| 10 | + "method. This tutorial shows how to use two classes to configure a broadcast action that must be\n", |
| 11 | + "taken for communication to occur:\n", |
| 12 | + "\n", |
| 13 | + "* [Broadcast](../api_reference/act/index.html#bsk_rl.act.Broadcast), which gives satellites an action\n", |
| 14 | + " that enables communication from them at the end of the current step.\n", |
| 15 | + "* [BroadcastCommunication](../api_reference/comm/index.html#bsk_rl.comm.BroadcastCommunication), which\n", |
| 16 | + " can be combined with another communication method to limit communication from broadcasters to\n", |
| 17 | + " those satellites satisfying the requirements of the other communication method.\n", |
| 18 | + "\n", |
| 19 | + "## Configuring the Environment\n", |
| 20 | + "\n", |
| 21 | + "For this example, a multisatellite target imaging environment will be used. The goal is\n", |
| 22 | + "to maximize the value of unique images taken. This configuration is similar to the \n", |
| 23 | + "[Multi-Agent Environments](../examples/multiagent_envs.html) example." |
| 24 | + ] |
| 25 | + }, |
| 26 | + { |
| 27 | + "cell_type": "code", |
| 28 | + "execution_count": 1, |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [], |
| 31 | + "source": [ |
| 32 | + "from bsk_rl import sats, act, obs, scene, data, comm\n", |
| 33 | + "from bsk_rl.sim import dyn, fsw\n", |
| 34 | + "\n", |
| 35 | + "\n", |
| 36 | + "class ImagingSatellite(sats.ImagingSatellite):\n", |
| 37 | + " observation_spec = [\n", |
| 38 | + " obs.OpportunityProperties(\n", |
| 39 | + " dict(prop=\"priority\"),\n", |
| 40 | + " dict(prop=\"opportunity_open\", norm=5700.0),\n", |
| 41 | + " n_ahead_observe=4,\n", |
| 42 | + " )\n", |
| 43 | + " ]\n", |
| 44 | + " action_spec = [act.Broadcast(duration=15.0), act.Image(n_ahead_image=4)]\n", |
| 45 | + " dyn_type = dyn.FullFeaturedDynModel\n", |
| 46 | + " fsw_type = fsw.SteeringImagerFSWModel" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "markdown", |
| 51 | + "metadata": {}, |
| 52 | + "source": [ |
| 53 | + "Satellite properties are set to give the satellite near-unlimited power and storage resources. To randomize some parameters in a correlated manner across satellites, a ``sat_arg_randomizer`` is set and passed to the environment. In this case, the satellites are distributed in a trivial single-plane Walker-delta constellation." |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "cell_type": "code", |
| 58 | + "execution_count": 2, |
| 59 | + "metadata": {}, |
| 60 | + "outputs": [], |
| 61 | + "source": [ |
| 62 | + "from bsk_rl.utils.orbital import walker_delta_args\n", |
| 63 | + "\n", |
| 64 | + "N_AGENTS = 2\n", |
| 65 | + "sat_args = dict(\n", |
| 66 | + " imageAttErrorRequirement=0.01,\n", |
| 67 | + " imageRateErrorRequirement=0.01,\n", |
| 68 | + " batteryStorageCapacity=1e9,\n", |
| 69 | + " storedCharge_Init=1e9,\n", |
| 70 | + " dataStorageCapacity=1e12,\n", |
| 71 | + " u_max=0.4,\n", |
| 72 | + " K1=0.25,\n", |
| 73 | + " K3=3.0,\n", |
| 74 | + " omega_max=0.087,\n", |
| 75 | + " servo_Ki=5.0,\n", |
| 76 | + " servo_P=150 / 5,\n", |
| 77 | + ")\n", |
| 78 | + "sat_arg_randomizer = walker_delta_args(\n", |
| 79 | + " altitude=800.0, inc=60.0, n_planes=1, clustersize=N_AGENTS, clusterspacing=5.0\n", |
| 80 | + ")" |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "markdown", |
| 85 | + "metadata": {}, |
| 86 | + "source": [ |
| 87 | + "Todo" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": 3, |
| 93 | + "metadata": {}, |
| 94 | + "outputs": [], |
| 95 | + "source": [ |
| 96 | + "class BroadcastLOS(comm.BroadcastCommunication, comm.LOSMultiCommunication):\n", |
| 97 | + " pass" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "markdown", |
| 102 | + "metadata": {}, |
| 103 | + "source": [ |
| 104 | + "Todo" |
| 105 | + ] |
| 106 | + }, |
| 107 | + { |
| 108 | + "cell_type": "code", |
| 109 | + "execution_count": 4, |
| 110 | + "metadata": {}, |
| 111 | + "outputs": [ |
| 112 | + { |
| 113 | + "name": "stderr", |
| 114 | + "output_type": "stream", |
| 115 | + "text": [ |
| 116 | + "\u001b[90;3m2024-11-12 11:26:28,059 \u001b[0m\u001b[mgym \u001b[0m\u001b[mINFO \u001b[0m\u001b[mResetting environment with seed=2342335920\u001b[0m\n", |
| 117 | + "\u001b[90;3m2024-11-12 11:26:28,062 \u001b[0m\u001b[mscene.targets \u001b[0m\u001b[mINFO \u001b[0m\u001b[mGenerating 1000 targets\u001b[0m\n", |
| 118 | + "\u001b[90;3m2024-11-12 11:26:28,220 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mFinding opportunity windows from 0.00 to 600.00 seconds\u001b[0m\n", |
| 119 | + "\u001b[90;3m2024-11-12 11:26:28,246 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mFinding opportunity windows from 0.00 to 600.00 seconds\u001b[0m\n", |
| 120 | + "\u001b[90;3m2024-11-12 11:26:28,269 \u001b[0m\u001b[mgym \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[mEnvironment reset\u001b[0m\n" |
| 121 | + ] |
| 122 | + } |
| 123 | + ], |
| 124 | + "source": [ |
| 125 | + "from bsk_rl import ConstellationTasking\n", |
| 126 | + "\n", |
| 127 | + "env = ConstellationTasking(\n", |
| 128 | + " satellites=[ImagingSatellite(f\"EO-{i+1}\", sat_args) for i in range(N_AGENTS)],\n", |
| 129 | + " scenario=scene.UniformTargets(1000),\n", |
| 130 | + " rewarder=data.UniqueImageReward(),\n", |
| 131 | + " communicator=BroadcastLOS(),\n", |
| 132 | + " sat_arg_randomizer=sat_arg_randomizer,\n", |
| 133 | + " log_level=\"INFO\",\n", |
| 134 | + ")\n", |
| 135 | + "_ = env.reset()" |
| 136 | + ] |
| 137 | + }, |
| 138 | + { |
| 139 | + "cell_type": "markdown", |
| 140 | + "metadata": {}, |
| 141 | + "source": [ |
| 142 | + "Todo" |
| 143 | + ] |
| 144 | + }, |
| 145 | + { |
| 146 | + "cell_type": "code", |
| 147 | + "execution_count": 5, |
| 148 | + "metadata": {}, |
| 149 | + "outputs": [ |
| 150 | + { |
| 151 | + "name": "stderr", |
| 152 | + "output_type": "stream", |
| 153 | + "text": [ |
| 154 | + "\u001b[90;3m2024-11-12 11:26:28,276 \u001b[0m\u001b[mgym \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[93;1m=== STARTING STEP ===\u001b[0m\n", |
| 155 | + "\u001b[90;3m2024-11-12 11:26:28,277 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mtarget index 2 tasked\u001b[0m\n", |
| 156 | + "\u001b[90;3m2024-11-12 11:26:28,278 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mTarget(tgt-475) tasked for imaging\u001b[0m\n", |
| 157 | + "\u001b[90;3m2024-11-12 11:26:28,280 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mTarget(tgt-475) window enabled: 207.1 to 339.7\u001b[0m\n", |
| 158 | + "\u001b[90;3m2024-11-12 11:26:28,280 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[msetting timed terminal event at 339.7\u001b[0m\n", |
| 159 | + "\u001b[90;3m2024-11-12 11:26:28,281 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mtarget index 1 tasked\u001b[0m\n", |
| 160 | + "\u001b[90;3m2024-11-12 11:26:28,281 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mTarget(tgt-81) tasked for imaging\u001b[0m\n", |
| 161 | + "\u001b[90;3m2024-11-12 11:26:28,282 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mTarget(tgt-81) window enabled: 143.6 to 213.3\u001b[0m\n", |
| 162 | + "\u001b[90;3m2024-11-12 11:26:28,282 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<0.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[msetting timed terminal event at 213.3\u001b[0m\n", |
| 163 | + "\u001b[90;3m2024-11-12 11:26:28,313 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<146.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mimaged Target(tgt-81)\u001b[0m\n", |
| 164 | + "\u001b[90;3m2024-11-12 11:26:28,315 \u001b[0m\u001b[mdata.base \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<146.00> \u001b[0m\u001b[mData reward: {'EO-2': 0.1336693557001335}\u001b[0m\n", |
| 165 | + "\u001b[90;3m2024-11-12 11:26:28,318 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<146.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mSatellite EO-2 requires retasking\u001b[0m\n", |
| 166 | + "\u001b[90;3m2024-11-12 11:26:28,320 \u001b[0m\u001b[mgym \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<146.00> \u001b[0m\u001b[mStep reward: {'EO-2': 0.1336693557001335}\u001b[0m\n" |
| 167 | + ] |
| 168 | + } |
| 169 | + ], |
| 170 | + "source": [ |
| 171 | + "_ = env.step({env.agents[0]: 3, env.agents[1]: 2})" |
| 172 | + ] |
| 173 | + }, |
| 174 | + { |
| 175 | + "cell_type": "markdown", |
| 176 | + "metadata": {}, |
| 177 | + "source": [ |
| 178 | + "Todo" |
| 179 | + ] |
| 180 | + }, |
| 181 | + { |
| 182 | + "cell_type": "code", |
| 183 | + "execution_count": 6, |
| 184 | + "metadata": {}, |
| 185 | + "outputs": [ |
| 186 | + { |
| 187 | + "name": "stderr", |
| 188 | + "output_type": "stream", |
| 189 | + "text": [ |
| 190 | + "\u001b[90;3m2024-11-12 11:26:28,324 \u001b[0m\u001b[mgym \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<146.00> \u001b[0m\u001b[93;1m=== STARTING STEP ===\u001b[0m\n", |
| 191 | + "\u001b[90;3m2024-11-12 11:26:28,325 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<146.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[msetting timed terminal event at 161.0\u001b[0m\n", |
| 192 | + "\u001b[90;3m2024-11-12 11:26:28,328 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<146.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[msetting timed terminal event at 161.0\u001b[0m\n", |
| 193 | + "\u001b[90;3m2024-11-12 11:26:28,331 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mtimed termination at 161.0 for broadcast\u001b[0m\n", |
| 194 | + "\u001b[90;3m2024-11-12 11:26:28,332 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mtimed termination at 161.0 for broadcast\u001b[0m\n", |
| 195 | + "\u001b[90;3m2024-11-12 11:26:28,334 \u001b[0m\u001b[mdata.base \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[mData reward: {}\u001b[0m\n", |
| 196 | + "\u001b[90;3m2024-11-12 11:26:28,335 \u001b[0m\u001b[mcomm.communication \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[mCommunicating data through 2 satellite connections\u001b[0m\n", |
| 197 | + "\u001b[90;3m2024-11-12 11:26:28,336 \u001b[0m\u001b[mcomm.communication \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[mOptimizing data communication between all pairs of satellites\u001b[0m\n", |
| 198 | + "\u001b[90;3m2024-11-12 11:26:28,338 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mSatellite EO-1 requires retasking\u001b[0m\n", |
| 199 | + "\u001b[90;3m2024-11-12 11:26:28,338 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mSatellite EO-2 requires retasking\u001b[0m\n", |
| 200 | + "\u001b[90;3m2024-11-12 11:26:28,340 \u001b[0m\u001b[mgym \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[mStep reward: {}\u001b[0m\n" |
| 201 | + ] |
| 202 | + } |
| 203 | + ], |
| 204 | + "source": [ |
| 205 | + "_ = env.step({env.agents[0]: 0, env.agents[1]: 0}) # Agent 1 broadcasts" |
| 206 | + ] |
| 207 | + }, |
| 208 | + { |
| 209 | + "cell_type": "markdown", |
| 210 | + "metadata": {}, |
| 211 | + "source": [ |
| 212 | + "Todo" |
| 213 | + ] |
| 214 | + }, |
| 215 | + { |
| 216 | + "cell_type": "code", |
| 217 | + "execution_count": 7, |
| 218 | + "metadata": {}, |
| 219 | + "outputs": [ |
| 220 | + { |
| 221 | + "name": "stderr", |
| 222 | + "output_type": "stream", |
| 223 | + "text": [ |
| 224 | + "\u001b[90;3m2024-11-12 11:26:28,344 \u001b[0m\u001b[mgym \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[93;1m=== STARTING STEP ===\u001b[0m\n", |
| 225 | + "\u001b[90;3m2024-11-12 11:26:28,344 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mtarget index 2 tasked\u001b[0m\n", |
| 226 | + "\u001b[90;3m2024-11-12 11:26:28,345 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mTarget(tgt-287) tasked for imaging\u001b[0m\n", |
| 227 | + "\u001b[90;3m2024-11-12 11:26:28,347 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[mTarget(tgt-287) window enabled: 256.8 to 406.3\u001b[0m\n", |
| 228 | + "\u001b[90;3m2024-11-12 11:26:28,347 \u001b[0m\u001b[36msats.satellite.EO-1 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[36mEO-1: \u001b[0m\u001b[msetting timed terminal event at 406.3\u001b[0m\n", |
| 229 | + "\u001b[90;3m2024-11-12 11:26:28,347 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<161.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[msetting timed terminal event at 176.0\u001b[0m\n", |
| 230 | + "\u001b[90;3m2024-11-12 11:26:28,350 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<176.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mtimed termination at 176.0 for broadcast\u001b[0m\n", |
| 231 | + "\u001b[90;3m2024-11-12 11:26:28,352 \u001b[0m\u001b[mdata.base \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<176.00> \u001b[0m\u001b[mData reward: {}\u001b[0m\n", |
| 232 | + "\u001b[90;3m2024-11-12 11:26:28,353 \u001b[0m\u001b[mcomm.communication \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<176.00> \u001b[0m\u001b[mCommunicating data through 1 satellite connections\u001b[0m\n", |
| 233 | + "\u001b[90;3m2024-11-12 11:26:28,354 \u001b[0m\u001b[92msats.satellite.EO-2 \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<176.00> \u001b[0m\u001b[92mEO-2: \u001b[0m\u001b[mSatellite EO-2 requires retasking\u001b[0m\n", |
| 234 | + "\u001b[90;3m2024-11-12 11:26:28,356 \u001b[0m\u001b[mgym \u001b[0m\u001b[mINFO \u001b[0m\u001b[33m<176.00> \u001b[0m\u001b[mStep reward: {}\u001b[0m\n" |
| 235 | + ] |
| 236 | + } |
| 237 | + ], |
| 238 | + "source": [ |
| 239 | + "_ = env.step({env.agents[0]: 3, env.agents[1]: 0}) # Agent 1 broadcasts" |
| 240 | + ] |
| 241 | + } |
| 242 | + ], |
| 243 | + "metadata": { |
| 244 | + "kernelspec": { |
| 245 | + "display_name": ".venv", |
| 246 | + "language": "python", |
| 247 | + "name": "python3" |
| 248 | + }, |
| 249 | + "language_info": { |
| 250 | + "codemirror_mode": { |
| 251 | + "name": "ipython", |
| 252 | + "version": 3 |
| 253 | + }, |
| 254 | + "file_extension": ".py", |
| 255 | + "mimetype": "text/x-python", |
| 256 | + "name": "python", |
| 257 | + "nbconvert_exporter": "python", |
| 258 | + "pygments_lexer": "ipython3", |
| 259 | + "version": "3.10.11" |
| 260 | + } |
| 261 | + }, |
| 262 | + "nbformat": 4, |
| 263 | + "nbformat_minor": 2 |
| 264 | +} |
0 commit comments