1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use *;
/// Rotosolve optimizer configuration: Ostaszewski, Grant and Benedetti's
/// closed-form coordinate update, with the value reuse of Nakanishi, Fujii and
/// Todo.
///
/// It needs a circuit in which every trainable parameter is the angle of
/// exactly one rotation generated by a single Pauli operator (`rx`, `ry`,
/// `rz`, `rxx`, `rzz`, `p`, `u1`, any angle of `u`, `u2` or `u3`, and for
/// Qiskit circuits also `ryy`, `rzx` and the angle θ of `r`), as `±θ + c`,
/// and a fitness that averages a cost per bitstring over
/// the shots. Then the fitness is a sinusoid of each parameter, and one
/// parameter at a time moves to its maximum, computed from the current point
/// and the two points `±π/2` along the parameter. `train` and `qml.train`
/// check the circuit before anything runs and raise `ValueError` naming the
/// first gate or parameter that does not qualify; `qml.train` also rejects a
/// `polypus.SampleCost`, which is not such an average.
///
/// Each step is one batch of two circuits; the step reuses the value the
/// previous one predicted for the current point, and measures the point
/// again (a third circuit) on the first step and every `reevaluate_every`
/// steps, so shot noise does not build up. A sweep visits every parameter once,
/// in order. After the last step, the point it reached is measured too, one
/// more circuit. `best_params` is the best of the points measured. The run stops
/// after `patience` consecutive sweeps that improve the best measured fitness
/// by less than `tolerance`, or after `sweeps` sweeps. The settings are
/// validated when `train`/`qml.train` starts, before any circuit runs: an
/// invalid one raises `ValueError` (contract C-5).