tf.Tensor of strings with shape [batch_size] containing
the string representations of the circuits
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 specificed by programs, following the ordering
dictated by symbol_names.
other_programs
tf.Tensor of strings with shape [batch_size, n_others]
containing the string representations of the circuits with which to
compute the overlap on programs with. Must not contain any free
symbols.
Returns
tf.Tensor with shape [batch_size, n_others] where out[i][j] is equal
to the fidelity of programs[i] with symbol_values[i]
resolved in and other_programs[i][j].
[null,null,["Last updated 2024-05-17 UTC."],[],[],null,["# tfq.math.fidelity\n\n|----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/quantum/blob/v0.7.3/tensorflow_quantum/core/ops/math_ops/fidelity_op.py#L20-L94) |\n\nCalculate the fidelity between circuits. \n\n @tf.function\n tfq.math.fidelity(\n programs, symbol_names, symbol_values, other_programs\n )\n\nCompute (potentially many) fidelities between the given circuits and\nthe symbol free comparison circuits.\n\nCalculates out\\[i\\]\\[j\\] = $ \\| \\\\langle \\\\psi*{ ext{programs\\[i\\]} }\n( ext{symbol_values\\[i\\]}) \\| \\\\psi* { ext{other_programs\\[j\\]} }\nangle \n\n\\|\\^2 $ \n\n symbols = sympy.symbols('alpha beta')\n qubits = cirq.GridQubit.rect(1, 2)\n reference_circuits = [\n cirq.Circuit((cirq.H**symbols[0]).on_each(qubits)),\n cirq.Circuit(\n cirq.X(qubits[0]) ** symbols[0],\n cirq.Y(qubits[1]) ** symbols[1])\n ]\n other_circuits = [\n cirq.Circuit(cirq.X.on_each(qubits)),\n cirq.Circuit((cirq.Y**0.125).on_each(qubits)),\n cirq.Circuit((cirq.X**0.5).on_each(qubits))\n ]\n reference_tensor = tfq.convert_to_tensor(reference_circuits)\n symbol_tensor = tf.convert_to_tensor([s.name for s in symbols])\n values_tensor = tf.convert_to_tensor(np.arange(4).reshape(2, 2))\n other_tensor = tfq.convert_to_tensor([other_circuits, other_circuits])\n fid = tfq.math.fidelity(reference_tensor, symbol_tensor,\n values_tensor, other_tensor)\n fid\n tf.Tensor(\n [[ 0., 0.925, 0.25],\n [ 0., 0.036, 0.25]],shape=(2, 3), dtype=float32)\n\n| **Note:** `other_programs` must not contain any free symbols. These can be resolved beforehand with [`tfq.resolve_parameters`](../../tfq/resolve_parameters).\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 |\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 specificed by programs, following the ordering dictated by `symbol_names`. |\n| `other_programs` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of strings with shape \\[batch_size, n_others\\] containing the string representations of the circuits with which to compute the overlap on `programs` with. Must not contain any free symbols. |\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, n_others\\] where `out[i][j]` is equal to the fidelity of `programs[i]` with `symbol_values[i]` resolved in and `other_programs[i][j]`. ||\n\n\u003cbr /\u003e"]]