Skip to content

Physical property tweaking#201

Merged
ndaelman-hu merged 25 commits intodevelopfrom
physical-property-tweaking
Aug 12, 2025
Merged

Physical property tweaking#201
ndaelman-hu merged 25 commits intodevelopfrom
physical-property-tweaking

Conversation

@ndaelman-hu
Copy link
Collaborator

@ndaelman-hu ndaelman-hu commented Jul 13, 2025

As discussed, I broke off the modifications to PhysicalProperty in #197 (which was used to test plotting and mapping parser, as well as modifications to outputs) into its own PR.

This PR incrementally applies some modifications. If you disagree about any particular ones, mention the commit hash and we can see to cherry-pick it out. The rough order includes:

  • Removal of superfluous logic, e.g. connected to variables.
  • The integration of PhysicalContribution into PhysicalProperty. This aims to half the number of definitions for each property. There is a note for a follow-up PR, but we should consult Theodore here first.
  • Addition of sub_plots to manage aggregation of plots from contributions.
  • Cleaning of dependent sections + removal of unnecessary initializers.
  • Update of tests.

@EBB2675 I would add the spin base section to a specialized version of PhysicalProperty. Would leave this as a short follow-up.
Similarly specializing the contributions for electronics requires the addition of OrbitalsState to ModelSystem itself, as I already raised.

@everyone Feel free to raise suggestions for the remaining in-code comments.

- Simplify `is_derived`
- Clean dependencies
- Mark unused or superfluous quantities
- Extend normalization to:
-- allow for normalization only once
-- move up normalization of the parent class
- Change `sub_plots` to use pre-existing sub_plot figures or produce them
- Apply contribution structure to properties like Energy, Force, and Eigenvalues
-- Correct mypy error in `order_eigenvalues` by simplifying return type to just tuples
- Prune superfluous initializers
- Add naming logic to `Variables` base section
- Remove superfluous test checking the no. subsections in outputs
@ndaelman-hu ndaelman-hu requested a review from Copilot July 13, 2025 21:27
@ndaelman-hu ndaelman-hu self-assigned this Jul 13, 2025
@ndaelman-hu ndaelman-hu added the improvement/fix Improvement or fix of a previous feature label Jul 13, 2025

This comment was marked as outdated.

@ndaelman-hu ndaelman-hu requested a review from JFRudzinski July 13, 2025 21:54
Copy link
Collaborator

@JFRudzinski JFRudzinski left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this @ndaelman-hu !

I think most of it is good as is.

  • My comments referring to the TODOs could be addressed simply by coming to a consensus and adding to the TODO
  • My main concern is the change in contributions implementation, I don't think it is functioning now in the way we intended. Let's discuss and either adjust it or move it to another PR

