OK. When I change the line to compute the loss function using the array interface:
loss += (sol[1,i]-1.0)^2
There is no error and the solution of the optimization proceeds. It is not quite what I wanted, in general, but it works. I still don’t understand why the value for the ‘loss’ is a different value than the example. But, for now, this is solved.