Skip to content

Fixes for test collection and guards for missing PhysicsNeMo-Sym #902

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 7 commits into
base: main
Choose a base branch
from
28 changes: 22 additions & 6 deletions docs/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import os
# SPDX-FileCopyrightText: Copyright (c) 2023 - 2024 NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path
import subprocess

import pytest

# Collecting all the Python files in the scripts directory
script_files = [f for f in os.listdir("test_scripts/") if f.endswith(".py")]
test_scripts_dir = Path(__file__).parent / "test_scripts"
script_files = [f for f in test_scripts_dir.glob("*.py")]


# print(script_files)
@pytest.mark.parametrize("script_file", script_files)
def test_script_execution(script_file):
"""Test if a script runs without error."""
filepath = os.path.join("test_scripts/", script_file)
print(filepath)
result = subprocess.run(["python", filepath], capture_output=True, text=True)
print(f"Running {script_file}")
result = subprocess.run(["python", script_file], capture_output=True, text=True)

# Check that the script executed successfully
assert (
Expand Down
15 changes: 9 additions & 6 deletions docs/test_scripts/test_custom_model_demo_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ class MdlsUNetMetaData(ModelMetaData):
# [physicsnemo model]

# [physicsnemo sym model]

from typing import Dict, Optional

from physicsnemo.sym.key import Key
from physicsnemo.sym.models.arch import Arch
try:
from physicsnemo.sym.key import Key
from physicsnemo.sym.models.arch import Arch
except ImportError as e:
raise ImportError(
"This optional test depends on the `physicsnemo.sym` package.\n"
"If desired, you can install it with instructions from https://github.com/NVIDIA/physicsnemo-sym."
) from e


class MdlsSymUNet(Arch):
Expand All @@ -91,7 +94,7 @@ def __init__(

self.mdls_model = MdlsUNet(in_channels, out_channels) # MdlsUNet defined above

def forward(self, dict_tensor: Dict[str, torch.Tensor]):
def forward(self, dict_tensor: dict[str, torch.Tensor]):
x = self.concat_input(
dict_tensor,
self.input_key_dict,
Expand Down