tfq.get_unitary_op
Stay organized with collections
Save and categorize content based on your preferences.
Get an op that calculates the unitary matrix for the given circuits.
tfq.get_unitary_op(
quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()
)
unitary_op = tfq.get_unitary_op()
qubit = cirq.GridQubit(0, 0)
symbol = sympy.Symbol('alpha')
my_circuit = cirq.Circuit(cirq.H(qubit) ** symbol)
tensor_circuit = tfq.convert_to_tensor([my_circuit])
unitary_op(tensor_circuit, ['alpha'], [[0.2]])
<tf.RaggedTensor [
[[(0.9720+0.0860j), (0.0675-0.2078j)],
[(0.0675-0.2078j), (0.8369+0.5017j)]]]>
Args |
quantum_concurrent
|
Optional Python bool . True indicates that the
returned op should not block graph level parallelism on itself when
executing. False indicates that graph level parallelism on itself
should be blocked. Defaults to value specified in
tfq.get_quantum_concurrent_op_mode which defaults to True
(no blocking). This flag is only needed for advanced users when
using TFQ for very large simulations, or when running on a real
chip.
|
Returns |
A callable with the following signature:
op(programs, symbol_names, symbol_values)
|
programs
|
tf.Tensor of strings with shape [batch_size] containing
the string representations of the circuits to be executed.
|
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, , ]
that holds the unitary matrix for each circuit (after resolving
the corresponding parameters in).
|
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.get_unitary_op\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_unitary_op.py#L24-L81) |\n\nGet an op that calculates the unitary matrix for the given circuits. \n\n tfq.get_unitary_op(\n quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()\n )\n\n unitary_op = tfq.get_unitary_op()\n qubit = cirq.GridQubit(0, 0)\n symbol = sympy.Symbol('alpha')\n my_circuit = cirq.Circuit(cirq.H(qubit) ** symbol)\n tensor_circuit = tfq.convert_to_tensor([my_circuit])\n unitary_op(tensor_circuit, ['alpha'], [[0.2]])\n \u003ctf.RaggedTensor [\n [[(0.9720+0.0860j), (0.0675-0.2078j)],\n [(0.0675-0.2078j), (0.8369+0.5017j)]]]\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `quantum_concurrent` | Optional Python `bool`. True indicates that the returned op should not block graph level parallelism on itself when executing. False indicates that graph level parallelism on itself should be blocked. Defaults to value specified in [`tfq.get_quantum_concurrent_op_mode`](../tfq/get_quantum_concurrent_op_mode) which defaults to True (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| A `callable` with the following signature: \u003cbr /\u003e `op(programs, symbol_names, symbol_values)` ||\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 executed. |\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| `Returns` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with shape \\[batch_size, , \\] that holds the unitary matrix for each circuit (after resolving the corresponding parameters in). |\n\n\u003cbr /\u003e"]]