diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 759dc57..9d73598 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -11,11 +11,11 @@ jobs: build-and-deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v5 with: - python-version: "3.7" + python-version: "3.11" - name: Install livelossplot with dependencies run: | pip install -e . diff --git a/.github/workflows/external_packages.yml b/.github/workflows/external_packages.yml index 30ceec0..4766d1e 100644 --- a/.github/workflows/external_packages.yml +++ b/.github/workflows/external_packages.yml @@ -14,11 +14,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v5 with: - python-version: "3.7" + python-version: "3.11" - name: Install package and dev dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/flake8_yapf.yml b/.github/workflows/flake8_yapf.yml index 5deec54..293f289 100644 --- a/.github/workflows/flake8_yapf.yml +++ b/.github/workflows/flake8_yapf.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v5 with: - python-version: "3.7" + python-version: "3.11" - name: Install dependencies run: | pip install flake8 diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 8607b34..c2a82c1 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -15,12 +15,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/examples/neptune.py b/examples/neptune.py index 3ac9a1f..3b410d5 100644 --- a/examples/neptune.py +++ b/examples/neptune.py @@ -1,5 +1,5 @@ # TO START: -# pip install neptune-client, livelossplot +# pip install neptune, livelossplot # export environment variables # enjoy results @@ -13,22 +13,26 @@ def main(): - api_token = os.environ.get('NEPTUNE_API_TOKEN') - project_qualified_name = os.environ.get('NEPTUNE_PROJECT_NAME') - logger = NeptuneLogger(api_token=api_token, project_qualified_name=project_qualified_name) + api_token = os.environ.get("NEPTUNE_API_TOKEN") + project_qualified_name = os.environ.get("NEPTUNE_PROJECT") + logger = NeptuneLogger( + api_token=api_token, + project_qualified_name=project_qualified_name, + tags=["example", "livelossplot"], + ) liveplot = PlotLosses(outputs=[logger]) for i in range(20): liveplot.update( { - 'accuracy': 1 - np.random.rand() / (i + 2.), - 'val_accuracy': 1 - np.random.rand() / (i + 0.5), - 'mse': 1. / (i + 2.), - 'val_mse': 1. / (i + 0.5) + "accuracy": 1 - np.random.rand() / (i + 2.0), + "val_accuracy": 1 - np.random.rand() / (i + 0.5), + "mse": 1.0 / (i + 2.0), + "val_mse": 1.0 / (i + 0.5), } ) liveplot.send() - sleep(.5) + sleep(0.5) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/livelossplot/outputs/neptune_logger.py b/livelossplot/outputs/neptune_logger.py index 06b30b8..ce92dea 100644 --- a/livelossplot/outputs/neptune_logger.py +++ b/livelossplot/outputs/neptune_logger.py @@ -15,16 +15,17 @@ def __init__(self, api_token: Optional[str] = None, project_qualified_name: Opti **kwargs: keyword args, that will be passed to create_experiment function """ import neptune + self.neptune = neptune - self.neptune.init(api_token=api_token, project_qualified_name=project_qualified_name) - self.experiment = self.neptune.create_experiment(**kwargs) + self.run = self.neptune.init_run(api_token=api_token, project=project_qualified_name, **kwargs) def close(self): """Close connection""" - self.neptune.stop() + if hasattr(self, "run"): + self.run.stop() def send(self, logger: MainLogger): """Send metrics collected in last step to neptune server""" for name, log_items in logger.log_history.items(): last_log_item = log_items[-1] - self.neptune.send_metric(name, x=last_log_item.step, y=last_log_item.value) + self.run[name].append(value=last_log_item.value, step=last_log_item.step) diff --git a/livelossplot/plot_losses.py b/livelossplot/plot_losses.py index 86d5241..b87d48e 100644 --- a/livelossplot/plot_losses.py +++ b/livelossplot/plot_losses.py @@ -13,7 +13,6 @@ class PlotLosses: """ Class collect metrics from the training engine and send it to plugins, when send is called """ - def __init__( self, outputs: List[Union[Type[BO], str]] = ['MatplotlibPlot', 'ExtremaPrinter'], diff --git a/setup.py b/setup.py index c7ba1d5..0e435df 100644 --- a/setup.py +++ b/setup.py @@ -50,6 +50,8 @@ def version(): 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', ], packages=find_packages(), zip_safe=False diff --git a/tests/external_api_test_neptune.py b/tests/external_api_test_neptune.py index d75299f..bf5e3af 100644 --- a/tests/external_api_test_neptune.py +++ b/tests/external_api_test_neptune.py @@ -8,31 +8,31 @@ def test_neptune(): neptune_logger = NeptuneLogger( - api_token="ANONYMOUS", project_qualified_name="shared/colab-test-run", tags=['livelossplot', 'github-actions'] + api_token="ANONYMOUS", + project_qualified_name="shared/colab-test-run", + tags=["livelossplot", "github-actions"], ) plotlosses = PlotLosses(outputs=[neptune_logger]) - assert neptune_logger.experiment.state == 'running' + assert neptune_logger.run.exists for i in range(3): plotlosses.update( { - 'acc': 1 - np.random.rand() / (i + 2.), - 'val_acc': 1 - np.random.rand() / (i + 0.5), - 'loss': 1. / (i + 2.), - 'val_loss': 1. / (i + 0.5) + "acc": 1 - np.random.rand() / (i + 2.0), + "val_acc": 1 - np.random.rand() / (i + 0.5), + "loss": 1.0 / (i + 2.0), + "val_loss": 1.0 / (i + 0.5), } ) plotlosses.send() - assert neptune_logger.experiment.state == 'running' + assert neptune_logger.run.exists neptune_logger.close() - # This is not working anymore. - # assert neptune_logger.experiment.state == 'succeeded' - - url = neptune.project._get_experiment_link(neptune_logger.experiment) + # Get the run URL + url = neptune_logger.run.get_url() assert len(url) > 0