Skip to content

Add support for multidimensional metrics #844

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

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

kzscisoft
Copy link
Collaborator

Add Support for Tensor Metrics

Issue: #833

Python Version(s) Tested: 3.13

Operating System(s): Ubuntu 25.04

Documentation PR: Issue on Docs repo.

📝 Summary

Allows the user to define a grid and then log tensors as metrics (or multidimensional metrics) to that grid.

🔄 Changes

Low Level API

  • Creation of Grid class for defining a new grid:
grid = Grid.new(
    name="my_grid",
    grid=numpy.vstack([
        numpy.linspace(0, 10, 10),
        numpy.linspace(10, 20, 10)
    ]),
    labels=["x", "y"]
)
grid.assign_to_run(run_id)
  • Creation of GridMetrics class for logging metrics across multiple grids for a given run:
metrics = GridMetrics.new(
    run=run_id,
    metrics=[
        {
            "timestamp": datetime.datetime.now(datetime.timezone.utc).strftime(
                "%Y-%m-%dT%H:%M:%S.%f"
            ),
            "time": _time,
            "step": _step,
            "array": numpy.ones((10, 10)),
            "grid_identifier": _grid.id
        }
    ],
)

User API

For the user, log_metrics has been updated to allow numpy arrays as metric values, the user must firstly assign or create a grid for that metric:

run.assign_metric_to_grid(
    metric_name="A",
    grid_name="base_grid",
    axes_ticks=numpy.vstack([
        numpy.linspace(0, 10, 10),
        numpy.linspace(10, 20, 10)
    ]),
    axes_labels=["x", "y"]
)
run.log_metrics({"x": 2, "A": numpy.ones((10, 10))}

Note if the user does not specify axes_ticks and axes_labels it is assumed the grid already exists.

✔️ Checklist

  • Unit and integration tests passing.
  • Pre-commit hooks passing.
  • Quality checks passing.
  • Updated the documentation.

@kzscisoft kzscisoft added this to the Python API v2.2 milestone Aug 18, 2025
@kzscisoft kzscisoft added the enhancement New feature or request label Aug 18, 2025
@kzscisoft kzscisoft linked an issue Aug 18, 2025 that may be closed by this pull request
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.

Add Support for Multidimensional Metrics
2 participants