Skip to content

Commit 7453b97

Browse files
authored
Merge pull request #185 from aidotse/main
main -> release (for v0.2.0)
2 parents de801ac + 61d0610 commit 7453b97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2560
-681
lines changed

.github/workflows/autoblack.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Black Format Check
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: psf/black@stable
11+
with:
12+
options: "--check --line-length 100"
13+
src: "."
14+
jupyter: false
15+
version: "23.3.0"

.github/workflows/run_tests.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ jobs:
2525
2626
build:
2727
runs-on: ubuntu-latest
28-
28+
permissions:
29+
pull-requests: write
30+
contents: read
31+
id-token: write
2932
steps:
3033
- uses: actions/checkout@v2
3134
- name: Set up Python 3.9
@@ -47,6 +50,18 @@ jobs:
4750
shell: bash -l {0}
4851
run: |
4952
micromamba activate paseos
50-
cd paseos/tests
51-
micromamba install pytest
52-
pytest
53+
micromamba install pytest pytest-cov pytest-asyncio
54+
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=paseos paseos/tests/ | tee pytest-coverage.txt
55+
- name: Pytest coverage comment
56+
uses: MishaKav/pytest-coverage-comment@main
57+
if: github.event_name == 'pull_request'
58+
with:
59+
pytest-coverage-path: ./pytest-coverage.txt
60+
title: Coverage Report
61+
badge-title: Overall Coverage
62+
hide-badge: false
63+
hide-report: false
64+
create-new-comment: false
65+
hide-comment: false
66+
report-only-changed-files: false
67+
junitxml-path: ./pytest.xml

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,7 @@ examples/Sentinel_2_example_notebook/La_Palma_02.tif
136136
paseos/tests/de421.bsp
137137
test.csv
138138
thermal_test.csv
139-
results
139+
results
140+
pytest-coverage.txt
141+
pytest.xml
142+
examples/Orekit_example/orekit-data.zip

README.md

Lines changed: 393 additions & 93 deletions
Large diffs are not rendered by default.

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies:
88
- numpy==1.23.5 # core non-optional depedency
99
- myst-parser # for markdown math in docs
1010
- pykep>=2.6 # core non-optional dependency
11+
- pyquaternion>=0.9.9 # core non-optional dependency
1112
- pytest # for tests
1213
- pytest-asyncio # for tests involving activities
1314
- python>=3.8 # core non-optional dependency

examples/Constellation_example/constellation_example_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def get_closest_entry(df, t, id):
1818

1919

