hybrax 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. hybrax/__init__.py +5 -0
  2. hybrax/format/__init__.py +160 -0
  3. hybrax/format/_logging.py +18 -0
  4. hybrax/format/dataclasses.py +599 -0
  5. hybrax/format/inspect.py +1428 -0
  6. hybrax/format/json_io.py +154 -0
  7. hybrax/format/mechanistic.py +1051 -0
  8. hybrax/format/monotone_spline.py +648 -0
  9. hybrax/format/serialization.py +993 -0
  10. hybrax/format/simulation.py +384 -0
  11. hybrax/format/splines.py +1853 -0
  12. hybrax/format/time_series/__init__.py +6 -0
  13. hybrax/format/time_series/constants.py +11 -0
  14. hybrax/format/time_series/grid_utils.py +74 -0
  15. hybrax/format/time_series/io.py +49 -0
  16. hybrax/format/time_series/ppoly.py +120 -0
  17. hybrax/format/time_series/spline_ops.py +260 -0
  18. hybrax/format/time_series/timeseries.py +660 -0
  19. hybrax/format/validate.py +1383 -0
  20. hybrax/train/__init__.py +277 -0
  21. hybrax/train/augmentation.py +457 -0
  22. hybrax/train/augmentation_plot.py +155 -0
  23. hybrax/train/bounds_loss.py +244 -0
  24. hybrax/train/checkpointing.py +245 -0
  25. hybrax/train/cli.py +1312 -0
  26. hybrax/train/constants.py +10 -0
  27. hybrax/train/controls.py +490 -0
  28. hybrax/train/controls_store.py +1431 -0
  29. hybrax/train/defaults.py +684 -0
  30. hybrax/train/dense.py +141 -0
  31. hybrax/train/diffrax_callbacks/README.md +345 -0
  32. hybrax/train/diffrax_callbacks/__init__.py +26 -0
  33. hybrax/train/diffrax_callbacks/_callbacks.py +392 -0
  34. hybrax/train/diffrax_callbacks/_solution.py +124 -0
  35. hybrax/train/diffrax_callbacks/_solve.py +883 -0
  36. hybrax/train/diffrax_callbacks/examples/01_basic_fed_batch.py +164 -0
  37. hybrax/train/diffrax_callbacks/examples/02_multiple_callbacks.py +153 -0
  38. hybrax/train/diffrax_callbacks/examples/03_hybrid_node_control.py +362 -0
  39. hybrax/train/forward_plotting.py +367 -0
  40. hybrax/train/harness.py +2731 -0
  41. hybrax/train/inspect.py +424 -0
  42. hybrax/train/logging.py +416 -0
  43. hybrax/train/loo.py +1423 -0
  44. hybrax/train/loo_metrics.py +1045 -0
  45. hybrax/train/model_api.py +1157 -0
  46. hybrax/train/physical_solve.py +421 -0
  47. hybrax/train/postprocessing.py +743 -0
  48. hybrax/train/preflight.py +171 -0
  49. hybrax/train/prepare.py +599 -0
  50. hybrax/train/run_config.py +802 -0
  51. hybrax/train/runtime_artifact.py +1614 -0
  52. hybrax/train/runtime_context.py +534 -0
  53. hybrax/train/serialization.py +658 -0
  54. hybrax/train/trainer.py +717 -0
  55. hybrax/train/training_data.py +920 -0
  56. hybrax/train/utils.py +97 -0
  57. hybrax/train/validate.py +330 -0
  58. hybrax/train/wrapper.py +645 -0
  59. hybrax-0.1.0.dist-info/METADATA +132 -0
  60. hybrax-0.1.0.dist-info/RECORD +64 -0
  61. hybrax-0.1.0.dist-info/WHEEL +5 -0
  62. hybrax-0.1.0.dist-info/entry_points.txt +2 -0
  63. hybrax-0.1.0.dist-info/licenses/LICENSE +21 -0
  64. hybrax-0.1.0.dist-info/top_level.txt +1 -0
