1

I have been writing some code for automatically aligning my fiber (whose X, Y, Z positions are controlled by a motor) to a light source. For this I have written my axis.move_to(pos) method to move an axis to a position, and a pm.meas_power() method to measure optical power from my power meter.

My goal is to find the optimal (Y, Z) position (X is not needed at this stage) to maximise the optical power. Now, the search area is quite big compared to the light spot size, so a simple gradient search would not help if I start in an area where only noise is found, so what I do is randomly move across the search area, and move to a hill climbing algorithm as soon as I find a power higher than a certain threshold.

Problem with this, is that it's quite inefficient. A first approach to optimisation would be to search for first light in a spiral rather than randomly, but computationally it does not really improve the number of steps.

I have come across, instead, the simplex algorithm, which supposedly yields much better results than hill climbing. I found out that scipy has a optimize.linprog() method which has a simplex algorithm, but it seems to me that this works for a 1D problem only.

I tried to read the documentation and write my own code, but I know little about optimisation so I was having a hard time really understanding how that works.

I was wondering whether you could help me write an algorithm given [ystart, zstart, yend, zend], i.e. the search area limits, and my two methods axis.move_to(pos) and pm.meas_power():

from labFunctions import PowerMeter, MotorAxis

pm = PowerMeter('pm_address')
yaxis = MotorAxis('y_address')
zaxis = MotorAxis('z_address')

limits = [ystart, zstart, yend, zend] # These can be formatted differently if needed
Enzo
  • 338
  • 1
  • 2
  • 15

2 Answers2

2

Unfortunately, there are two very different Simplex methods:

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
  • That is a very helpful clarification. My only concern now is that I don't have a function, but a series of measurements, so I am unsure as to what to feed the `fun` parameter. I will try to read some more about this. Can I just use my `pm.power` as `fun`? – Enzo Sep 13 '21 at 14:28
  • Write a new function with the correct signature. Call pm.power from there. – Erwin Kalvelagen Sep 14 '21 at 09:08
1

I think your problem is physical and thus you are asking in the wrong forum. nevertheless, i will attempt an answer.

if you are trying to match the TEM00 mode of the laser, your algorithm of hill climbing after reaching a threshold power is a very good refinement strategy, since the power profile does not have any other maxima.

Concerning the random search, I think if you are unable to physically constrain the search space, you might as well do a random search on an equidistant grid with grid points about half the laser spot size.

Colin Teo
  • 11
  • 1
  • The issue is not really a physical one, as I already know the beam profile and its properties. What I am trying to do is developing an algorithm which is more efficient than simple hill-climbing, as the approach I am currently using is quite slow, hence my question about Simplex – Enzo Sep 13 '21 at 14:26