-
Notifications
You must be signed in to change notification settings - Fork 612
Cleanup function spec, plus adding a few functionals #1457
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
loliverhennigh
wants to merge
15
commits into
NVIDIA:main
Choose a base branch
from
loliverhennigh:split-functional-arch-interp-spec-bench
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+14,264
−2,445
Open
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a1183b8
Refactor functional architecture, interpolation, specs, and benchmarks
loliverhennigh cc83d37
Sync benchmark/docs/function-spec cleanups from fea branch
loliverhennigh 8b63ddb
Refactor functional structure and restore interpolation/geometry updates
loliverhennigh eedb2d2
most recent
loliverhennigh 6c24bf4
updating docs
loliverhennigh b7ddbb0
Refactor functional structure, interpolation kernels, and tests
loliverhennigh 9e192ab
Refine functional tests and add geometry/interpolation assets
loliverhennigh 0d4a4e1
Set warp default for grid-to-point and align compare hooks
loliverhennigh 6fb0c27
Align functional test conventions and radius backward inputs
loliverhennigh 2e42c45
Add functional visualization generation scripts
loliverhennigh f2777cb
Merge upstream/main into split-functional-arch-interp-spec-bench
loliverhennigh 0264dcf
sdf
loliverhennigh ed2a0c3
Standardize geometry functional tests with parameterized error cases
loliverhennigh 9337850
Apply pre-commit cleanup and header fixes
loliverhennigh c4dd8bf
Merge remote-tracking branch 'upstream/main' into split-functional-ar…
loliverhennigh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 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. | ||
|
|
||
| """Shared helpers for functional ASV benchmark scripts.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| import torch | ||
|
|
||
| from physicsnemo.core.function_spec import FunctionSpec | ||
|
|
||
| PHASE_ORDER = ("forward", "backward") | ||
|
|
||
|
|
||
| def supports_backward_inputs(spec: type) -> bool: | ||
| """Return True when a spec overrides backward input generation.""" | ||
|
|
||
| return spec.make_inputs_backward.__func__ is not FunctionSpec.make_inputs_backward | ||
|
|
||
|
|
||
| def _metadata_case_labels(spec: type) -> list[str]: | ||
| """Return benchmark case labels from optional spec metadata.""" | ||
|
|
||
| benchmark_cases = getattr(spec, "_BENCHMARK_CASES", None) | ||
| if isinstance(benchmark_cases, (list, tuple)): | ||
| labels = [ | ||
| case[0] | ||
| for case in benchmark_cases | ||
| if isinstance(case, tuple) and case and isinstance(case[0], str) | ||
| ] | ||
| if labels: | ||
| return labels | ||
|
|
||
| benchmark_cases_fn = getattr(spec, "_benchmark_cases", None) | ||
| if callable(benchmark_cases_fn): | ||
| labels = [ | ||
| case[0] | ||
| for case in benchmark_cases_fn() | ||
| if isinstance(case, tuple) and case and isinstance(case[0], str) | ||
| ] | ||
| if labels: | ||
| return labels | ||
|
|
||
| return [] | ||
|
|
||
|
|
||
| def case_labels(spec: type, phase: str, device: torch.device | str) -> list[str]: | ||
| """Resolve labeled benchmark cases for one phase.""" | ||
|
|
||
| if phase not in PHASE_ORDER: | ||
| raise ValueError(f"Unsupported benchmark phase: {phase}") | ||
| if phase == "backward" and not supports_backward_inputs(spec): | ||
| return [] | ||
|
|
||
| labels = _metadata_case_labels(spec) | ||
| if labels: | ||
| return labels | ||
|
|
||
| if phase == "forward": | ||
| return [label for label, _, _ in spec.make_inputs_forward(device=device)] | ||
| return [label for label, _, _ in spec.make_inputs_backward(device=device)] | ||
|
|
||
|
|
||
| def case_by_index( | ||
| spec: type, | ||
| phase: str, | ||
| case_index: int, | ||
| device: torch.device | str, | ||
| ) -> tuple[str, tuple[Any, ...], dict[str, Any]]: | ||
| """Materialize one case from the phase-specific input generator.""" | ||
|
|
||
| if phase == "forward": | ||
| case_iter = spec.make_inputs_forward(device=device) | ||
| elif phase == "backward": | ||
| case_iter = spec.make_inputs_backward(device=device) | ||
| else: | ||
| raise ValueError(f"Unsupported benchmark phase: {phase}") | ||
|
|
||
| for index, case in enumerate(case_iter): | ||
| if index == case_index: | ||
| return case | ||
| raise IndexError( | ||
| f"Case index {case_index} out of range for {spec.__name__} phase={phase}" | ||
| ) | ||
|
|
||
|
|
||
| __all__ = ["PHASE_ORDER", "supports_backward_inputs", "case_labels", "case_by_index"] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code in the benchmarks is still a bit junky.