Skip to content

Conversation

SAKURA-CAT
Copy link
Member

@SAKURA-CAT SAKURA-CAT commented Jun 7, 2025

Description

Allow users to set hardware monitoring frequency(greater than 5s), use case:

import swanlab
settings = swanlab.Settings(
    hardware_interval=5,
)

run = swanlab.init(settings=settings)

@SAKURA-CAT SAKURA-CAT requested review from Copilot and Zeyi-Lin June 7, 2025 08:40
@SAKURA-CAT SAKURA-CAT self-assigned this Jun 7, 2025
@SAKURA-CAT SAKURA-CAT requested a review from ShaohonChen June 7, 2025 08:41
@SAKURA-CAT SAKURA-CAT added the 💪 enhancement New feature or request label Jun 7, 2025
@SAKURA-CAT SAKURA-CAT marked this pull request as ready for review June 7, 2025 08:41
Copilot

This comment was marked as outdated.

@SAKURA-CAT SAKURA-CAT force-pushed the feat/hardware-interval branch 2 times, most recently from 0ff126d to 3d45c1c Compare June 7, 2025 08:43
@SAKURA-CAT SAKURA-CAT requested a review from Copilot June 7, 2025 08:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables users to configure the hardware monitoring interval (minimum 5 seconds) via the Settings object and integrates that value into the runtime monitor logic.

  • Added a new hardware_interval field to Settings with validation (integer ≥ 5 or None by default).
  • Updated MonitorCron in swanlab/data/run/helper.py to use the user-defined interval when sleeping.
  • Added unit tests for the new hardware_interval behavior in test_swanlab_settings.py.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/unit/test_swanlab_settings.py Added tests to verify default, too-small, and non-integer hardware_interval
swanlab/swanlab_settings.py Introduced hardware_interval: Optional[PositiveInt] with ge=5 validation
swanlab/data/run/helper.py Pulled hardware_interval from settings into MonitorCron and updated sleep_time logic
Comments suppressed due to low confidence (3)

test/unit/test_swanlab_settings.py:172

  • Add a positive test case to confirm that Settings(hardware_interval=5) (and other integers ≥ 5) is accepted without raising a ValidationError.
        with pytest.raises(ValidationError):

swanlab/data/run/helper.py:170

  • Include unit tests for MonitorCron.sleep_time to verify it returns the custom hardware_interval when set and falls back to the default timing logic otherwise.
        if self.monitor_interval is not None:

swanlab/swanlab_settings.py:16

  • The fallback except ImportError block only imports Annotated and Literal, so Optional will be undefined in Python <3.9 environments. Add Optional to the fallback import from typing_extensions as well.
from typing import Annotated, Literal, Optional  # Python 3.9+

@SAKURA-CAT SAKURA-CAT force-pushed the feat/hardware-interval branch from 3d45c1c to c21c705 Compare June 7, 2025 08:46
@SAKURA-CAT SAKURA-CAT merged commit 58aa9f2 into main Jun 7, 2025
5 checks passed
@SAKURA-CAT SAKURA-CAT deleted the feat/hardware-interval branch June 7, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants