Skip to content

outputs: Annotate fields with Unit markers#146

Merged
mbercx merged 1 commit into
aiidateam:mainfrom
mbercx:new/units
Apr 30, 2026
Merged

outputs: Annotate fields with Unit markers#146
mbercx merged 1 commit into
aiidateam:mainfrom
mbercx:new/units

Conversation

@mbercx
Copy link
Copy Markdown
Member

@mbercx mbercx commented Apr 30, 2026

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).

`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).
@mbercx mbercx merged commit 365eaaf into aiidateam:main Apr 30, 2026
4 checks passed
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.

1 participant