Skip to content

Conversation

FedericoNegri
Copy link
Contributor

@FedericoNegri FedericoNegri commented Oct 14, 2025

Stop using the static _result_properties dict from PyDPF-Core and rather look up result location from the result info.

What's problematic: for operators not listed as available results, we fail to lookup the corresponding native location. That's the case for beam operators (like B_N, B_M1, etc.) that are sort of a wrapper around SMISC.

I've tried to make it explicit in _get_native_location, where I'm also throwing an exception if a result was not found, rather than ignoring it and then deliver wrong results (because averaging is misconfigured etc.).

@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.11%. Comparing base (d68421e) to head (68a8b53).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #918      +/-   ##
==========================================
- Coverage   85.16%   85.11%   -0.05%     
==========================================
  Files          52       52              
  Lines        5217     5220       +3     
==========================================
  Hits         4443     4443              
- Misses        774      777       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FedericoNegri FedericoNegri marked this pull request as ready for review October 14, 2025 11:14
assert field.component_count == 1
assert np.allclose(field.data, field_ref.data)
# the model does not contain structural temperature results
with pytest.raises(ValueError) as excinfo:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FedericoNegri so this test used to silently fail at finding the native location, and returned something wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the test was comparing trivial arrays, there's an internal bug report for that operator. But in general the logic before was resorting to some defaults in case of missing location. That resulted in hidden errors for results that weren't registered in the _result_properties dict.

"B_T1",
"B_T2",
]:
res = next((r for r in available_results if r.operator_name == "SMISC"), None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FedericoNegri so all SMISC results have the same native location then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's my understanding

if res is not None:
return res.native_location

raise ValueError(f"Result with base name '{base_name}' not found.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ValueError(f"Result with base name '{base_name}' not found.")
raise ValueError(f"Unknown native location for result with base name '{base_name}'.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either we make this check explicit here, or we move the check for existing result with base name somewhere above.
This function checks for the native location, not whether the result exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function checks for the native location, not whether the result exists.

I disagree, the function throws if it can't find the result, which is a prerequisite for querying its location.
Unknown native location would be an appropriate error message for a native location set to None.

we move the check for existing result with base name somewhere above

I've been thinking about this and considered having a function

def _get_available_result(
    available_results: list[AvailableResult], base_name: str
) -> AvailableResult:
    res = next((r for r in available_results if r.operator_name == base_name), None)

    # special case for beam results, which are extracted from SMISC
    if res is None and base_name in [
        "B_N",
        "B_M1",
        "B_M2",
        "B_MT",
        "B_SN",
        "B_EL",
        "B_T1",
        "B_T2",
    ]:
        res = next((r for r in available_results if r.operator_name == "SMISC"), None)

    if res is None:
        raise ValueError(f"Result with base name '{base_name}' is not available.")

    return res

but I think it would just be misleading. You come in with B_N (axial force) and it returns you an available result with physical name 'Elemental Summable Miscellaneous Data', no unit etc.

The proper fix is to have those beam results be listed as available results (that was discussed internally).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on the proper fix.
Let's call this a quick fix then.

# the model does not contain structural temperature results
with pytest.raises(ValueError) as excinfo:
_ = transient_simulation.structural_temperature(set_ids=[1])
assert "not found" in str(excinfo.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert "not found" in str(excinfo.value)
assert "Unknown native location" in str(excinfo.value)

create_operator_callable: Callable[[str], Operator],
average_per_body: bool,
):
res = _result_properties[base_name] if base_name in _result_properties else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also have a function here which redirects from B_N and whatnot to SMISC as you did, but does not handle getting the native location.
This way the handling of the native location remains the same, and you have a clear function which checks for availability of results and throws a precise error when it fails.

@FedericoNegri FedericoNegri merged commit 83ee36a into main Oct 15, 2025
62 of 63 checks passed
@FedericoNegri FedericoNegri deleted the feat/remove-res-prop branch October 15, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants