E-MD0008 — Named expression cannot be saved in the OMMX output
Error Type |
|
|---|---|
Phase |
declaring a named expression |
Python exception |
|
Message
The named expression `{name}` has type `{type_name}`, which cannot be stored as an OMMX NamedFunction.
Only the following types can be stored:
- numeric scalars
- tensors of numeric scalars
- dicts of numeric scalars with a fully known key set
Possible fix: pass `save_in_ommx=False` or change the definition to a supported type.
({name} is the name you gave the named expression; {type_name} is the type inferred for its definition, such as Tuple[float, float])
Cause
problem.NamedExpr(name, definition, save_in_ommx=True) was called, but the type inferred for definition is not one that can be stored in the OMMX output.
Only three kinds of definitions can be stored as an OMMX NamedFunction: a single numeric scalar, a tensor whose elements are numeric scalars, or a dictionary whose values are numeric scalars and whose key set is fully known.
A definition of any other type triggers this error — for example a tuple, a dictionary whose values are themselves arrays, or a dictionary whose key set is not fully known even though its values are numeric scalars.
The check runs only when save_in_ommx=True; with the default save_in_ommx=False, any definition type is accepted.
Fix
If you do not need the expression in the OMMX output, drop save_in_ommx=True (the default is False); the named expression remains fully usable inside the model either way.
Otherwise, reshape the definition into a numeric scalar, a tensor of numeric scalars, or a dict of numeric scalars with a fully known key set — for example, store the components as separate named expressions instead of one tuple:
import jijmodeling as jm
problem = jm.Problem("example")
a = problem.Placeholder("a", dtype=float, ndim=1)
# Raises E-MD0008: the definition is a tuple
# pair = problem.NamedExpr("pair", (a[0], a[1]), save_in_ommx=True)
first = problem.NamedExpr("first", a[0], save_in_ommx=True)
second = problem.NamedExpr("second", a[1], save_in_ommx=True)