Fitting a simple function

Analog blocks can be parametrized in the usual Qadence manner. Like any other parameters, they can be optimized. The next snippet examplifies the creation of an analog and parameterized ansatz to fit a simple function. First, define a register and feature map block. We again use a default spacing of \(8~\mu\text{m}\) as done in the basic tutorial.

Next, we define the ansatz with parameterized rotations.

We define the measured observable as the total magnetization, and build the QuantumModel.

Now we can define the function to fit as well as our training and test data.

Finally we define a simple loss function and training loop.

And with the model trained we can plot the final results.

y_pred_final = model.expectation({"x": x_test}).detach()

plt.plot(x_test, y_pred_initial, label = "Initial prediction")
plt.plot(x_test, y_pred_final, label = "Final prediction")
plt.scatter(x_train, y_train, label = "Training points")
2024-06-16T15:43:01.997341 image/svg+xml Matplotlib v3.7.5, https://matplotlib.org/