WIP: Add tree printer
Related to #61.
Should not be merged until the
coroutines branch is merged.
This adds a textual printer utility to visualise component connections as trees. We should clarify though whether this should show all components, not just optical ones, and the user interface (whether
Model.tree is appropriate, whether it should show all types of connection including node couplings or just optical/electrical ones, etc.).
EDIT: from our meeting: this should show all types of component, including electrical, but be configurable to display only certain types. Make it open enough that we can modify its format later as we use it and find what we like and don't like.
from finesse import Model from finesse.components import Beamsplitter, Laser, Mirror from finesse.paths import Tree ifo = Model() ifo.chain(Laser('lsr'), Beamsplitter('bs')) # connecting YARM to BS ifo.connect( ifo.bs.p2, Mirror('itmy') ) ifo.connect( ifo.itmy, Mirror('etmy'), ) # connecting XARM to BS ifo.connect( ifo.bs.p3, Mirror('itmx'), ) ifo.connect( ifo.itmx, Mirror('etmx'), ) tree = ifo.tree(ifo.lsr) print(tree)
└── lsr └── bs (lsr.p1 -> bs.p1) ├── itmy (bs.p2 -> itmy.p1) │ └── etmy (itmy.p2 -> etmy.p1) └── itmx (bs.p3 -> itmx.p1) └── etmx (itmx.p2 -> etmx.p1)
└── bs ├── lsr (bs.p1 -> lsr.p1) ├── itmy (bs.p2 -> itmy.p1) │ └── etmy (itmy.p2 -> etmy.p1) └── itmx (bs.p3 -> itmx.p1) └── etmx (itmx.p2 -> etmx.p1)
I bumped NetworkX to v2.4 to get access to a function that was there, but I don't use this any more so I could remove this if it causes any other issues.