Skip to content

Commit 6d13126

Browse files
committed
doc: private / public / fix references
* Exclude private members from the sphinx documentation * Make some supposed-to-be-private members private * Fix references * Fix docstrings To be continued...
1 parent 6b3bf83 commit 6d13126

File tree

16 files changed

+464
-529
lines changed

16 files changed

+464
-529
lines changed

doc/_templates/autosummary/module.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{{ fullname | escape | underline}}
22

33
.. automodule:: {{ fullname }}
4-
:members:
5-
:undoc-members:
64

75
{% block attributes %}
86
{% if attributes %}

doc/conf.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,12 @@ def install_doxygen():
207207
"inherited-members": True,
208208
"undoc-members": True,
209209
"ignore-module-all": False,
210+
"imported-members": True,
210211
}
211212

213+
# autosummary
214+
autosummary_ignore_module_all = False
215+
212216
# sphinx-autodoc-typehints
213217
typehints_fully_qualified = True
214218
typehints_document_rtype = True
@@ -469,36 +473,21 @@ def process_missing_ref(app, env, node, contnode):
469473

470474

471475
def skip_member(app, what, name, obj, skip, options):
476+
"""Decide whether to skip a member during autodoc processing.
477+
478+
> Emitted when autodoc has to decide whether a member should be included in
479+
> the documentation.
480+
> The member is excluded if a handler returns True.
481+
> It is included if the handler returns False.
482+
"""
472483
ignored_names = {
473484
"AbstractModel",
474485
"CVodeSolver",
475486
"IDASolver",
476487
"Model_ODE",
477488
"Model_DAE",
478489
"ConditionContext",
479-
"checkSigmaPositivity",
480-
"createGroup",
481490
"equals",
482-
"printErrMsgIdAndTxt",
483-
"wrapErrHandlerFn",
484-
"printWarnMsgIdAndTxt",
485-
"AmiciApplication",
486-
"writeReturnData",
487-
"writeReturnDataDiagnosis",
488-
"attributeExists",
489-
"locationExists",
490-
"createAndWriteDouble1DDataset",
491-
"createAndWriteDouble2DDataset",
492-
"createAndWriteDouble3DDataset",
493-
"createAndWriteInt1DDataset",
494-
"createAndWriteInt2DDataset",
495-
"createAndWriteInt3DDataset",
496-
"getDoubleDataset1D",
497-
"getDoubleDataset2D",
498-
"getDoubleDataset3D",
499-
"getIntDataset1D",
500-
"getIntScalarAttribute",
501-
"getDoubleScalarAttribute",
502491
"stdVec2ndarray",
503492
"SwigPyIterator",
504493
"thisown",
@@ -507,6 +496,16 @@ def skip_member(app, what, name, obj, skip, options):
507496
if name in ignored_names:
508497
return True
509498

499+
# skip, unless in __all__
500+
# (we want to include imported members, but only the exported ones.
501+
# autodoc does not provide this functionality out of the box)
502+
module_name = app.env.temp_data.get("autodoc:module")
503+
if module_name and what == "module":
504+
module_obj = sys.modules.get(module_name)
505+
if module_obj is not None and hasattr(module_obj, "__all__"):
506+
if name not in getattr(module_obj, "__all__", []):
507+
return True
508+
510509
if name.startswith("_") and name != "__init__":
511510
return True
512511

doc/examples/example_presimulation/ExampleExperimentalConditions.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
"source": [
212212
"# Retrieve model output names and formulae from AssignmentRules and remove the respective rules\n",
213213
"observables = amici.assignment_rules_to_observables(\n",
214-
" sbml_importer.sbml, # the libsbml model object\n",
214+
" sbml_importer.sbml_model, # the libsbml model object\n",
215215
" filter_function=lambda variable: variable.getName() == \"pPROT\",\n",
216216
")\n",
217217
"print(\"Observables:\")\n",

python/sdist/amici/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
2-
The AMICI Python module provides functionality for importing SBML or PySB
3-
models and turning them into C++ Python extensions.
2+
Top-level module.
43
"""
54

65
import contextlib
@@ -226,7 +225,7 @@ def import_model_module(
226225
module_name: str, module_path: Path | str
227226
) -> ModelModule:
228227
"""
229-
Import Python module of an AMICI model
228+
Import Python module of an AMICI model.
230229
231230
:param module_name:
232231
Name of the python package of the model

python/sdist/amici/adapters/fiddy.py

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,28 @@
3838
__all__ = [
3939
"run_simulation_to_cached_functions",
4040
"simulate_petab_to_cached_functions",
41+
"simulate_petab_v2_to_cached_functions",
4142
]
4243

4344
LOG_E_10 = np.log(10)
4445

4546

46-
def transform_gradient_lin_to_lin(gradient_value, _):
47+
def _transform_gradient_lin_to_lin(gradient_value, _):
4748
return gradient_value
4849

4950

50-
def transform_gradient_lin_to_log(gradient_value, parameter_value):
51+
def _transform_gradient_lin_to_log(gradient_value, parameter_value):
5152
return gradient_value * parameter_value
5253

5354

54-
def transform_gradient_lin_to_log10(gradient_value, parameter_value):
55+
def _transform_gradient_lin_to_log10(gradient_value, parameter_value):
5556
return gradient_value * (parameter_value * LOG_E_10)
5657

5758

5859
transforms = {
59-
LIN: transform_gradient_lin_to_lin,
60-
LOG: transform_gradient_lin_to_log,
61-
LOG10: transform_gradient_lin_to_log10,
60+
LIN: _transform_gradient_lin_to_lin,
61+
LOG: _transform_gradient_lin_to_log,
62+
LOG10: _transform_gradient_lin_to_log10,
6263
}
6364

6465

@@ -93,20 +94,13 @@ def transform_gradient_lin_to_log10(gradient_value, parameter_value):
9394
}
9495

9596

96-
def rdata_array_transpose(array: np.ndarray, variable: str) -> tuple[int]:
97+
def _rdata_array_transpose(array: np.ndarray, variable: str) -> tuple[int]:
9798
if array.size == 0:
9899
return array
99100
original_parameter_dimension = derivative_parameter_dimension[variable]
100101
return np.moveaxis(array, original_parameter_dimension, -1)
101102

102103

103-
def fiddy_array_transpose(array: np.ndarray, variable: str) -> tuple[int]:
104-
if array.size == 0:
105-
return array
106-
original_parameter_dimension = derivative_parameter_dimension[variable]
107-
return np.moveaxis(array, -1, original_parameter_dimension)
108-
109-
110104
default_derivatives = {
111105
k: v
112106
for k, v in all_rdata_derivatives.items()
@@ -181,7 +175,7 @@ def function(point: Type.POINT):
181175
def derivative(point: Type.POINT, return_dict: bool = False):
182176
rdata = run_amici_simulation(point=point, order=SensitivityOrder.first)
183177
outputs = {
184-
variable: rdata_array_transpose(
178+
variable: _rdata_array_transpose(
185179
array=fiddy_array(getattr(rdata, derivative_variable)),
186180
variable=derivative_variable,
187181
)
@@ -244,48 +238,6 @@ def derivative(point: Type.POINT, return_dict: bool = False):
244238
TYPE_STRUCTURE = tuple[int, int, tuple[int, ...]]
245239

246240

247-
def flatten(arrays: dict[str, Type.ARRAY]) -> Type.ARRAY:
248-
flattened_value = np.concatenate([array.flat for array in arrays.values()])
249-
return flattened_value
250-
251-
252-
def reshape(
253-
array: Type.ARRAY,
254-
structure: TYPE_STRUCTURE,
255-
sensitivities: bool = False,
256-
) -> dict[str, Type.ARRAY]:
257-
reshaped = {}
258-
for variable, (start, stop, shape) in structure.items():
259-
# array is currently "flattened" w.r.t. fiddy dimensions
260-
# hence, if sensis, reshape w.r.t. fiddy dimensions
261-
if sensitivities and (
262-
dimension0 := derivative_parameter_dimension.get(
263-
"s" + variable, False
264-
)
265-
):
266-
shape = [
267-
size
268-
for dimension, size in enumerate(shape)
269-
if dimension != dimension0
270-
] + [shape[dimension0]]
271-
272-
array = array[start:stop]
273-
if array.size != 0:
274-
array = array.reshape(shape)
275-
276-
# now reshape to AMICI dimensions
277-
if sensitivities and (
278-
derivative_parameter_dimension.get(f"s{variable}", False)
279-
):
280-
array = fiddy_array_transpose(
281-
array=array,
282-
variable=f"s{variable}",
283-
)
284-
reshaped[variable] = array
285-
286-
return reshaped
287-
288-
289241
def simulate_petab_to_cached_functions(
290242
petab_problem: petab.Problem,
291243
amici_model: Model,

python/sdist/amici/exporters/sundials/de_export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __init__(
218218
# include/amici/model.h for details)
219219
self.model: DEModel = de_model
220220
self._code_printer.known_functions.update(
221-
splines.spline_user_functions(
221+
splines._spline_user_functions(
222222
self.model._splines, self._get_index("p")
223223
)
224224
)

python/sdist/amici/importers/antimony/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ def antimony2sbml(ant_model: str | Path) -> str:
5151
def antimony2amici(ant_model: str | Path, *args, **kwargs):
5252
"""Convert Antimony model to AMICI model.
5353
54-
Converts the Antimony model provided as string of file to SBML and then imports it into AMICI.
54+
Converts the Antimony model provided as string or file to SBML and then
55+
imports it into AMICI.
5556
56-
For documentation see :meth:`amici.sbml_import.SbmlImporter.sbml2amici`.
57+
For documentation see :meth:`amici.importers.sbml.SbmlImporter.sbml2amici`.
5758
"""
5859
from amici.importers.sbml import SbmlImporter
5960

python/sdist/amici/importers/petab/v1/sbml_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def import_model_sbml(
332332
sbml_model,
333333
discard_annotations=discard_sbml_annotations,
334334
)
335-
sbml_model = sbml_importer.sbml
335+
sbml_model = sbml_importer.sbml_model
336336

337337
allow_n_noise_pars = (
338338
not petab.lint.observable_table_has_nontrivial_noise_formula(

python/sdist/amici/importers/pysb/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,16 @@ def pysb2amici(
180180
.. warning::
181181
**PySB models with Compartments**
182182
183-
When importing a PySB model with ``pysb.Compartment``\ s, BioNetGen
184-
scales reaction fluxes with the compartment size. Instead of using the
183+
When importing a PySB model with ``pysb.core.Compartment``\ s,
184+
BioNetGen scales reaction fluxes with the compartment size.
185+
Instead of using the
185186
respective symbols, the compartment size Parameter or Expression is
186187
evaluated when generating equations. This may lead to unexpected
187188
results if the compartment size parameter is changed for AMICI
188189
simulations.
189190
190191
:param model:
191-
pysb model, :attr:`pysb.Model.name` will determine the name of the
192+
pysb model, :attr:`pysb.core.Model.name` will determine the name of the
192193
generated module
193194
194195
:param output_dir:
@@ -197,7 +198,7 @@ def pysb2amici(
197198
:param observation_model:
198199
The different measurement channels that make up the observation
199200
model, see also :class:`amici.importers.utils.MeasurementChannel`.
200-
The ID is expected to be the name of a :class:`pysb.Expression` or
201+
The ID is expected to be the name of a :class:`pysb.core.Expression` or
201202
:class:`pysb.Observable` in the provided model that should be mapped to
202203
an observable.
203204
``sigma`` is expected to be the name of a :class:`pysb.Expression` to

0 commit comments

Comments
 (0)