From 0b6019d4f417710c83568ec364aade5d6dbb2885 Mon Sep 17 00:00:00 2001 From: Krzysztof Rusek Date: Mon, 15 Jul 2024 14:14:48 +0200 Subject: [PATCH 1/4] Rename walls to loss_gain --- mapc_sim/sim.py | 10 +++++----- mapc_sim/utils.py | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mapc_sim/sim.py b/mapc_sim/sim.py index f308ec1..b325645 100644 --- a/mapc_sim/sim.py +++ b/mapc_sim/sim.py @@ -12,7 +12,7 @@ def network_data_rate(key: PRNGKey, tx: Array, pos: Array, mcs: Array, tx_power: Array, sigma: Scalar, - walls: Array, return_sample: bool = False) -> Union[Scalar,tuple]: + loss_gain: Array, return_sample: bool = False) -> Union[Scalar,tuple]: r""" Calculates the aggregated effective data rate based on the nodes' positions, MCS, and tx power. Channel is modeled using TGax channel model with additive white Gaussian noise. Effective @@ -41,9 +41,9 @@ def network_data_rate(key: PRNGKey, tx: Array, pos: Array, mcs: Array, tx_power: Transmission power of the nodes. Each entry corresponds to the transmission power of the transmitting node. sigma: Scalar Standard deviation of the additive white Gaussian noise. - walls: Array - Adjacency matrix of walls. If node i is separated from node j by a wall, - then `walls[i, j] = 1`, otherwise `walls[i, j] = 0`. + loss_gain: Array + Adjacency matrix of combined loss and gain. If node `i` is separated from node `j` by a wall or the antena is directional, + then `loss_gain[i, j] = val`, otherwise `walls[i, j] = 0`. return_sample: bool A flag indicating whether the simulator returns raw number of transmitted frames. @@ -59,7 +59,7 @@ def network_data_rate(key: PRNGKey, tx: Array, pos: Array, mcs: Array, tx_power: distance = jnp.sqrt(jnp.sum((pos[:, None, :] - pos[None, ...]) ** 2, axis=-1)) distance = jnp.clip(distance, REFERENCE_DISTANCE, None) - signal_power = tx_power[:, None] - tgax_path_loss(distance, walls) + signal_power = tx_power[:, None] - tgax_path_loss(distance, loss_gain) interference_matrix = jnp.ones_like(tx) * tx.sum(axis=0) * tx.sum(axis=1, keepdims=True) * (1 - tx) a = jnp.concatenate([signal_power, jnp.full((1, signal_power.shape[1]), fill_value=NOISE_FLOOR)], axis=0) diff --git a/mapc_sim/utils.py b/mapc_sim/utils.py index c65b3d5..7e9ca49 100644 --- a/mapc_sim/utils.py +++ b/mapc_sim/utils.py @@ -1,11 +1,10 @@ import jax -import jax.numpy as jnp from chex import Array from mapc_sim.constants import * -def tgax_path_loss(distance: Array, walls: Array) -> Array: +def tgax_path_loss(distance: Array, loss_gain: Array) -> Array: r""" Calculates the path loss according to the TGax channel model [1]_. @@ -13,7 +12,7 @@ def tgax_path_loss(distance: Array, walls: Array) -> Array: ---------- distance: Array Distance between nodes - walls: Array + loss_gain: Array Adjacency matrix describing walls between nodes (1 if there is a wall, 0 otherwise). Returns @@ -27,7 +26,7 @@ def tgax_path_loss(distance: Array, walls: Array) -> Array: """ return (40.05 + 20 * jnp.log10((jnp.minimum(distance, BREAKING_POINT) * CENTRAL_FREQUENCY) / 2.4) + - (distance > BREAKING_POINT) * 35 * jnp.log10(distance / BREAKING_POINT) + WALL_LOSS * walls) + (distance > BREAKING_POINT) * 35 * jnp.log10(distance / BREAKING_POINT) + loss_gain) def logsumexp_db(a: Array, b: Array) -> Array: From 17cbb6e5dbb95e684462c388f266a4f14f6866e0 Mon Sep 17 00:00:00 2001 From: Krzysztof Rusek Date: Mon, 15 Jul 2024 14:26:35 +0200 Subject: [PATCH 2/4] API for directional antena and walls --- mapc_sim/experimental/antenas.py | 21 +++++++++++++++++++++ mapc_sim/experimental/walls.py | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 mapc_sim/experimental/antenas.py create mode 100644 mapc_sim/experimental/walls.py diff --git a/mapc_sim/experimental/antenas.py b/mapc_sim/experimental/antenas.py new file mode 100644 index 0000000..f16c6c3 --- /dev/null +++ b/mapc_sim/experimental/antenas.py @@ -0,0 +1,21 @@ +import chex +import jax.numpy as jnp + + +def isotropic(pos: chex.Array) -> chex.Array: + """Calculate gain matrix for each point to point communication. + + Parameters + ---------- + pos: Array + An array of 2d positions for `n` points + + Returns + ------- + Array + Antena gain for each point in pos. + + """ + npoints = pos.shape[0] + + return jnp.zeros((npoints, npoints)) diff --git a/mapc_sim/experimental/walls.py b/mapc_sim/experimental/walls.py new file mode 100644 index 0000000..f76198e --- /dev/null +++ b/mapc_sim/experimental/walls.py @@ -0,0 +1,20 @@ +import chex +import jax.numpy as jnp + + +def free_space(pos: chex.Array) -> chex.Array: + """Calculate free space loss + + Parameters + ---------- + pos: Array + An array of 2d positions for `n` points + + Returns + ------- + Transmission loss for every pair of points in `pos`. + + """ + npoints = pos.shape[0] + + return jnp.zeros((npoints, npoints)) From 28f3d6cbb75a3e360b1eceb7b8fa63c0877f3709 Mon Sep 17 00:00:00 2001 From: Maksymilian Wojnar <38166640+m-wojnar@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:55:41 +0200 Subject: [PATCH 3/4] Update dependencies --- pyproject.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d100208..36c9c0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,11 +17,11 @@ authors = [ requires-python = ">=3.9" dependencies = [ - "chex~=0.1.85", - "jax~=0.4.23", - "jaxlib~=0.4.23", - "matplotlib~=3.8.2", - "tensorflow-probability[jax]~=0.23.0" + "chex~=0.1.86", + "jax~=0.4.30", + "jaxlib~=0.4.30", + "matplotlib~=3.9.1", + "tensorflow-probability[jax]~=0.24.0" ] [build-system] From 6fd9577af52e3c3fc2a9cc06e0d1d94436e1670a Mon Sep 17 00:00:00 2001 From: Krzysztof Rusek Date: Mon, 15 Jul 2024 17:05:00 +0200 Subject: [PATCH 4/4] Try to fix ci --- .github/workflows/github-actions.yml | 2 +- .github/workflows/publish_documentation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 7977914..0e8b5b8 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: 'pip' diff --git a/.github/workflows/publish_documentation.yml b/.github/workflows/publish_documentation.yml index d1d0d26..11dc621 100644 --- a/.github/workflows/publish_documentation.yml +++ b/.github/workflows/publish_documentation.yml @@ -15,7 +15,7 @@ jobs: persist-credentials: false - name: Set up Python 3.11 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.11