Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.3.1 #109

Merged
merged 12 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ jobs:
- name: Test with pytest
run: |
pip install pytest
pytest --ignore-glob=*_figures.py
pytest --ignore-glob=*_figures.py --ignore-glob=*_benchmark.py

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ checkpoints/
lightning_logs/
*.pt
*.jpg
*.benchmarks/
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime

ENV DEBIAN_FRONTEND=noninteractive

ADD torchsig/ /build/torchsig

ADD pyproject.toml /build/pyproject.toml

RUN pip3 install /build

RUN pip3 install notebook

WORKDIR /workspace/code

ADD examples/ /workspace/code/examples
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<p align="center">
<img src="docs/logo.png" alt="drawing" width="500"/>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/torchsig_logo_white_dodgerblue.png">
<img src="docs/logo.png" width="500">
</picture>
</p>

-----
Expand Down Expand Up @@ -40,6 +43,17 @@ cd torchsig
pip install .
```

## Using the Dockerfile
If you have Docker installed along with compatible GPUs and drivers, you can try:

```
docker build -t torchsig -f Dockerfile .
docker run -d --rm --network=host --shm-size=32g --gpus all --name torchsig_workspace torchsig tail -f /dev/null
docker exec torchsig_workspace jupyter notebook --allow-root --ip=0.0.0.0 --no-browser
```

Then use the URL in the output in your browser to run the examples and notebooks.

## License
---
TorchSig is released under the MIT License. The MIT license is a popular open-source software license enabling free use, redistribution, and modifications, even for commercial purposes, provided the license is included in all copies or substantial portions of the software. TorchSig has no connection to MIT, other than through the use of this license.
Expand Down
Binary file added docs/torchsig_logo_white_dodgerblue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
requires-python = ">=3.7"
license = {text = "MIT"}
dependencies = [
"torch==1.13.0",
"torch==1.13.1",
"torchvision",
"tqdm",
"numpy",
Expand Down
69 changes: 69 additions & 0 deletions tests/test_modulation_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from torchsig.datasets.synthetic import (
ConstellationDataset,
FSKDataset,
OFDMDataset,
default_const_map,
freq_map,
)
from matplotlib import pyplot as plt
import numpy as np
import pytest


def iterate_one_epoch(dataset):
for _ in dataset:
pass


@pytest.mark.benchmark(group="constellation")
@pytest.mark.parametrize("modulation_name", default_const_map.keys())
def test_generate_constellation_benchmark(benchmark, modulation_name):
dataset = ConstellationDataset(
[modulation_name],
num_iq_samples=4096,
num_samples_per_class=100,
iq_samples_per_symbol=2,
pulse_shape_filter=None,
random_pulse_shaping=False,
random_data=False,
use_gpu=False,
)
benchmark(iterate_one_epoch, dataset)


@pytest.mark.benchmark(group="fsk")
@pytest.mark.parametrize("modulation_name", freq_map.keys())
def test_generate_fsk_benchmark(benchmark, modulation_name):
dataset = FSKDataset(
[modulation_name],
num_iq_samples=4096,
num_samples_per_class=100,
iq_samples_per_symbol=2,
random_pulse_shaping=False,
random_data=False,
use_gpu=False,
)
benchmark(iterate_one_epoch, dataset)


num_subcarriers = (64, 72, 128, 180, 256, 300, 512, 600, 900, 1024, 1200, 2048)


@pytest.mark.benchmark(group="ofdm")
@pytest.mark.parametrize("num_subcarriers", num_subcarriers)
def test_generate_ofdm_benchmark(benchmark, num_subcarriers):
constellations = ("bpsk", "qpsk", "16qam", "64qam", "256qam", "1024qam")
sidelobe_suppression_methods = ("lpf", "win_start")
dataset = OFDMDataset(
constellations,
num_subcarriers=(num_subcarriers,),
num_iq_samples=4096,
num_samples_per_class=100,
sidelobe_suppression_methods=sidelobe_suppression_methods,
use_gpu=False,
)
benchmark(iterate_one_epoch, dataset)


if __name__ == "__main__":
pytest.main()
121 changes: 121 additions & 0 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
from unittest import TestCase
from torchsig.transforms.system_impairment.si import RandomTimeShift, TimeCrop
import numpy as np


class RandomTimeShiftTestCase(TestCase):
def test_random_time_shift_right(self):
rng = np.random.RandomState(0)
data = (
rng.rand(
16,
)
- 0.5
) + 1j * (
rng.rand(
16,
)
- 0.5
)
shift = 5
t = RandomTimeShift(
shift=shift,
)
new_data = t(data)
self.assertTrue(np.allclose(data[:-shift], new_data[shift:]))
self.assertTrue(np.allclose(new_data[:shift], np.zeros(shift)))

def test_random_time_shift_left(self):
rng = np.random.RandomState(0)
data = (
rng.rand(
16,
)
- 0.5
) + 1j * (
rng.rand(
16,
)
- 0.5
)
shift = -5
t = RandomTimeShift(
shift=shift,
)
new_data = t(data)
self.assertTrue(np.allclose(data[-shift:], new_data[:shift]))
self.assertTrue(np.allclose(new_data[shift:], np.zeros(np.abs(shift))))


class TimeCropTestCase(TestCase):
def test_time_crop_start(self):
rng = np.random.RandomState(0)
num_iq_samples = 16
data = (
rng.rand(
num_iq_samples,
)
- 0.5
) + 1j * (
rng.rand(
num_iq_samples,
)
- 0.5
)
length = 4
t = TimeCrop(
crop_type="start",
length=length,
)
new_data: np.ndarray = t(data)
self.assertTrue(np.allclose(data[:length], new_data))
self.assertTrue(new_data.shape[0] == length)

def test_time_crop_center(self):
rng = np.random.RandomState(0)
num_iq_samples = 16
data = (
rng.rand(
num_iq_samples,
)
- 0.5
) + 1j * (
rng.rand(
num_iq_samples,
)
- 0.5
)
length = 4
t = TimeCrop(
crop_type="center",
length=length,
)
new_data: np.ndarray = t(data)
extra_samples = num_iq_samples - length
self.assertTrue(
np.allclose(data[extra_samples // 2 : -extra_samples // 2], new_data)
)
self.assertTrue(new_data.shape[0] == length)

def test_time_crop_end(self):
rng = np.random.RandomState(0)
num_iq_samples = 16
data = (
rng.rand(
num_iq_samples,
)
- 0.5
) + 1j * (
rng.rand(
num_iq_samples,
)
- 0.5
)
length = 4
t = TimeCrop(
crop_type="end",
length=length,
)
new_data: np.ndarray = t(data)
self.assertTrue(np.allclose(data[-length:], new_data))
self.assertTrue(new_data.shape[0] == length)
2 changes: 1 addition & 1 deletion torchsig/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.0"
__version__ = "0.3.1"
Loading