From db046e95b7427a5610e5176b52a2e362d1515a4a Mon Sep 17 00:00:00 2001 From: Piotr Migdal Date: Fri, 3 Jan 2025 14:40:02 +0100 Subject: [PATCH 1/6] fix build versions --- .github/workflows/docs.yml | 8 ++++---- .github/workflows/external_packages.yml | 6 +++--- .github/workflows/flake8_yapf.yml | 8 ++++---- .github/workflows/pythonpackage.yml | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) 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 From 4adfb95f7fe91d3516533b638e7d04426bf6bcb5 Mon Sep 17 00:00:00 2001 From: Piotr Migdal Date: Fri, 3 Jan 2025 14:46:23 +0100 Subject: [PATCH 2/6] fix for yapf --- livelossplot/plot_losses.py | 1 - 1 file changed, 1 deletion(-) 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'], From 110bc8b09086092523b44f8068031dcac7f3034e Mon Sep 17 00:00:00 2001 From: Piotr Migdal Date: Fri, 3 Jan 2025 15:01:47 +0100 Subject: [PATCH 3/6] neptune integration update --- examples/neptune.py | 24 ++++++++++++++---------- livelossplot/outputs/neptune_logger.py | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 15 deletions(-) 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..77d66a9 100644 --- a/livelossplot/outputs/neptune_logger.py +++ b/livelossplot/outputs/neptune_logger.py @@ -7,7 +7,13 @@ class NeptuneLogger(BaseOutput): """See: https://github.com/neptune-ai/neptune-client YOUR_API_TOKEN and USERNAME/PROJECT_NAME """ - def __init__(self, api_token: Optional[str] = None, project_qualified_name: Optional[str] = None, **kwargs): + + def __init__( + self, + api_token: Optional[str] = None, + project_qualified_name: Optional[str] = None, + **kwargs + ): """Set secrets and create experiment Args: api_token: your api token, you can create NEPTUNE_API_TOKEN environment variable instead @@ -15,16 +21,19 @@ 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) From 370a96cadb252a034d579dd0e93bdd4145b857b2 Mon Sep 17 00:00:00 2001 From: Piotr Migdal Date: Fri, 3 Jan 2025 15:07:13 +0100 Subject: [PATCH 4/6] neptune yapf fix --- livelossplot/outputs/neptune_logger.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/livelossplot/outputs/neptune_logger.py b/livelossplot/outputs/neptune_logger.py index 77d66a9..ce92dea 100644 --- a/livelossplot/outputs/neptune_logger.py +++ b/livelossplot/outputs/neptune_logger.py @@ -7,13 +7,7 @@ class NeptuneLogger(BaseOutput): """See: https://github.com/neptune-ai/neptune-client YOUR_API_TOKEN and USERNAME/PROJECT_NAME """ - - def __init__( - self, - api_token: Optional[str] = None, - project_qualified_name: Optional[str] = None, - **kwargs - ): + def __init__(self, api_token: Optional[str] = None, project_qualified_name: Optional[str] = None, **kwargs): """Set secrets and create experiment Args: api_token: your api token, you can create NEPTUNE_API_TOKEN environment variable instead @@ -23,9 +17,7 @@ def __init__( import neptune self.neptune = neptune - self.run = self.neptune.init_run( - api_token=api_token, project=project_qualified_name, **kwargs - ) + self.run = self.neptune.init_run(api_token=api_token, project=project_qualified_name, **kwargs) def close(self): """Close connection""" From 1e7f1eae79146c051ad405203b788f432c04d9d3 Mon Sep 17 00:00:00 2001 From: Piotr Migdal Date: Fri, 3 Jan 2025 15:10:03 +0100 Subject: [PATCH 5/6] neptune test fix --- tests/external_api_test_neptune.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 From 288ff6ff5de5fd4646901adb5e28c8c0969f5117 Mon Sep 17 00:00:00 2001 From: Piotr Migdal Date: Fri, 3 Jan 2025 15:14:47 +0100 Subject: [PATCH 6/6] version notes --- setup.py | 2 ++ 1 file changed, 2 insertions(+) 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