How to adaptively sample a function with vector input and output?

32 Views Asked by At

I'm trying to adaptively sample a function using adaptive.

Code:

import adaptive

def measure(setpoints: Union[float, np.ndarray]) -> Union[float, np.ndarray]:
    for setpoint in setpoints:
        measurement_schedule.add(setpoint)

    prepare_device(measurement_schedule)
    measurement_data = start_measurement()

    return measurement_data 

learner = adaptive.Learner1D(measure, bounds=(-1, 1))
runner = adaptive.Runner(learner, loss_goal=0.01)

where measurement_data has the same shape as setpoints. If the input and output are just scalars, it works fine with adaptive. However, prepare_device() takes quite a while, so I want to accelerate by using vector input/output to minimize the number of calls of prepare_device(). Multiprocessing is not feasible as there is only one device. Any idea how to do this by adaptive, or is there any other Python package that can do this?

I see that adaptive natively supports multiprocessing, so from the aspect of algorithm it should be possible to do this in theory.

0

There are 0 best solutions below