fix(python): added stubs

code inspection now works with fourdst
This commit is contained in:
2025-11-25 11:54:08 -05:00
parent a799957f3e
commit a55a661b39
14 changed files with 604 additions and 48 deletions

View File

@@ -1,4 +1,5 @@
from ._phys import *
# src-pybind/fourdst/__init__.py
from __future__ import annotations
import sys
from ._phys import atomic, composition, constants, config
@@ -8,4 +9,6 @@ sys.modules['fourdst.composition'] = composition
sys.modules['fourdst.constants'] = constants
sys.modules['fourdst.config'] = config
__all__ = ['atomic', 'composition', 'constants', 'config', 'core', 'cli']
__all__ = ['atomic', 'composition', 'constants', 'config', 'core', 'cli']
__version__ = 'v0.9.6'

View File

@@ -0,0 +1,9 @@
from __future__ import annotations
from fourdst import atomic
from fourdst import composition
from fourdst import config
from fourdst import constants
__all__: list = ['atomic', 'composition', 'constants', 'config', 'core', 'cli']

View File

@@ -0,0 +1,9 @@
"""
Python bindings for the fourdst utility modules which are a part of the 4D-STAR project.
"""
from __future__ import annotations
from . import atomic
from . import composition
from . import config
from . import constants
__all__: list[str] = ['atomic', 'composition', 'config', 'constants']

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,215 @@
"""
Composition-module bindings
"""
from __future__ import annotations
import fourdst.atomic
import typing
from . import utils
__all__: list[str] = ['CanonicalComposition', 'Composition', 'utils']
class CanonicalComposition:
def __repr__(self) -> str:
...
@property
def X(self) -> float:
...
@property
def Y(self) -> float:
...
@property
def Z(self) -> float:
...
class Composition:
def __eq__(self, arg0: Composition) -> bool:
...
def __hash__(self) -> int:
...
@typing.overload
def __init__(self) -> None:
"""
Default constructor
"""
@typing.overload
def __init__(self, symbols: list[str]) -> None:
"""
Constructor taking a list of symbols to register
"""
@typing.overload
def __init__(self, symbols: set[str]) -> None:
"""
Constructor taking a set of symbols to register
"""
@typing.overload
def __init__(self, species: list[fourdst.atomic.Species]) -> None:
"""
Constructor taking a list of species to register
"""
@typing.overload
def __init__(self, species: set[fourdst.atomic.Species]) -> None:
"""
Constructor taking a set of species to register
"""
@typing.overload
def __init__(self, symbols: list[str], molarAbundances: list[float]) -> None:
"""
Constructor taking a list of symbols and molar abundances
"""
@typing.overload
def __init__(self, species: list[fourdst.atomic.Species], molarAbundances: list[float]) -> None:
"""
Constructor taking a list of species and molar abundances
"""
@typing.overload
def __init__(self, symbols: set[str], molarAbundances: list[float]) -> None:
"""
Constructor taking a set of symbols and a list of molar abundances
"""
@typing.overload
def __init__(self, speciesMolarAbundances: dict[fourdst.atomic.Species, float]) -> None:
"""
Constructor taking an unordered map of species to molar abundances
"""
@typing.overload
def __init__(self, speciesMolarAbundances: dict[fourdst.atomic.Species, float]) -> None:
"""
Constructor taking a map of species to molar abundances
"""
def __iter__(self) -> typing.Iterator[tuple[fourdst.atomic.Species, float]]:
...
def __repr__(self) -> str:
...
@typing.overload
def contains(self, symbol: str) -> bool:
"""
Check if a symbol is in the composition.
"""
@typing.overload
def contains(self, species: fourdst.atomic.Species) -> bool:
"""
Check if a species is in the composition.
"""
def getCanonicalComposition(self) -> CanonicalComposition:
"""
Get a canonical composition (X, Y, Z). d
"""
@typing.overload
def getMassFraction(self, symbol: str) -> float:
"""
Get mass fraction for a symbol.
"""
@typing.overload
def getMassFraction(self, species: fourdst.atomic.Species) -> float:
"""
Get mass fraction for a species.
"""
@typing.overload
def getMassFraction(self) -> dict[fourdst.atomic.Species, float]:
"""
Get dictionary of all mass fractions.
"""
def getMassFractionVector(self) -> list[float]:
"""
Get mass fractions as a vector (ordered by species mass).
"""
def getMeanParticleMass(self) -> float:
"""
Get the mean particle mass (amu)
"""
@typing.overload
def getMolarAbundance(self, symbol: str) -> float:
"""
Get molar abundance for a symbol.
"""
@typing.overload
def getMolarAbundance(self, species: fourdst.atomic.Species) -> float:
"""
Get molar abundance for a species.
"""
def getMolarAbundanceVector(self) -> list[float]:
"""
Get molar abundances as a vector (ordered by species mass).
"""
@typing.overload
def getNumberFraction(self, symbol: str) -> float:
"""
Get number fraction for a symbol.
"""
@typing.overload
def getNumberFraction(self, species: fourdst.atomic.Species) -> float:
"""
Get number fraction for a species.
"""
@typing.overload
def getNumberFraction(self) -> dict[fourdst.atomic.Species, float]:
"""
Get dictionary of all number fractions.
"""
def getNumberFractionVector(self) -> list[float]:
"""
Get number fractions as a vector (ordered by species mass)
"""
def getRegisteredSpecies(self) -> set[fourdst.atomic.Species]:
"""
Get the set of registered species.
"""
def getRegisteredSymbols(self) -> set[str]:
"""
Get the set of registered symbols.
"""
def getSpeciesAtIndex(self, index: int) -> fourdst.atomic.Species:
"""
Get the species at a given index in the internal ordering.
"""
@typing.overload
def getSpeciesIndex(self, symbol: str) -> int:
"""
Get the index of a species in the internal ordering.
"""
@typing.overload
def getSpeciesIndex(self, species: fourdst.atomic.Species) -> int:
"""
Get the index of a species in the internal ordering.
"""
@typing.overload
def registerSpecies(self, species: fourdst.atomic.Species) -> None:
"""
Register a single species. The molar abundance will be initialized to zero.
"""
@typing.overload
def registerSpecies(self, species: list[fourdst.atomic.Species]) -> None:
"""
Register multiple species. Each molar abundance will be initialized to zero.
"""
@typing.overload
def registerSymbol(self, symbol: str) -> None:
"""
Register a single symbol. The molar abundance will be initialized to zero.
"""
@typing.overload
def registerSymbol(self, symbols: list[str]) -> None:
"""
Register multiple symbols. Each molar abundance will be initialized to zero.
"""
@typing.overload
def setMolarAbundance(self, symbol: str, molarAbundance: float) -> None:
"""
Set the molar abundance for a symbol.
"""
@typing.overload
def setMolarAbundance(self, species: fourdst.atomic.Species, molarAbundance: float) -> None:
"""
Set the molar abundance for a species.
"""
@typing.overload
def setMolarAbundance(self, symbols: list[str], molarAbundances: list[float]) -> None:
"""
Set the molar abundance for a list of symbols. The molar abundance vector must be parallel to the symbols vector.
"""
@typing.overload
def setMolarAbundance(self, species: list[fourdst.atomic.Species], molarAbundances: list[float]) -> None:
"""
Set the molar abundance for a list of species. The molar abundance vector must be parallel to the species vector.
"""
def size(self) -> int:
"""
Get the number of registered species in the composition.
"""

