Using `Mirror.phi` for model with dof creates unusable state
Please check the Issue Tracker if your bug is already listed before reporting.
Summary
When a degree of freedom is associated with the microscopic position of a mirror scanning that position directly (via mirror.phi
) instead of using the degree of freedom causes an exception (this is working as intended). But if this exception is handled or the model state is otherwise used again, for example in a jupyter notebook, the degree of freedom can no longer be used.
Steps to reproduce
import finesse
import matplotlib.pyplot as plt
model = finesse.Model()
model.parse(
"""
l l1 P=1
link(l1, ITM, 1, ETM)
m ITM R=0.99 L=0
m ETM R=0.99 L=0
pd out ETM.p2.o
dof ETM_z ETM.dofs.z +1
"""
)
sol1 = model.run("xaxis(ETM_z.DC, lin, -180, 180, 100)")
try:
model.run("xaxis(ETM.phi, lin, -180, 180, 100)")
except Exception:
pass
sol2 = model.run("xaxis(ETM_z.DC, lin, -180, 180, 100)")
plt.plot(sol1.x1, sol1["out"], label="before exception")
plt.plot(sol2.x1, sol2["out"], label="after exception")
plt.legend()
plt.xlabel("ETM_z.DC [deg]")
plt.ylabel("out [W]")
plt.show()
Bug behavior
In this example a simple cavity with a length degree of freedom is defined. The first xaxis
shows the usual working state when scanning the dof. The second xaxis
attemps to use ETM.phi
directly, which fails as this is a symbolic value controlled by the dof. But the exception is caught (alternatively one could have this in a jupyter notebook, run it and then run it again after fixing the mistake). The third xaxis
produces a constant result, as the dof ETM_z
no longer works.
What is the expected correct behavior?
The model should either not be broken by this or the exception should clearly state that that is the case.
Alternatively the message for the exception could be changed to note that the model is now likely to be broken.
Relevant logs and/or screenshots
This warning is given, but as far as I can tell ETM.phi
was already not tunable before.
UserWarning: <ETM.phi=180.0 @ 0x7984f8b37c40>: setting `is_tunable` to False as new value is symbolic; is_tunable was previously True
node.DC.remove_external_setter(self, amp * self.DC.ref)
Possible Fixes
I guess that the wrong xaxis
tries to set ETM.phi
before noticing that it shouldn't do that and so breaks the symbolic value connecting it to the dof, in that case we might want to change the order, or just ensure that the model is marked as broken and running another xaxis
again raises an exception.
Labels
Please assign labels to the issue by uncommenting approiate lines:
Reproducing the bug
If cannot reproduce the bug comment out the first line and uncomment the second.
Area of the bug
If possible label the area the bug is occuring in: - Packaging (you can only use one) - Build system - Documentation - Parser (of the KatScript) Use Parser::legacy if you are parsing legacy files - Plotting - Testing (for issues with the automated tests) - User interface
Operating system
Add a label for the operating system you are using Finesse on. ~label /"OS::Linux
Urgency
If the bug is preventing Finesse from being used, for example if it produces seemingly valid but incorrect results, add this label.