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

add Filtration Curve for visualization #38

Merged
merged 15 commits into from
Aug 1, 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
run: poetry install

- name: "Run benchmark"
run: poetry run pytest test/test_benchmark.py --benchmark-json output.json
run: poetry run pytest test/test_benchmark.py -k 200_500 --benchmark-json output.json

- name: Download previous benchmark data
uses: actions/cache@v1
Expand Down
30 changes: 30 additions & 0 deletions benchmark/profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import torch
from torch.profiler import profile, record_function, ProfilerActivity
import isn_tractor.ibisn as it
from benchmark import continuous

df = continuous(500, 1500)

with profile(
activities=[ProfilerActivity.CPU],
record_shapes=True,
profile_memory=True,
with_stack=True,
) as prof:
for isn in it.dense_isn(df):
del isn

print(
prof.key_averages(group_by_input_shape=True).table(
sort_by="cpu_time_total", row_limit=25
)
)
print(
prof.key_averages(group_by_input_shape=True).table(
sort_by="cpu_memory_usage", row_limit=25
)
)

prof.export_chrome_trace("profiling_trace.json")

prof.export_stacks("profiler_stacks.txt", "self_cpu_time_total")
184 changes: 3 additions & 181 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ numpy = "^1.24.1"
scipy = "^1.10.0"
scikit-learn = "^1.2.0"
torch = {version = "^2.0.1+cu118", source = "torch"}
sympy = "^1.12"


[tool.poetry.group.dev.dependencies]
Expand All @@ -33,6 +34,10 @@ pytest-benchmark = "^4.0.0"
pyperf = "^2.6.0"



[tool.poetry.group.visualization.dependencies]
networkx = "^3.1"

[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cu118"
Expand Down
167 changes: 99 additions & 68 deletions test/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ def mapped_info(df):
n_rows = len(df.columns)

# Generate random values for each column
chrs = np.repeat(np.arange(1, n_chromosomes + 1), n_rows // n_chromosomes + 1)[
:n_rows
]
starts = np.arange(1, n_rows * 10000 + 1, 10000)
stops = starts + 9

Expand Down Expand Up @@ -83,189 +80,223 @@ def continuous(n_individuals: int, m_genes: int) -> DataFrame:
)


"""
def compute_dense_isn(data, device):
for isn in dense_isn(data, device=t.device("cuda")):
def compute_dense_isn(data, device=None):
for isn in dense_isn(data, device=device):
del isn


@pytest.mark.benchmark
def test_dense_200_1000(benchmark):
def test_dense_200_500_cpu(benchmark):
data = continuous(200, 500)
benchmark(compute_dense_isn, data)


@pytest.mark.benchmark
def test_dense_200_1000_cuda(benchmark):
data = continuous(200, 1000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_200_2000(benchmark):
def test_dense_200_2000_cuda(benchmark):
data = continuous(200, 2000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_200_3000(benchmark):
def test_dense_200_3000_cuda(benchmark):
data = continuous(200, 3000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_500_1000(benchmark):
def test_dense_500_1000_cuda(benchmark):
data = continuous(500, 1000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_500_2000(benchmark):
def test_dense_500_2000_cuda(benchmark):
data = continuous(500, 2000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_500_3000(benchmark):
def test_dense_500_3000_cuda(benchmark):
data = continuous(500, 3000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_1000_1000(benchmark):
def test_dense_1000_1000_cuda(benchmark):
data = continuous(1000, 1000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_1000_2000(benchmark):
def test_dense_1000_2000_cuda(benchmark):
data = continuous(1000, 2000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_1000_3000(benchmark):
def test_dense_1000_3000_cuda(benchmark):
data = continuous(1000, 3000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_2000_1000(benchmark):
def test_dense_2000_1000_cuda(benchmark):
data = continuous(2000, 1000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_2000_2000(benchmark):
def test_dense_2000_2000_cuda(benchmark):
data = continuous(2000, 2000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_2000_3000(benchmark):
def test_dense_2000_3000_cuda(benchmark):
data = continuous(2000, 3000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_2000_5000(benchmark):
def test_dense_2000_5000_cuda(benchmark):
data = continuous(2000, 5000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_2000_10000(benchmark):
def test_dense_2000_10000_cuda(benchmark):
data = continuous(2000, 10000)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,device), rounds=20, iterations=3)
"""
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


