Skip to content

Commit

Permalink
Pass folder path to initialize Tensorboard object (#86)
Browse files Browse the repository at this point in the history
* Pass folder path to initialize Tensorboard object

* Add tensorboard unit test

* Minor style and import fix

* Add codecov token for reliability

Co-authored-by: William Fondrie <[email protected]>
  • Loading branch information
melihyilmaz and wfondrie authored Oct 26, 2022
1 parent 38af61a commit a5c05b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ jobs:
- name: Upload coverage to codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
12 changes: 8 additions & 4 deletions casanovo/denovo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import pytorch_lightning as pl
import torch
from torch.utils.tensorboard import SummaryWriter
from depthcharge.components import ModelMixin, PeptideDecoder, SpectrumEncoder

from . import evaluate
Expand Down Expand Up @@ -63,9 +64,9 @@ class Spec2Pep(pl.LightningModule, ModelMixin):
fit the specified isotope error: `abs(calc_mz - (precursor_mz - isotope * 1.00335 / precursor_charge)) < precursor_mass_tol`
n_log : int
The number of epochs to wait between logging messages.
tb_summarywriter: Optional[torch.utils.tensorboard.SummaryWriter]
Object to record performance metrics during training. If ``None``, don't
use a ``SummarWriter``.
tb_summarywriter: Optional[str]
Folder path to record performance metrics during training. If ``None``, don't
use a ``SummaryWriter``.
warmup_iters: int
The number of warm up iterations for the learning rate scheduler.
max_iters: int
Expand Down Expand Up @@ -142,7 +143,10 @@ def __init__(
# Logging.
self.n_log = n_log
self._history = []
self.tb_summarywriter = tb_summarywriter
if tb_summarywriter is not None:
self.tb_summarywriter = SummaryWriter(tb_summarywriter)
else:
self.tb_summarywriter = tb_summarywriter

# Output writer during predicting.
self.out_writer = out_writer
Expand Down
12 changes: 12 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
"""Test that setuptools-scm is working correctly"""
import casanovo
from casanovo.denovo.model import Spec2Pep


def test_version():
"""Check that the version is not None"""
assert casanovo.__version__ is not None


def test_tensorboard():
"""Check that the version is not None"""
model = Spec2Pep(
tb_summarywriter="test_path",
)
assert model.tb_summarywriter is not None

model = Spec2Pep()
assert model.tb_summarywriter is None

0 comments on commit a5c05b8

Please sign in to comment.