8 quantities: List[Union[str, int]],
9 include_auxiliary_variables: bool =
False,
13 Translate names and indices of the entries of Q into sorted indices
15 @param solver: exahype2.api.Solver
16 The solver whose entries of Q we refer to.
18 @param quantities: List[str or int]
19 A string is the name of a variable as passed to the solver (e.g.
20 "lapse" or "G" for exagrype.api.CCZ4Solver) and selects all of its
21 entries. An int is the index of one entry of Q. The list must not be
24 @param include_auxiliary_variables: bool
25 If False, only the unknowns can be selected. Otherwise, the auxiliary
26 variables can be selected, too.
29 Sorted indices without duplicates.
32 entries = solver.unknowns + (
33 solver.auxiliary_variables
if include_auxiliary_variables
else 0
35 if len(quantities) == 0:
36 raise ValueError(f
"Solver {solver.name}: the list of quantities is empty")
37 names = solver.variable_names_per_entry()[:entries]
39 for quantity
in quantities:
40 if isinstance(quantity, bool)
or not isinstance(quantity, (int, str)):
42 f
"Solver {solver.name}: quantities have to be names (str) or "
43 f
"indices (int) of entries of Q, but got {quantity!r}"
45 if isinstance(quantity, int):
46 if not 0 <= quantity < entries:
48 f
"Solver {solver.name}: quantity index {quantity} is out of "
49 f
"range, as only {entries} entries can be selected"
55 for index, name
in enumerate(names)
56 if name == quantity
or name.startswith(quantity +
"[")
60 f
"Solver {solver.name}: {quantity!r} is not the name of a "
61 f
"variable which can be selected. Available names are "
62 f
"{sorted(set(name.split('[')[0] for name in names))}."
64 indices.update(matches)
65 return sorted(indices)