Have not seen much activity on PySD for a few months... nonetheless if there still are people out there looking after this would be grateful if you could take another look at how arrays are handled for XMILE.
PySD Bug Report: Wildcard Subscript [] Not Parsed in XMILE/SMILE Equations
Environment
PySD version: 3.14.3
Python: 3.10
Source format: XMILE (Stella Architect .stmx)
Entry point: pysd.read_xmile()
What fails
Any equation containing a wildcard subscript — Var[] — causes a parse failure during xmile_file.parse(). The error occurs before any model logic runs.
Triggering equation (from Total population aux):
SUM(Customers[*]) + Potential_customers
Full traceback:
File ".../xmile_element.py", line 219, in _smile_parser
tree = vu.Grammar.get("equations", parsing_ops).parse(...)
parsimonious.exceptions.IncompleteParseError: Rule 'expr_type' matched in its entirety,
but it didn't consume all the text. The non-matching portion of the text begins with
'(Customers[*]) + Pot' (line 1, column 4).
Root cause
The XMILE equation grammar (equations.peg) defines subscript_list as:
subscript_list = "[" _ (name _ "!"? _ ","? _)+ _ "]"
A name must be a valid identifier (id_start id_continue*). The * character is not in id_continue, so [] cannot match subscript_list. The parser matches SUM as a reference, then fails on (Customers[]) because * is unrecognised inside the bracket.
The Vensim grammar (components.peg) has the identical subscript_list definition, so the same gap exists there.
What [] means in SMILE / Stella
Var[] is the wildcard subscript — it refers to all elements of a dimension, used specifically as the argument to reduction functions like SUM(), PROD(), MAX(), MIN(). Stella Architect emits isee:summing/ alongside these equations to flag the intent. It is distinct from the ! (mapping) operator already handled in the grammar.
The XMILE spec (§6.5) and Stella documentation both define this syntax as valid.
Minimal reproduction
import pysd
model = pysd.read_xmile("model_with_sum_wildcard.stmx")
raises IncompleteParseError on any equation containing Var[*]
The .stmx only needs one aux with SUM(AnySubscriptedVar[*]) to trigger the failure.
Suggested fix
subscript_list in equations.peg (and the matching Vensim grammar) needs a wildcard alternative:
subscript_list = "[" _ (subscript_item _ ","? _)+ _ "]"
subscript_item = "*" / (name _ "!"?)
The AST visitor that handles subscript_list would then need to recognise * as "all elements of the dimension" and expand it, likely producing the same result as enumerating every element explicitly — equivalent to SUM(Customers[A], Customers[B], ...) for a known dimension.
Workaround (current)
We reimplemented the model equations directly in Python (simulation/model.py) using numpy arrays. SUM(Customers[*]) becomes cust.sum() where cust is a numpy.ndarray over the Customer dimension.
Have not seen much activity on PySD for a few months... nonetheless if there still are people out there looking after this would be grateful if you could take another look at how arrays are handled for XMILE.
PySD Bug Report: Wildcard Subscript [] Not Parsed in XMILE/SMILE Equations
Environment
PySD version: 3.14.3
Python: 3.10
Source format: XMILE (Stella Architect .stmx)
Entry point: pysd.read_xmile()
What fails
Any equation containing a wildcard subscript — Var[] — causes a parse failure during xmile_file.parse(). The error occurs before any model logic runs.
Triggering equation (from Total population aux):
SUM(Customers[*]) + Potential_customers Full traceback:File ".../xmile_element.py", line 219, in _smile_parser
tree = vu.Grammar.get("equations", parsing_ops).parse(...)
parsimonious.exceptions.IncompleteParseError: Rule 'expr_type' matched in its entirety,
but it didn't consume all the text. The non-matching portion of the text begins with
'(Customers[*]) + Pot' (line 1, column 4).
Root cause
The XMILE equation grammar (equations.peg) defines subscript_list as:
subscript_list = "[" _ (name _ "!"? _ ","? _)+ _ "]"
A name must be a valid identifier (id_start id_continue*). The * character is not in id_continue, so [] cannot match subscript_list. The parser matches SUM as a reference, then fails on (Customers[]) because * is unrecognised inside the bracket.
The Vensim grammar (components.peg) has the identical subscript_list definition, so the same gap exists there.
What [] means in SMILE / Stella
Var[] is the wildcard subscript — it refers to all elements of a dimension, used specifically as the argument to reduction functions like SUM(), PROD(), MAX(), MIN(). Stella Architect emits isee:summing/ alongside these equations to flag the intent. It is distinct from the ! (mapping) operator already handled in the grammar.
The XMILE spec (§6.5) and Stella documentation both define this syntax as valid.
Minimal reproduction
import pysd
model = pysd.read_xmile("model_with_sum_wildcard.stmx")
raises IncompleteParseError on any equation containing Var[*]
The .stmx only needs one aux with SUM(AnySubscriptedVar[*]) to trigger the failure.
Suggested fix
subscript_list in equations.peg (and the matching Vensim grammar) needs a wildcard alternative:
subscript_list = "[" _ (subscript_item _ ","? _)+ _ "]"
subscript_item = "*" / (name _ "!"?)
The AST visitor that handles subscript_list would then need to recognise * as "all elements of the dimension" and expand it, likely producing the same result as enumerating every element explicitly — equivalent to SUM(Customers[A], Customers[B], ...) for a known dimension.
Workaround (current)
We reimplemented the model equations directly in Python (simulation/model.py) using numpy arrays. SUM(Customers[*]) becomes cust.sum() where cust is a numpy.ndarray over the Customer dimension.