2020
def get_analysis_df(df, timestep=60, orbital_period=1):
21-
2221
t = np.round(np.linspace(0, df.Time.max(), int(df.Time.max() // timestep)))
2322
sats = df.ID.unique()
2423
df["known_actors"] = pd.Categorical(df.known_actors)

examples/Learning_example/simple_neural_network.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def __len__(self):
5757

5858
# Instantiate training and test data
5959
X, y = make_circles(n_samples=10000, noise=0.05, random_state=26)
60-
X_train, X_test, y_train, y_test = train_test_split(
61-
X, y, test_size=0.33, random_state=26
62-
)
60+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=26)
6361

6462
# divide the training set so none of the peers have the same data
6563
if self.node_id == 1:
@@ -75,12 +73,8 @@ def __len__(self):
7573
# Create dataloaders
7674
train_data = Data(X_train, y_train)
7775
test_data = Data(X_test, y_test)
78-
self.train_dataloader = DataLoader(
79-
dataset=train_data, batch_size=64, shuffle=True
80-
)
81-
self.test_dataloader = DataLoader(
82-
dataset=test_data, batch_size=64, shuffle=True
83-
)
76+
self.train_dataloader = DataLoader(dataset=train_data, batch_size=64, shuffle=True)
77+
self.test_dataloader = DataLoader(dataset=test_data, batch_size=64, shuffle=True)
8478

8579
def forward(self, x):
8680
"""Do inference on model

examples/Learning_example/simple_node.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ class Node:
1313
"""
1414

1515
def __init__(self, node_id, pos_and_vel, paseos_cfg, power_consumption_in_watt):
16-
1716
# Create PASEOS instance to node
1817
earth = pk.planet.jpl_lp("earth")
1918
self.node_id = node_id
20-
sat = ActorBuilder.get_actor_scaffold(
21-
f"sat{node_id}", SpacecraftActor, pk.epoch(0)
22-
)
19+
sat = ActorBuilder.get_actor_scaffold(f"sat{node_id}", SpacecraftActor, pk.epoch(0))
2320
ActorBuilder.set_orbit(sat, pos_and_vel[0], pos_and_vel[1], pk.epoch(0), earth)
2421
ActorBuilder.set_power_devices(
2522
actor=sat,
@@ -37,8 +34,7 @@ def __init__(self, node_id, pos_and_vel, paseos_cfg, power_consumption_in_watt):
3734

3835
transmit_bits = self.model_size()
3936
self.transmit_duration = transmit_bits / (
40-
1000
41-
* self.paseos.local_actor.communication_devices["link"].bandwidth_in_kbps
37+
1000 * self.paseos.local_actor.communication_devices["link"].bandwidth_in_kbps
4238
)
4339

4440
self.current_activity = "train"
@@ -70,9 +66,7 @@ def model_size(self):
7066
# Return model parameters as a list of NumPy ndarrays
7167
bytestream = b"" # Empty byte represenation
7268
for _, val in self.model.state_dict().items(): # go over each layer
73-
bytestream += (
74-
val.cpu().numpy().tobytes()
75-
) # convert layer to bytes and concatenate
69+
bytestream += val.cpu().numpy().tobytes() # convert layer to bytes and concatenate
7670
return len(bytestream) * 8
7771

7872
def local_time(self):
@@ -112,9 +106,7 @@ def transmission_is_feasible(self, target_node):
112106
target_actor = target_node.paseos.local_actor
113107
local_actor = self.paseos.local_actor
114108

115-
transmit_end = pk.epoch(
116-
self.local_time().mjd2000 + self.transmit_duration * pk.SEC2DAY
117-
)
109+
transmit_end = pk.epoch(self.local_time().mjd2000 + self.transmit_duration * pk.SEC2DAY)
118110
los_end = local_actor.is_in_line_of_sight(target_actor, transmit_end)
119111
return los_end
120112

examples/MPI_example/mpi_example.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
try:
2727
from mpi4py import MPI
2828
except:
29-
print(
30-
"This example requires mpi4py. Please install with conda install mpi4py -c conda-forge"
31-
)
29+
print("This example requires mpi4py. Please install with conda install mpi4py -c conda-forge")
3230

3331
import pykep as pk
3432
import paseos
@@ -44,9 +42,7 @@
4442
# Now we will initialize MPI, for more details please refer to the mpi4py docs.
4543
# In MPI "rank" indicates the index of the compute node (so 0-3 in our example).
4644
comm = MPI.COMM_WORLD
47-
assert (
48-
comm.Get_size() == 4
49-
), "Please run the example with mpiexec -n 4 python mpi_example.py"
45+
assert comm.Get_size() == 4, "Please run the example with mpiexec -n 4 python mpi_example.py"
5046
rank = comm.Get_rank()
5147
other_ranks = [x for x in range(4) if x != rank]
5248
print(f"Started rank {rank}, other ranks are {other_ranks}")
@@ -65,9 +61,7 @@
6561
planet_list, sats_pos_and_v, _ = get_constellation(
6662
altitude, inclination, nSats, nPlanes, t0, verbose=False
6763
)
68-
print(
69-
f"Rank {rank} set up its orbit with altitude={altitude}m and inclination={inclination}deg"
70-
)
64+
print(f"Rank {rank} set up its orbit with altitude={altitude}m and inclination={inclination}deg")
7165

7266
############ PASEOS INIT #############
7367
# We will now initialize the PASEOS instance on each rank
@@ -78,9 +72,7 @@
7872
local_actor = ActorBuilder.get_actor_scaffold(
7973
name="Sat_" + str(rank), actor_type=SpacecraftActor, epoch=t0
8074
)
81-
ActorBuilder.set_orbit(
82-
actor=local_actor, position=pos, velocity=v, epoch=t0, central_body=earth
83-
)
75+
ActorBuilder.set_orbit(actor=local_actor, position=pos, velocity=v, epoch=t0, central_body=earth)
8476

8577
paseos_instance = paseos.init_sim(local_actor=local_actor)
8678
print(f"Rank {rank} set up its PASEOS instance for its local actor {local_actor}")
@@ -97,6 +89,7 @@
9789
# Let's define the variable to track the actors we see
9890
total_seen_actors = 0
9991

92+
10093
# We will (ab)use PASEOS constraint function to track all the actors
10194
# we see in an evaluation window (see timestep below).
10295
# Turn on SHOW_ALL_WINDOWS if you want to see each window
@@ -135,7 +128,6 @@ def constraint_func(verbose=SHOW_ALL_WINDOWS):
135128

136129
# Run until end of simulation
137130
while t <= simulation_time:
138-
139131
# Advance the simulation state of this rank
140132
# Note how we pass the "constraint_func" to tell paseos
141133
# to track windows
@@ -147,9 +139,7 @@ def constraint_func(verbose=SHOW_ALL_WINDOWS):
147139
sys.stdout.flush() # update prints to better see parallelism
148140

149141
# Exchange actors between all ranks
150-
exchange_actors(
151-
comm, paseos_instance, local_actor, other_ranks, rank, verbose=SHOW_ALL_COMMS
152-
)
142+
exchange_actors(comm, paseos_instance, local_actor, other_ranks, rank, verbose=SHOW_ALL_COMMS)
153143

154144
# Wait until all ranks finished
155145
print(f"Rank {rank} finished the simulation. Waiting for all to finish.")

examples/MPI_example/mpi_utility_func.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def _parse_actor_data(actor_data):
4848
return actor
4949

5050

51-
def exchange_actors(
52-
comm, paseos_instance, local_actor, other_ranks, rank, verbose=False
53-
):
51+
def exchange_actors(comm, paseos_instance, local_actor, other_ranks, rank, verbose=False):
5452
"""This function exchanges the states of various actors among all MPI ranks.
5553
5654
Args:
@@ -69,9 +67,7 @@ def exchange_actors(
6967
# Send local actor to other ranks
7068
for i in other_ranks:
7169
actor_data = _encode_actor(local_actor)
72-
send_requests.append(
73-
comm.isend(actor_data, dest=i, tag=int(str(rank) + str(i)))
74-
)
70+
send_requests.append(comm.isend(actor_data, dest=i, tag=int(str(rank) + str(i))))
7571

7672
# Receive from other ranks
7773
for i in other_ranks:

0 commit comments

Comments
 (0)