# A Simple Example¶

The best way to familiarise yourself with Finesse is with example models. In this section we will cover the simple case of modelling resonances in a Fabry-Perot cavity as a starting point.

## The Optical Configuration¶

In the figure below we show the layout that we want to model. This consists of an input laser incident upon a two-mirror optical cavity. Measuring the reflected, transmitted and circulating power requires the use of three photodiodes - PDrefl, PDtrans and PDcirc, respectively.

To find the resonances of this cavity we can either change the tuning(s) of the mirrors or scan over the frequency of the input laser. In this case we will alter the tuning of the input test mass (ITM) in the range $$\phi_{\mathrm{ITM}} \in [-180^{\circ}, 180^{\circ}]$$ to show multiple (repeated) resonances.

## The Finesse Model¶

To represent the above layout with a Finesse model we can write the following Python code:

import finesse

kat = finesse.Model()
kat.parse("""
# add a Laser named L0 with a power of 1 W
l L0 P=1

# space attaching L0 <-> ITM with length of 0 m (default)
s s0 L0.p1 ITM.p1

# input mirror of cavity
m ITM R=0.99 T=0.01

# intra-cavity space with length of 1 m
s CAV ITM.p2 ETM.p1 L=1

# end mirror of cavity
m ETM R=0.99 T=0.01

# scan over the detuning DOF of ITM from -180 deg to +180 deg with 400 points.
xaxis &ITM.phi lin (-180) (180) 400

# power detectors on reflection, circulation and transmission
pd refl ITM.p1.o
pd circ ETM.p1.i
pd trns ETM.p2.o
""")


This creates a model of a Fabry-Perot cavity with a length of 1 metre and equal reflectivities on both the input mirror and end mirror. The input laser power is set to 1 W.

## Plotting the Outputs¶

To run this model and plot the outputs from the power-detectors we can simply write:

Todo

The semicolon below is used to stop the stdout output from plot() below. Ideally it should be removed, e.g. once there is a way in jupyter-sphinx to suppress stdout. See https://github.com/jupyter/jupyter-sphinx/issues/109.

out = kat.run()
out.plot(logy=True);


The logy flag passed to the plot method here tells the plotting routines to use a log-scale on the y-axis of any produced figures.

## Printing Model Information¶

A quick summary of the model can be retrieved by printing it:

print(kat)

Model (λ=1064 nm, untraced, unbuilt) with:
- 1 optical mode
- 3 components
- 3 detectors
- 0 cavities
- 0 locking loops


## Printing Component Connections¶

It is often useful to show the connections between components as a tree, with components as nodes and connected components as branches. Such a tree can be printed in the following way:

print(kat.component_tree(kat.L0))

○ L0
╰──○ ITM
╰──○ ETM


The argument to component_tree() is the component to start from (the tree’s root). Any component in the model can be the tree root.

Note

Models that contain cyclic connections (such as Sagnac interferometers) will not show one of the connections that would create the cycle, to prevent infinite recursion.