✨ outputs: Annotate fields with Unit markers#146
Merged
Conversation
`dough` 0.4 introduced the `Unit(...)` annotation on `Annotated[T, Spec(...),
Unit(...)]` to label a field's physical unit, and a matching `to="pint"` target
on `BaseOutput.get_output` / `get_output_dict` that wraps marked numeric outputs
into `pint.Quantity`. Annotate the existing `_PwMapping`,
`_PwParametersMapping`, and `_DosMapping` fields with their physical unit so
users can opt in to `pint`-based conversion (`pw_out.get_output("total_energy",
to="pint")`).
Units annotated:
- `_PwMapping`: `forces` (eV/Å), `stress` (GPa),
`fermi_energy`/`fermi_energy_up`/ `fermi_energy_down`/`total_energy` (eV),
`k_points_cartesian` (1/Å).
- `_PwParametersMapping`: `ecutwfc`, `ecutrho`, `degauss` (eV).
- `_DosMapping`: `energy`, `fermi_energy` (eV); `dos`, `dos_up`, `dos_down`
(1/eV).
Fields without a meaningful physical unit (`integrated_dos` is a count of
states, `k_points_weights` are dimensionless QE-convention weights) deliberately
stay unmarked — `to="pint"` passes those through unchanged.
Also fix the `_DosMapping.integrated_dos` docstring to clarify the unit (number
of states, not eV).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
dough0.4 introduced theUnit(...)annotation onAnnotated[T, Spec(...), Unit(...)]to label a field's physical unit, and a matchingto="pint"target onBaseOutput.get_output/get_output_dictthat wraps marked numeric outputs intopint.Quantity. Annotate the existing_PwMapping,_PwParametersMapping, and_DosMappingfields with their physical unit so users can opt in topint-based conversion (pw_out.get_output("total_energy", to="pint")).Units annotated:
_PwMapping:forces(eV/Å),stress(GPa),fermi_energy/fermi_energy_up/fermi_energy_down/total_energy(eV),k_points_cartesian(1/Å)._PwParametersMapping:ecutwfc,ecutrho,degauss(eV)._DosMapping:energy,fermi_energy(eV);dos,dos_up,dos_down(1/eV).Fields without a meaningful physical unit (
integrated_dosis a count of states,k_points_weightsare dimensionless QE-convention weights) deliberately stay unmarked —to="pint"passes those through unchanged.Also fix the
_DosMapping.integrated_dosdocstring to clarify the unit (number of states, not eV).