diff --git a/.github/workflows/run_E2E_tests.yml b/.github/workflows/run_E2E_tests.yml index 37c2c40..340fa1c 100644 --- a/.github/workflows/run_E2E_tests.yml +++ b/.github/workflows/run_E2E_tests.yml @@ -9,9 +9,11 @@ on: pull_request: branches: [ "main" ] -jobs: - build: +permissions: + contents: read +jobs: + non-cuda-tests: runs-on: ubuntu-latest strategy: fail-fast: false @@ -38,9 +40,38 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest + - name: Test non-CUDA with pytest + run: | + pytest -s --cov=pinballrt --cov-report xml --cov-report term -k "not cuda" + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + cuda-tests: + runs-on: machine/id=${{ github.run_id }}/gpu=t4/tenancy=spot + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11", "3.12", "3.13"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + python -m pip install -e .[train] + + - name: Test CUDA with pytest run: | - pytest -s --cov=pinballrt --cov-report xml --cov-report term + pytest -s --cov=pinballrt --cov-report xml --cov-report term -k "cuda" - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5 diff --git a/pinballrt/dust.py b/pinballrt/dust.py index 9e99cac..b55e6d3 100644 --- a/pinballrt/dust.py +++ b/pinballrt/dust.py @@ -1544,6 +1544,14 @@ def __init__(self, lam=None, kabs=None, ksca=None, scattering_phase_function=Non def to_device(self, device): super().to_device(device) + for model in ["scattering_phase_function","random_direction"]: + if hasattr(self, f"{model}_model"): + getattr(self, f"{model}_model").to(device) + if hasattr(self, f"{model}_x_scaler"): + getattr(self, f"{model}_x_scaler").to(device) + if hasattr(self, f"{model}_y_scaler"): + getattr(self, f"{model}_y_scaler").to(device) + def scatter(self, photon_list, iphotons): nphotons = iphotons.size(0) diff --git a/pinballrt/tests/test_E2E.py b/pinballrt/tests/test_E2E.py index 17f5aea..addfe78 100644 --- a/pinballrt/tests/test_E2E.py +++ b/pinballrt/tests/test_E2E.py @@ -93,7 +93,7 @@ def test_E2E(grid_class, grid_kwargs, dust, percentile, device, return_vals=Fals # Load the comparison data. temperature = np.load(os.path.join(os.path.dirname(__file__), f"data/{grid_class.__name__}_E2E_temperature.npz"))['temperature'] Q = calculate_Qvalue(temperature, model.grid.grid.temperature.numpy(), percentile=99.0) - assert Q < 1.045, f"Temperature difference exceeds tolerance: {Q}" + assert Q < 1.046, f"Temperature difference exceeds tolerance: {Q}" scattering = np.load(os.path.join(os.path.dirname(__file__), f"data/{grid_class.__name__}_E2E_scattering.npz"))['scattering'] Q = calculate_Qvalue(scattering, model.grid.scattering.cpu().numpy(), percentile=percentile, clip=0.1)