is populated, the quantity `is_derived` is set to True via normalization.
""",
)
) # TODO: only used for electronic states, remove
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that this doesn't belong under PP. Are there real use cases of properties referencing individual atoms such that we need to generalize Outputs.modelsystem_ref?

I think if there is a per-atom PP, then Output just references the ModelSystem with the corresponding list of atoms in particles_indices

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have some use cases of properties referencing individual atoms, and referencing through particle_indices sounds suitable from my end 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be pointing to specific orbital states too.

There are indeed properties which are per atom or per orbital, while there might be a total one as well. Either way, I thought that the model_system_ref would be use for the global system, while this one for specific AtomsState or OrbitalsState.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

properties which are per atom or per orbital, while there might be a total one as well

Indeed, one can define orbitals at a system-wide level, or projected onto a specific ion, species, etc. This is why particle_indices alone don't suffice.
We have a

I would work towards a bi-directional reference, where electronic entities (like orbitals) are integrated as well.
I was testing this out in the other PR, already.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would develop anything based on how easy is to use, and leverage out logic to methods or references.

From the user perspective, is it easy to get a property and need to code something to read the particle indices to then get which atom refers to? And a similar question for the orbitals? In my opinion, the current entity_ref was the easiest solution. Equivalently, you can also leverage out the logic to resolve this kind of things to a method.

I think we are on the same page @ndaelman-hu, I just wanted to make sure we are all in the same one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe just as a summary (also for myself), at the time of writing.

Either way, I thought that the model_system_ref would be use for the global system, while this one for specific AtomsState or OrbitalsState.

ModelSystem can point to a ParticleState or AtomsState at the top level alone (unsure whether programmatically enforced). The latter can point to an OrbitalState, so the connection is indirect at best.
There atm no way to define the OrbitalState (or SpinState) for a collection of particles / atoms. The latter is based on notes from a discussion with @EBB2675

From the user perspective, is it easy to get a property and need to code something to read the particle indices to then get which atom refers to? [...] In my opinion, the current entity_ref was the easiest solution.

I agree that direct references are generally indeed easier, but no comment on the use of particle_indices.
I think entity_ref is too limited, as it only allows me to reference an orbital / band, but it doesn't define the over which collection of particles / atoms.

I see 2 possible fixes. This tackles the same issue as Spin, so I suggest packing both together in a follow-up issue.

@EBB2675
Copy link
Collaborator

EBB2675 commented Aug 5, 2025

@EBB2675 I would add the spin base section to a specialized version of PhysicalProperty. Would leave this as a short follow-up.

@ndaelman-hu Approximately when will you be tackling this part? We will plan some remaining parts of the QC schema accordingly with Denis

@coveralls
Copy link

coveralls commented Aug 6, 2025

Pull Request Test Coverage Report for Build 16906346307

Details

  • 97 of 100 (97.0%) changed or added relevant lines in 8 files are covered.
  • 10 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.04%) to 69.696%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/nomad_simulations/schema_packages/physical_property.py 69 72 95.83%
Files with Coverage Reduction New Missed Lines %
src/nomad_simulations/schema_packages/properties/fermi_surface.py 1 88.89%
src/nomad_simulations/schema_packages/variables.py 9 84.21%
Totals Coverage Status
Change from base Build 16905149454: -0.04%
Covered Lines: 1971
Relevant Lines: 2828

💛 - Coveralls

@ndaelman-hu
Copy link
Collaborator Author

All tests pass, some points that have been brought up (SCF, referencing species orbitals, spin) are deferred to their own issues.
All other threads have been resolved, as far as I care, but feel free to double-check.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements significant refactoring of the PhysicalProperty class and its integration with contributions, alongside comprehensive test updates and removal of deprecated patterns. The changes aim to simplify the codebase by consolidating functionality and improving plotting capabilities.

  • Integration of PhysicalContribution into PhysicalProperty with contributions as subsections
  • Addition of plotting functionality and sub-plot aggregation from contributions
  • Removal of redundant __init__ methods and consolidation of name-setting logic

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/nomad_simulations/schema_packages/physical_property.py Major refactor integrating contributions, adding plotting support, and validation methods
src/nomad_simulations/schema_packages/variables.py Consolidated name-setting logic in normalize method
src/nomad_simulations/schema_packages/properties/*.py Removed redundant __init__ methods across all property classes
tests/test_physical_properties.py Comprehensive new tests for plotting, contributions, and validation
tests/test_variables.py Added test for name-setting during normalization
tests/test_outputs.py Updated test expectations and removed deprecated test
tests/properties/test_*.py Removed obsolete name assertion tests and fixed test logic
Comments suppressed due to low confidence (1)

tests/properties/test_band_structure.py:115

  • The return type change from Union[bool, tuple] to tuple | tuple[()] is inconsistent with the removal of the decorator. Consider using Optional[tuple[pint.Quantity, np.ndarray]] for clearer type annotation.
                        0.0,

Copy link
Collaborator

@JFRudzinski JFRudzinski left a comment

Choose a reason for hiding this comment

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

See #208

@ndaelman-hu ndaelman-hu merged commit 74f1835 into develop Aug 12, 2025
7 checks passed
@ndaelman-hu ndaelman-hu deleted the physical-property-tweaking branch August 12, 2025 11:00
@ndaelman-hu ndaelman-hu restored the physical-property-tweaking branch August 12, 2025 11:00
@JosePizarro3 JosePizarro3 mentioned this pull request Aug 18, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement/fix Improvement or fix of a previous feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants