Is there the latest version of the quantum circuit structure learning demo

I tried replacing ansatz in

to make it more complicated, but failed. But

states that it can be achieved with qml.RotoselectOptimizer and qml.RotosolveOptimizer. So I tried the following,

paras =
for i in range(3 * dims * numbers):
paras.append(np.random.random() * np.pi)
print(paras, type(paras))
init_params = np.array(paras, requires_grad=True)
params_rsol = init_params.copy()

n_steps = 30

costs_rotosolve =

for i in range(n_steps):
costs_rotosolve.append(cost(params_rsol, generators))
params_rsol, generators = opt.step(cost, params_rsol, generators)

TypeError Traceback (most recent call last)
Input In [102], in <cell line: 40>()
40 for i in range(n_steps):
41 costs_rotosolve.append(cost(params_rsol, generators))
—> 42 params_rsol, generators = opt.step(cost, params_rsol, generators)
44 ‘’’
45 params_gd = init_params.copy()
46 opt = qml.GradientDescentOptimizer(stepsize=0.5)
(…)
54 import matplotlib.pyplot as plt
55 ‘’’
57 costs_rotosolve =

File d:\Miniconda3\envs\test0\lib\site-packages\pennylane\optimize\rotoselect.py:148, in RotoselectOptimizer.step(self, objective_fn, x, generators, **kwargs)
143 raise ValueError(
144 f"Number of parameters {x} must be equal to the number of generators."
145 ) from e
147 for d, _ in enumerate(x_flat):
–> 148 x_flat[d], generators[d] = self._find_optimal_generators(
149 objective_fn_flat, x_flat, generators, d
150 )
152 return unflatten(x_flat, x), generators

File d:\Miniconda3\envs\test0\lib\site-packages\pennylane\optimize\rotoselect.py:180, in RotoselectOptimizer._find_optimal_generators(self, objective_fn, x, generators, d)
177 for generator in self.possible_generators:
178 generators[d] = generator
–> 180 x = self._rotosolve(objective_fn, x, generators, d)
181 params_cost = objective_fn(x, generators)
183 # save the best paramter and generator for position d

File d:\Miniconda3\envs\test0\lib\site-packages\pennylane\optimize\rotoselect.py:215, in RotoselectOptimizer._rotosolve(objective_fn, x, generators, d)
212 x[d] = theta
213 return x
–> 215 H_0 = float(objective_fn(insert(x, d, 0), generators))
216 H_p = float(objective_fn(insert(x, d, np.pi / 2), generators))
217 H_m = float(objective_fn(insert(x, d, -np.pi / 2), generators))

TypeError: only size-1 arrays can be converted to Python scalars

Can the official provide a more complex ansatz circuit structure optimization case? As a novice, I really want to learn

Hi @RX1, thank you for your question!

I can’t see which are your parameters and your ‘costs_rotosolve’. Could you please post your full code here?

It will help us answer your question!