hybrax/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Hybrax: bioprocess hybrid models and data management in JAX."""
2
+
3
+ from importlib.metadata import version
4
+
5
+ __version__ = version("hybrax")
@@ -0,0 +1,160 @@
1
+ """Bioprocess data structures, validation, serialization, and mechanistic modeling."""
2
+
3
+ import importlib
4
+ import os
5
+ import sys
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ # hybrax.format requires float64 throughout. Configure future JAX imports without
9
+ # importing JAX just to initialize this package.
10
+ os.environ["JAX_ENABLE_X64"] = "true"
11
+ if "jax" in sys.modules:
12
+ importlib.import_module("jax").config.update("jax_enable_x64", True)
13
+
14
+ from hybrax import __version__
15
+
16
+ if TYPE_CHECKING:
17
+ from . import mechanistic, serialization, splines, validate # noqa: F401
18
+ from .dataclasses import ( # noqa: F401
19
+ AugmentedBioProcess,
20
+ BioProcess,
21
+ BioProcessCollection,
22
+ BioProcessMetadata,
23
+ Bounds,
24
+ DiscreteEvents,
25
+ FeedMedium,
26
+ FeedMediumComponent,
27
+ Inflow,
28
+ Outflow,
29
+ ProcessOrdering,
30
+ ProcessVariable,
31
+ PseudobatchTransform,
32
+ ReactionOde,
33
+ ReactorMedium,
34
+ ReactorMediumComponent,
35
+ StaticVariable,
36
+ TimeAxis,
37
+ TimeSeries,
38
+ Volume,
39
+ VolumeChange,
40
+ silence_assumptions,
41
+ )
42
+ from .inspect import ( # noqa: F401
43
+ plot_collection,
44
+ plot_process,
45
+ print_collection_structure,
46
+ print_process_structure,
47
+ print_rhs_ode,
48
+ )
49
+ from .simulation import Simulation, SimulationEvent, SimulationResult # noqa: F401
50
+ from .validate import ( # noqa: F401
51
+ validate_augmented_parent_refs,
52
+ validate_biomass_in_reactor_medium,
53
+ validate_bounds,
54
+ validate_bounds_against_data,
55
+ validate_cross_process_consistency,
56
+ validate_discrete_events,
57
+ validate_for_publication,
58
+ validate_initial_state_alignment,
59
+ validate_measurement_sampling_alignment,
60
+ validate_outflow_retention,
61
+ validate_process,
62
+ validate_reaction_ode,
63
+ validate_reaction_ode_equivalence,
64
+ validate_time_axis,
65
+ validate_timeseries_shape,
66
+ validate_timestamp_bounds,
67
+ validate_volume_change_sign,
68
+ validate_volume_change_states,
69
+ validate_volume_consistency,
70
+ validate_volume_units,
71
+ )
72
+
73
+ _EXPORT_MODULES = {
74
+ ".dataclasses": (
75
+ "TimeAxis",
76
+ "DiscreteEvents",
77
+ "TimeSeries",
78
+ "StaticVariable",
79
+ "BioProcessMetadata",
80
+ "ProcessVariable",
81
+ "FeedMediumComponent",
82
+ "ReactorMediumComponent",
83
+ "VolumeChange",
84
+ "Inflow",
85
+ "Outflow",
86
+ "Volume",
87
+ "FeedMedium",
88
+ "ReactorMedium",
89
+ "Bounds",
90
+ "ReactionOde",
91
+ "ProcessOrdering",
92
+ "PseudobatchTransform",
93
+ "BioProcess",
94
+ "AugmentedBioProcess",
95
+ "BioProcessCollection",
96
+ "silence_assumptions",
97
+ ),
98
+ ".simulation": ("Simulation", "SimulationEvent", "SimulationResult"),
99
+ ".inspect": (
100
+ "print_process_structure",
101
+ "print_collection_structure",
102
+ "print_rhs_ode",
103
+ "plot_process",
104
+ "plot_collection",
105
+ ),
106
+ ".validate": (
107
+ "validate_time_axis",
108
+ "validate_timeseries_shape",
109
+ "validate_discrete_events",
110
+ "validate_timestamp_bounds",
111
+ "validate_volume_change_sign",
112
+ "validate_volume_change_states",
113
+ "validate_volume_units",
114
+ "validate_outflow_retention",
115
+ "validate_biomass_in_reactor_medium",
116
+ "validate_initial_state_alignment",
117
+ "validate_measurement_sampling_alignment",
118
+ "validate_process",
119
+ "validate_volume_consistency",
120
+ "validate_for_publication",
121
+ "validate_augmented_parent_refs",
122
+ "validate_reaction_ode",
123
+ "validate_reaction_ode_equivalence",
124
+ "validate_bounds",
125
+ "validate_bounds_against_data",
126
+ "validate_cross_process_consistency",
127
+ ),
128
+ }
129
+ _EXPORTS = {
130
+ name: module_name
131
+ for module_name, names in _EXPORT_MODULES.items()
132
+ for name in names
133
+ }
134
+ _EXPORTS.update(
135
+ {
136
+ "serialization": ".serialization",
137
+ "validate": ".validate",
138
+ "mechanistic": ".mechanistic",
139
+ "splines": ".splines",
140
+ }
141
+ )
142
+
143
+ # Ruff cannot infer that unpacking _EXPORTS yields only string keys.
144
+ __all__ = ["__version__", *_EXPORTS] # noqa: PLE0604
145
+
146
+
147
+ def __getattr__(name: str) -> Any:
148
+ """Load public objects only when accessed."""
149
+ module_name = _EXPORTS.get(name)
150
+ if module_name is None:
151
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
152
+ module = importlib.import_module(module_name, __name__)
153
+ value = module if name == module_name.removeprefix(".") else getattr(module, name)
154
+ globals()[name] = value
155
+ return value
156
+
157
+
158
+ def __dir__() -> list[str]:
159
+ """Include lazy exports in interactive discovery."""
160
+ return sorted(set(globals()) | set(__all__))
@@ -0,0 +1,18 @@
1
+ """Shared logging setup for hybrax.format."""
2
+
3
+ import logging
4
+
5
+
6
+ def get_logger(name: str) -> logging.Logger:
7
+ """Return a logger under the ``hybrax.format`` namespace.
8
+
9
+ Library code must never call ``logging.basicConfig()`` or set a shared
10
+ logger's level — that decision belongs solely to the hosting application.
11
+ A ``NullHandler`` is attached once so that, absent app-level logging
12
+ configuration, records are silently discarded instead of falling through
13
+ to ``logging.lastResort``.
14
+ """
15
+ top = logging.getLogger("hybrax.format")
16
+ if not top.handlers:
17
+ top.addHandler(logging.NullHandler())
18
+ return logging.getLogger(name)