def compute_sparse_isn(
data, interact_unmapped, interact_mapped, metric="incremental_pearson", pool=None
data,
interact_unmapped,
interact_mapped,
metric="incremental_pearson",
pool=None,
device=None,
):
for isn in sparse_isn(
data,
interact_unmapped=interact_unmapped,
interact_mapped=interact_mapped,
metric=metric,
pool=pool,
device=device,
):
del isn

'''

@pytest.mark.benchmark
def test_sparse_200_500_cpu(benchmark):
data = continuous(200, 500)
interact = interactions(500)
benchmark(compute_sparse_isn, data, None, interact)


@pytest.mark.benchmark
def test_sparse_200_10000(benchmark):
def test_sparse_200_10000_cuda(benchmark):
data = continuous(200, 10000)
i_m = interactions(5000)
# device = t.device("cuda")
device = t.device("cuda")
benchmark.pedantic(
compute_sparse_isn,
args=(data, None, i_m, "incremental_pearson", None),
args=(data, None, i_m, "incremental_pearson", None, device),
rounds=20,
iterations=3,
)


@pytest.mark.benchmark
def test_sparse_500_10000(benchmark):
def test_sparse_500_10000_cuda(benchmark):
data = continuous(500, 10000)
i_m = interactions(5200)
# device = t.device("cuda")
device = t.device("cuda")
benchmark.pedantic(
compute_sparse_isn,
args=(data, None, i_m, "incremental_pearson", None),
args=(data, None, i_m, "incremental_pearson", None, device),
rounds=20,
iterations=3,
)


@pytest.mark.benchmark
def test_sparse_1000_10000(benchmark):
def test_sparse_1000_10000_cuda(benchmark):
data = continuous(1000, 10000)
i_m = interactions(7000)
# device = t.device("cuda")
device = t.device("cuda")
benchmark.pedantic(
compute_sparse_isn,
args=(data, None, i_m, "incremental_pearson", None),
args=(data, None, i_m, "incremental_pearson", None, device),
rounds=20,
iterations=3,
)
'''


@pytest.mark.benchmark
def test_sparse_2000_10000(benchmark):
def test_sparse_2000_10000_cuda(benchmark):
data = continuous(2000, 10000)
i_m = interactions(8000)
# device = t.device("cuda")
device = t.device("cuda")
benchmark.pedantic(
compute_sparse_isn,
args=(data, None, i_m, "incremental_pearson", None),
args=(data, None, i_m, "incremental_pearson", None, device),
rounds=20,
iterations=3,
)



"""
@pytest.mark.benchmark
def test_dense_200_10000(benchmark):
def test_dense_200_10000_cuda(benchmark):
data = continuous(200, 10000)
#device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,), rounds=20, iterations=3)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_500_5000(benchmark):
def test_dense_500_5000_cuda(benchmark):
data = continuous(500, 5000)
#device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,), rounds=20, iterations=3)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_500_10000(benchmark):
def test_dense_500_10000_cuda(benchmark):
data = continuous(500, 10000)
#device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,), rounds=20, iterations=3)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_1000_5000(benchmark):
def test_dense_1000_5000_cuda(benchmark):
data = continuous(1000, 5000)
#device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,), rounds=20, iterations=3)
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)


@pytest.mark.benchmark
def test_dense_1000_10000(benchmark):
def test_dense_1000_10000_cuda(benchmark):
data = continuous(1000, 10000)
#device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data,), rounds=20, iterations=3)
"""
device = t.device("cuda")
benchmark.pedantic(compute_dense_isn, args=(data, device), rounds=20, iterations=3)
5 changes: 5 additions & 0 deletions visualisation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Run with:

```shell
poetry run python ./visualisation/filtration_curve.py ./visualisation/expression.csv ./visualisation/answer.csv ./visualisation/plot.png
```
Loading