pymixef.pharmacometrics.dsl module¶
Typed, introspectable declarations for pharmacometric models.
This module provides a small Python-native declaration language. Arithmetic
builds immutable expression trees; it is not evaluated with eval and it
does not embed optimizer-specific control statements.
The model() decorator intentionally does not claim that arbitrary
Python functions are safe to inspect. A decorated function is executed lazily
when it is compiled, just like any other Python function. Projects that must
inspect untrusted model text should deserialize a validated model IR instead of
importing and executing that text. Once compiled, the returned
CompiledModel is data-only and fully introspectable.
- class pymixef.pharmacometrics.dsl.CompiledModel(name, parameters=(), etas=(), states=(), symbols=(), doses=(), equations=(), observations=(), schema_version='1.0', authoring_mode='executed-python-declarations')[source]¶
Bases:
objectData-only pharmacometric model declaration.
- Parameters:
name (str)
parameters (tuple[Param, ...])
etas (tuple[Eta, ...])
states (tuple[State, ...])
symbols (tuple[Symbol, ...])
doses (tuple[Dose, ...])
equations (tuple[DifferentialEquation, ...])
observations (tuple[Observation, ...])
schema_version (str)
authoring_mode (str)
- name: str¶
- equations: tuple[DifferentialEquation, ...]¶
- observations: tuple[Observation, ...]¶
- schema_version: str¶
- authoring_mode: str¶
- to_ir()[source]¶
Compile this declaration into the common, versioned
ModelIR.Only expression and residual-error operations with defined semantic mappings are accepted. Custom operations fail here rather than being reduced to an opaque string that a backend could misinterpret.
- Return type:
- validate(*, raise_on_error=False)[source]¶
Validate names, equation coverage, mappings, and engine readiness.
- Parameters:
raise_on_error (bool)
- Return type:
- exception pymixef.pharmacometrics.dsl.DSLValidationError[source]¶
Bases:
ValueErrorRaised when declarations do not form a valid pharmacometric model.
- code = 'DSL-INVALID-001'¶
- class pymixef.pharmacometrics.dsl.DifferentialEquation(state, expression)[source]¶
Bases:
objectOne first-order ODE declaration.
- class pymixef.pharmacometrics.dsl.Dose(state, amount='AMT', rate='RATE', duration='DUR', compartment='CMT', lag=None, bioavailability=None, route='iv')[source]¶
Bases:
objectMapping from canonical event fields to a model state.
- Parameters:
state (State)
amount (str)
rate (str | None)
duration (str | None)
compartment (str)
lag (str | float | None)
bioavailability (str | float | None)
route (str)
- amount: str¶
- rate: str | None¶
- duration: str | None¶
- compartment: str¶
- lag: str | float | None¶
- bioavailability: str | float | None¶
- route: str¶
- class pymixef.pharmacometrics.dsl.Eta(name, block, covariance='diagonal', level='subject')[source]¶
Bases:
_SymbolicA named random effect and its covariance-block declaration.
- Parameters:
name (str)
block (str)
covariance (Literal['correlated', 'diagonal'])
level (str)
- name: str¶
- block: str¶
- covariance: Literal['correlated', 'diagonal']¶
- level: str¶
- Parameters:
names (str)
block (str | None)
level (str)
- Return type:
tuple[Eta, …]
- class pymixef.pharmacometrics.dsl.Expr(operation, arguments=(), value=None, metadata=<factory>)[source]¶
Bases:
objectAn immutable symbolic expression node.
- Parameters:
operation (str)
arguments (tuple[Expr, ...])
value (float | str | None)
metadata (Mapping[str, Any])
- operation: str¶
- value: float | str | None¶
- metadata: Mapping[str, Any]¶
- class pymixef.pharmacometrics.dsl.ModelDefinition(function, *, name=None)[source]¶
Bases:
objectLazy wrapper produced by
model().Calling or compiling it executes the original Python declaration function once per call in an isolated context. This behavior is explicit in
CompiledModel.authoring_mode.- Parameters:
function (Callable[..., Any])
name (str | None)
- to_ir(*args, **kwargs)[source]¶
Compile the declaration into the common versioned model IR.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
- property declaration_signature: str¶
- class pymixef.pharmacometrics.dsl.ModelValidation(valid, messages, dimensions, estimator_compatibility)[source]¶
Bases:
objectDry-run validation report for a compiled model.
- Parameters:
valid (bool)
messages (tuple[ValidationMessage, ...])
dimensions (Mapping[str, int])
estimator_compatibility (Mapping[str, bool])
- valid: bool¶
- messages: tuple[ValidationMessage, ...]¶
- dimensions: Mapping[str, int]¶
- estimator_compatibility: Mapping[str, bool]¶
- class pymixef.pharmacometrics.dsl.Observation(endpoint, mean, error, censored_below=None, censored_above=None, metadata=<factory>)[source]¶
Bases:
objectAn endpoint, prediction expression, and residual-error declaration.
- Parameters:
endpoint (str)
mean (Expr)
error (Any)
censored_below (str | float | None)
censored_above (str | float | None)
metadata (Mapping[str, Any])
- endpoint: str¶
- error: Any¶
- censored_below: str | float | None¶
- censored_above: str | float | None¶
- metadata: Mapping[str, Any]¶
- class pymixef.pharmacometrics.dsl.Param(name, init, constraint='real', lower=None, upper=None, unit=None, description=None)[source]¶
Bases:
_SymbolicA population parameter with an explicit natural-scale constraint.
- Parameters:
name (str)
init (float)
constraint (Literal['real', 'positive', 'bounded'])
lower (float | None)
upper (float | None)
unit (str | None)
description (str | None)
- name: str¶
- init: float¶
- constraint: Literal['real', 'positive', 'bounded']¶
- lower: float | None¶
- upper: float | None¶
- unit: str | None¶
- description: str | None¶
- classmethod real(name, *, init=0.0, unit=None, description=None)[source]¶
- Parameters:
name (str)
init (float)
unit (str | None)
description (str | None)
- Return type:
- classmethod positive(name, *, init, unit=None, description=None)[source]¶
- Parameters:
name (str)
init (float)
unit (str | None)
description (str | None)
- Return type:
- class pymixef.pharmacometrics.dsl.State(name, unit=None, initial=0.0)[source]¶
Bases:
_SymbolicAn ODE state/compartment declaration.
- Parameters:
name (str)
unit (str | None)
initial (float)
- name: str¶
- unit: str | None¶
- initial: float¶
- class pymixef.pharmacometrics.dsl.Symbol(name, role='covariate', unit=None, reference=None)[source]¶
Bases:
_SymbolicA named covariate or external model input.
- Parameters:
name (str)
role (str)
unit (str | None)
reference (float | str | None)
- name: str¶
- role: str¶
- unit: str | None¶
- reference: float | str | None¶
- class pymixef.pharmacometrics.dsl.ValidationMessage(code, severity, message)[source]¶
Bases:
objectOne coded severity and message emitted by dry-run model validation.
- Parameters:
code (str)
severity (Literal['error', 'warning', 'info'])
message (str)
- code: str¶
- severity: Literal['error', 'warning', 'info']¶
- message: str¶
- pymixef.pharmacometrics.dsl.as_expr(value)[source]¶
Convert declarations and numeric constants to an expression node.
- pymixef.pharmacometrics.dsl.compiled_model(name, *, parameters=(), etas=(), states=(), symbols=(), doses=(), equations=(), observations=(), validate=True)[source]¶
Build a data-only model directly, without executing a declaration function.
- Parameters:
name (str)
parameters (Sequence[Param])
etas (Sequence[Eta])
states (Sequence[State])
symbols (Sequence[Symbol])
doses (Sequence[Dose])
equations (Sequence[DifferentialEquation])
observations (Sequence[Observation])
validate (bool)
- Return type:
- pymixef.pharmacometrics.dsl.covariate(name, *, unit=None, reference=None)[source]¶
Declare a covariate symbol.
- Parameters:
name (str)
unit (str | None)
reference (float | str | None)
- Return type:
- pymixef.pharmacometrics.dsl.d(state, expression)[source]¶
Short alias for
derivative().Python does not permit the illustrative syntax
d(state) = expression; PyMixEF therefore usesd(state, expression)orstate.derivative(expression).- Parameters:
- Return type:
- pymixef.pharmacometrics.dsl.derivative(state, expression)[source]¶
Declare a state derivative in the active model.
- Parameters:
- Return type:
- pymixef.pharmacometrics.dsl.exp(value)[source]¶
Build a symbolic exponential expression without evaluating
value.
- pymixef.pharmacometrics.dsl.log(value)[source]¶
Build a symbolic natural-log expression without checking its domain.
- pymixef.pharmacometrics.dsl.log1p(value)[source]¶
Build a symbolic
log(1 + value)expression without evaluating it.
- pymixef.pharmacometrics.dsl.model(function: Callable[[P], R], /) ModelDefinition[source]¶
- pymixef.pharmacometrics.dsl.model(*, name: str | None = None) Callable[[Callable[[P], R]], ModelDefinition]
Decorate a Python function as a lazy model declaration.
- pymixef.pharmacometrics.dsl.observe(endpoint, *, mean, error, censored_below=None, censored_above=None, metadata=None)[source]¶
Declare an observation endpoint in the active model.
- Parameters:
endpoint (str)
mean (Expr | _Symbolic | int | float | number)
error (Any)
censored_below (str | float | None)
censored_above (str | float | None)
metadata (Mapping[str, Any] | None)
- Return type: