Bug Description
UnassignedVariableError.__init__ sets free_variables to expression.variables(), which returns every variable in the tree whether or not it holds a value. Evaluate an expression over one bound and one unbound variable and the error reports both, and its message lists both as unassigned, so the caller is sent to fix a variable that is already fine. The attribute's own docstring says it holds "The unbound variables that caused the failure". Filtering expression.variables() down to the ones whose value is UNASSIGNED would fix the attribute and the message together.
Minimal Reproducible Example
p = qp.QProgram()
amp, freq = p.variable("amp"), p.variable("freq")
amp.set_value(0.5)
try:
(amp * freq).evaluate_or_raise()
except qp.UnassignedVariableError as e:
print(sorted(v.id for v in e.free_variables))
print(e)
Expected Behavior
free_variables holds only freq, the one variable with no value, and the message names only that variable.
Actual Behavior
['amp', 'freq']
Cannot evaluate expression (Variable('amp') * Variable('freq')): unassigned variable(s) {Variable('freq'), Variable('amp')}
System Information
qprogram 0.1.0
python 3.14.3 | Linux-7.0.0-30-generic-x86_64-with-glibc2.43
vendors none
Bug Description
UnassignedVariableError.__init__setsfree_variablestoexpression.variables(), which returns every variable in the tree whether or not it holds a value. Evaluate an expression over one bound and one unbound variable and the error reports both, and its message lists both as unassigned, so the caller is sent to fix a variable that is already fine. The attribute's own docstring says it holds "The unbound variables that caused the failure". Filteringexpression.variables()down to the ones whosevalue is UNASSIGNEDwould fix the attribute and the message together.Minimal Reproducible Example
Expected Behavior
free_variablesholds onlyfreq, the one variable with no value, and the message names only that variable.Actual Behavior
System Information
qprogram 0.1.0 python 3.14.3 | Linux-7.0.0-30-generic-x86_64-with-glibc2.43 vendors none