Convert lists of tfq supported primitives to tensor representations.
tfq.convert_to_tensor(
items_to_convert, deterministic_proto_serialize=False
)
Used in the notebooks
Recursively convert a nested lists of cirq.PauliSum
or cirq.Circuit
objects to a tf.Tensor
representation. Note that cirq serialization only
supports cirq.GridQubit
s so we also require that input circuits and
pauli sums are defined only on cirq.GridQubit
s.
my_qubits = cirq.GridQubit.rect(1, 2)
my_circuits = [cirq.Circuit(cirq.X(my_qubits[0])),
cirq.Circuit(cirq.Z(my_qubits[0]))
]
tensor_input = tfq.convert_to_tensor(my_circuits)
# Now tensor_input can be used as model input etc.
same_circuits = tfq.from_tensor(tensor_input)
# same_circuits now holds cirq.Circuit objects once more.
same_circuits
[cirq.Circuit([
cirq.Moment(operations=[
cirq.X.on(cirq.GridQubit(0, 0)),
]),
])
cirq.Circuit([
cirq.Moment(operations=[
cirq.Z.on(cirq.GridQubit(0, 0)),
]),
])]
Args |
items_to_convert
|
Python list or nested list of cirq.Circuit
or cirq.Paulisum objects. Must be recangular.
|
deterministic_proto_serialize
|
Whether to use a deterministic
serialization when calling SerializeToString().
|
Returns |
A tf.Tensor that represents the input items.
|
Raises |
TypeError
|
In case of invalid arguments provided in items_to_convert .
|