tfq.optimizers.rotosolve_minimize
Stay organized with collections
Save and categorize content based on your preferences.
Applies the rotosolve algorithm.
tfq.optimizers.rotosolve_minimize(
expectation_value_function,
initial_position,
tolerance=1e-05,
max_iterations=50,
name=None
)
The rotosolve algorithm can be used to minimize a linear combination
of quantum measurement expectation values. See the following paper:
arXiv:1903.12166, Ken M. Nakanishi.
arXiv:1905.09692, Mateusz Ostaszewski.
Usage:
Here is an example of optimize a function which consists summation of
a few sinusoids.
n = 10 # Number of sinusoids
coefficient = tf.random.uniform(shape=[n])
min_value = -tf.math.reduce_sum(tf.abs(coefficient))
func = lambda x:tf.math.reduce_sum(tf.sin(x) * coefficient)
# Optimize the function with rotosolve, start with random parameters
result = tfq.optimizers.rotosolve_minimize(func, np.random.random(n))
result.converged
tf.Tensor(True, shape=(), dtype=bool)
result.objective_value
tf.Tensor(-4.7045116, shape=(), dtype=float32)
Args |
expectation_value_function
|
A Python callable that accepts
a point as a real tf.Tensor and returns a tf.Tensor s
of real dtype containing the value of the function.
The function to be minimized. The input is of shape [n] ,
where n is the size of the trainable parameters.
The return value is a real tf.Tensor Scalar (matching shape
[1] ). This must be a linear combination of quantum
measurement expectation value, otherwise this algorithm cannot
work.
|
initial_position
|
Real tf.Tensor of shape [n] . The starting
point, or points when using batching dimensions, of the search
procedure. At these points the function value and the gradient
norm should be finite.
|
tolerance
|
Scalar tf.Tensor of real dtype. Specifies the tolerance
for the procedure. If the supremum norm between two iteration
vector is below this number, the algorithm is stopped.
|
name
|
(Optional) Python str . The name prefixed to the ops created
by this function. If not supplied, the default name 'minimize'
is used.
|
Returns |
optimizer_results
|
A RotosolveOptimizerResults object contains the
result of the optimization process.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-05-17 UTC.
[null,null,["Last updated 2024-05-17 UTC."],[],[],null,["# tfq.optimizers.rotosolve_minimize\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/quantum/blob/v0.7.3/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py#L109-L274) |\n\nApplies the rotosolve algorithm. \n\n tfq.optimizers.rotosolve_minimize(\n expectation_value_function,\n initial_position,\n tolerance=1e-05,\n max_iterations=50,\n name=None\n )\n\nThe rotosolve algorithm can be used to minimize a linear combination\n\nof quantum measurement expectation values. See the following paper:\n\n[arXiv:1903.12166](https://arxiv.org/abs/1903.12166), Ken M. Nakanishi.\n[arXiv:1905.09692](https://arxiv.org/abs/1905.09692), Mateusz Ostaszewski.\n\n#### Usage:\n\nHere is an example of optimize a function which consists summation of\na few sinusoids. \n\n n = 10 # Number of sinusoids\n coefficient = tf.random.uniform(shape=[n])\n min_value = -tf.math.reduce_sum(tf.abs(coefficient))\n func = lambda x:tf.math.reduce_sum(tf.sin(x) * coefficient)\n # Optimize the function with rotosolve, start with random parameters\n result = tfq.optimizers.rotosolve_minimize(func, np.random.random(n))\n result.converged\n tf.Tensor(True, shape=(), dtype=bool)\n result.objective_value\n tf.Tensor(-4.7045116, shape=(), dtype=float32)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `expectation_value_function` | A Python callable that accepts a point as a real [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) and returns a [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor)s of real dtype containing the value of the function. The function to be minimized. The input is of shape `[n]`, where `n` is the size of the trainable parameters. The return value is a real [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) Scalar (matching shape `[1]`). This must be a linear combination of quantum measurement expectation value, otherwise this algorithm cannot work. |\n| `initial_position` | Real [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of shape `[n]`. The starting point, or points when using batching dimensions, of the search procedure. At these points the function value and the gradient norm should be finite. |\n| `tolerance` | Scalar [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of real dtype. Specifies the tolerance for the procedure. If the supremum norm between two iteration vector is below this number, the algorithm is stopped. |\n| `name` | (Optional) Python `str`. The name prefixed to the ops created by this function. If not supplied, the default name 'minimize' is used. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---------------------|-------------------------------------------------------------------------------------|\n| `optimizer_results` | A RotosolveOptimizerResults object contains the result of the optimization process. |\n\n\u003cbr /\u003e"]]