tfq.resolve_parameters
Stay organized with collections
Save and categorize content based on your preferences.
Replace symbols in a batch of programs with concrete values.
tfq.resolve_parameters(
programs, symbol_names, symbol_values
)
Used in the notebooks
This function has the ability to partially resolve parameters, so that
symbol_names
can contain fewer symbols than programs
; symbols not listed
remain unresolved in the output programs. Note also that because the output
of this function has type string, the function is not differentiable.
qubit = cirq.GridQubit(0, 0)
symbol = sympy.Symbol('alpha')
my_c = cirq.Circuit(cirq.H(qubit) ** symbol)
tensor_c = tfq.convert_to_tensor([my_c])
tfq.from_tensor(tfq.resolve_parameters(tensor_c, ['alpha'], [[0.2]]))
[(0, 0): ───H^0.2───]
Args |
programs
|
tf.Tensor of strings with shape [batch_size] containing
the string representations of the circuits to be resolved.
|
symbol_names
|
tf.Tensor of strings with shape [n_params], which
is used to specify the order in which the values in
symbol_values should be placed inside of the circuits in
programs .
|
symbol_values
|
tf.Tensor of real numbers with shape
[batch_size, n_params] specifying parameter values to resolve
into the circuits specified by programs, following the ordering
dictated by symbol_names .
|
Returns |
tf.Tensor with shape [batch_size]. Each entry corresponds to the
original circuit in program except with symbols listed in
symbol_names replaced with their corresponding values.
|
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.resolve_parameters\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/quantum/blob/v0.7.3/tensorflow_quantum/core/ops/tfq_utility_ops.py#L106-L141) |\n\nReplace symbols in a batch of programs with concrete values. \n\n tfq.resolve_parameters(\n programs, symbol_names, symbol_values\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|-----------------------------------------------------------------------------|\n| - [Quantum data](https://www.tensorflow.org/quantum/tutorials/quantum_data) |\n\nThis function has the ability to partially resolve parameters, so that\n`symbol_names` can contain fewer symbols than `programs`; symbols not listed\nremain unresolved in the output programs. Note also that because the output\nof this function has type string, the function is not differentiable. \n\n qubit = cirq.GridQubit(0, 0)\n symbol = sympy.Symbol('alpha')\n my_c = cirq.Circuit(cirq.H(qubit) ** symbol)\n tensor_c = tfq.convert_to_tensor([my_c])\n tfq.from_tensor(tfq.resolve_parameters(tensor_c, ['alpha'], [[0.2]]))\n [(0, 0): ───H^0.2───]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `programs` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of strings with shape \\[batch_size\\] containing the string representations of the circuits to be resolved. |\n| `symbol_names` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of strings with shape \\[n_params\\], which is used to specify the order in which the values in `symbol_values` should be placed inside of the circuits in `programs`. |\n| `symbol_values` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of real numbers with shape \\[batch_size, n_params\\] specifying parameter values to resolve into the circuits specified by programs, following the ordering dictated by `symbol_names`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with shape \\[batch_size\\]. Each entry corresponds to the original circuit in `program` except with symbols listed in `symbol_names` replaced with their corresponding values. ||\n\n\u003cbr /\u003e"]]