View File

@@ -0,0 +1,44 @@
"""
Utility functions for Composition
"""
from __future__ import annotations
import fourdst.atomic
import fourdst.composition
import typing
__all__: list[str] = ['CompositionHash', 'buildCompositionFromMassFractions']
class CompositionHash:
@staticmethod
def hash_exact(composition: fourdst.composition.Composition) -> int:
"""
Compute a hash for a given Composition object.
"""
@staticmethod
def hash_quantized(composition: fourdst.composition.Composition, eps: float) -> int:
"""
Compute a quantized hash for a given Composition object with specified precision.
"""
@typing.overload
def buildCompositionFromMassFractions(symbols: list[str], massFractions: list[float]) -> fourdst.composition.Composition:
"""
Build a Composition object from symbols and their corresponding mass fractions.
"""
@typing.overload
def buildCompositionFromMassFractions(species: list[fourdst.atomic.Species], massFractions: list[float]) -> fourdst.composition.Composition:
"""
Build a Composition object from species and their corresponding mass fractions.
"""
@typing.overload
def buildCompositionFromMassFractions(species: set[fourdst.atomic.Species], massFractions: list[float]) -> fourdst.composition.Composition:
"""
Build a Composition object from species in a set and their corresponding mass fractions.
"""
@typing.overload
def buildCompositionFromMassFractions(massFractionsMap: dict[fourdst.atomic.Species, float]) -> fourdst.composition.Composition:
"""
Build a Composition object from a map of species to mass fractions.
"""
@typing.overload
def buildCompositionFromMassFractions(massFractionsMap: dict[fourdst.atomic.Species, float]) -> fourdst.composition.Composition:
"""
Build a Composition object from a map of species to mass fractions.
"""

View File

@@ -0,0 +1,40 @@
"""
Configuration-module bindings
"""
from __future__ import annotations
import typing
__all__: list[str] = ['get', 'has', 'keys', 'loadConfig']
def __repr__() -> str:
...
@typing.overload
def get(key: str, defaultValue: int) -> int:
"""
Get configuration value (type inferred from default)
"""
@typing.overload
def get(key: str, defaultValue: float) -> float:
"""
Get configuration value (type inferred from default)
"""
@typing.overload
def get(key: str, defaultValue: str) -> str:
"""
Get configuration value (type inferred from default)
"""
@typing.overload
def get(key: str, defaultValue: bool) -> bool:
"""
Get configuration value (type inferred from default)
"""
def has(key: str) -> bool:
"""
Check if a key exists in the configuration.
"""
def keys() -> typing.Any:
"""
Get a list of all configuration keys.
"""
def loadConfig(configFilePath: str) -> bool:
"""
Load configuration from a YAML file.
"""

View File

@@ -0,0 +1,46 @@
"""
Constants-module bindings
"""
from __future__ import annotations
import typing
__all__: list[str] = ['Constant', 'Constants']
class Constant:
def __repr__(self) -> str:
...
@property
def name(self) -> str:
...
@property
def reference(self) -> str:
...
@property
def uncertainty(self) -> float:
...
@property
def unit(self) -> str:
...
@property
def value(self) -> float:
...
class Constants:
@staticmethod
def __class_getitem__(arg0: str) -> typing.Any:
...
@staticmethod
def get(arg0: str) -> typing.Any:
"""
Get a constant by name. Returns None if not found.
"""
@staticmethod
def has(arg0: str) -> bool:
"""
Check if a constant exists by name.
"""
@staticmethod
def keys() -> typing.Any:
"""
Get a list of all constant names.
"""
@property
def loaded(self) -> bool:
...