Skip to content

Commit

Permalink
re-organize tests and added toml as testing/dev dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Guest400123064 committed Feb 4, 2025
1 parent 064b0ac commit d0f956a
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 106 deletions.
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ coverage = {extras = ["toml"], version = "^7.6.1"}
mypy = "^1.11.2"
numba = "<0.59.0"
clifford = "^1.4.0"
toml = "^0.10.2"


[tool.poetry.group.docs.dependencies]
Expand Down
54 changes: 54 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ezgatr Tests README

## Overview

This directory contains test cases for the `ezgatr` library, ensuring that its components function correctly and as expected. Tests are organized to mirror the sub-module structure of the main package.

## Test Organization

- **Sub-module Specific Tests**: Tests for specific sub-modules (e.g., `ezgatr.nn`) reside within corresponding directories under `tests` (e.g., `tests.nn`).

- **Thematic Tests**: Tests covering specific themes that do not belong to any particular module are placed in the `tests/thematic` directory. For example, `tests.thematic.test_regress_with_clifford.py` ensures that the library's geometric algebra operations align with those of the `clifford` package.

## Configuration Management

To avoid hard-coding configurations and to maintain consistency across tests, configurations are centralized into dedicated files.

- **Core Configurations**: Shared configurations, such as execution devices, numerical precision tolerance, and test data generation parameters, are defined in `tests/config/core.toml`.

- **Module/Theme-Specific Configurations**: Configurations unique to specific sub-modules or themes are organized in respective files within the `tests/config` directory:
- `interfaces.toml`
- `thematic.toml`

## File Structure

```
tests/
├── __init__.py
├── conftest.py
├── utils.py
├── config/
│ ├── __init__.py
│ ├── core.toml
│ ├── interfaces.toml
│ └── thematic.toml
├── interfaces/
│ ├── __init__.py
│ ├── test_plane.py
│ ├── test_point.py
│ └── ...
├── nn/
│ ├── __init__.py
│ ├── test_functional.py
│ └── test_modules.py
└── thematic/
├── __init__.py
├── README.md
├── test_gradient_flow.py
├── test_operator_equivariance.py
└── test_regress_with_clifford.py
```

## Forward

This README provides an introduction to how tests and configurations are organized in the `tests` directory. Future updates will provide more detailed documentation as the test suite expands.
40 changes: 40 additions & 0 deletions tests/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from dataclasses import dataclass


@dataclass
class BasicConfig:
r"""Basic configurations shared across all tests.
Parameters
----------
rtol : float
Relative tolerance for ``torch.testing.assert_close``.
atol : float
Absolute tolerance for ``torch.testing.assert_close``.
equal_nan : bool
If ``True``, then two ``NaN`` s will be considered equal.
check_device : bool
If ``True``, check that ``input`` and ``other`` are on the same device.
check_dtype : bool
If ``True``, check that ``input`` and ``other`` have the same dtype.
device : str
The device on which tests are executed (e.g., 'cpu', 'cuda').
max_batch_size : int
Maximum number of sequences within a batch of multi-vectors when
generating random testing data points.
max_context_size : int
Maximum number of multi-vectors within a single sequence when generating
random testing data points.
max_channel_size : int
Maximum number of channels for each multi-vector within a sequence
when generating random testing data points.
"""
rtol: float
atol: float
equal_nan: bool
check_device: bool
check_dtype: bool
device: str
max_batch_size: int
max_context_size: int
max_channel_size: int
13 changes: 13 additions & 0 deletions tests/config/core.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Core Configurations for ezgatr Tests

execution_device = "cpu" # The device on which tests are executed (e.g., "cpu", "cuda")
numerical_precision = 1e-5 # The tolerance level for numerical precision in tests
rtol = 1e-5 # Relative tolerance for torch.testing.assert_close
atol = 1e-8 # Absolute tolerance for torch.testing.assert_close
equal_nan = true # If true, then two NaNs will be considered equal
check_device = false # If true, check that input and other are on the same device
check_dtype = true # If true, check that input and other have the same dtype
num_random_data_points = 100 # The number of random data points generated for tests
data_point_size = 256 # The size of each random data point

# Add additional core configurations as needed.
6 changes: 6 additions & 0 deletions tests/config/interfaces.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[geometric]
rotation_angles = [0.0, 0.7853981634, 1.5707963268] # 0, π/4, π/2
translation_mags = [0.0, 1.0, 5.0]
reflection_axes = ["x", "y", "z"]
rtol = 1e-4
atol = 1e-6
File renamed without changes.
Empty file added tests/config/nn.toml
Empty file.
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pathlib

import pytest
import toml

from tests.config import BasicConfig

DIR_TEST = pathlib.Path(".").resolve().parent


@pytest.fixture(scope="session")
def basic_config():
r"""Load basic configurations for tests.
This fixture reads the ``core.toml`` file and returns an instance of the `BasicConfig` dataclass
containing the configuration parameters.
Returns
-------
BasicConfig
An instance containing basic test configurations.
"""
with open(DIR_TEST / "config" / "core.toml") as f:
config_data = toml.load(f)
return BasicConfig(**config_data)
4 changes: 2 additions & 2 deletions tests/interfaces/test_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import torch
from hypothesis import given, settings

from ezgatr.interfaces.plane import encode_pga, decode_pga
from ezgatr.nn.functional import inner_product, geometric_product
from ezgatr.interfaces.plane import encode_pga
from ezgatr.nn.functional import geometric_product, inner_product
from tests.utils import make_random_3d_vectors, strategy_batch_dims


Expand Down
2 changes: 1 addition & 1 deletion tests/interfaces/test_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from hypothesis import given
from hypothesis.strategies import floats

from ezgatr.interfaces.point import encode_pga, decode_pga
from ezgatr.interfaces.point import decode_pga, encode_pga
from tests.utils import make_random_3d_vectors


Expand Down
Empty file added tests/nets/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions tests/thematic/test_regress_with_clifford.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from __future__ import annotations

import torch
import numpy as np
from hypothesis import given, settings

from ezgatr.nn.functional import (
equi_dual,
equi_join,
geometric_product,
outer_product,
)
Expand Down
99 changes: 0 additions & 99 deletions tests/utils.py

This file was deleted.

0 comments on commit d0f956a

Please sign in to comment.