Missed TensorFlow Dev Summit? Check out the video playlist. Watch recordings

tfq.get_state_op

View source on GitHub

Get a TensorFlow op that produces states from given quantum circuits.

tfq.get_state_op(
    backend=None
)

This function produces a non-differentiable op that will calculate batches of state tensors given tensor batches of cirq.Circuits and parameter values.

# Simulate circuits with cirq. 
my_op = tfq.get_state_op(backend=cirq.DensityMatrixSimulator()) 
# Simulate circuits with C++. 
my_second_op = tfq.get_state_op() 
# Prepare some inputs. 
qubit = cirq.GridQubit(0, 0) 
my_symbol = sympy.Symbol('alpha') 
my_circuit_tensor = tfq.convert_to_tensor([ 
    cirq.Circuit(cirq.Y(qubit) ** my_symbol) 
]) 
my_values = np.array([[0.5]]) 
# This op can now be run to calculate the state. 
output = my_second_op(my_circuit_tensor, ['alpha'], my_values) 
output 
<tf.RaggedTensor [[(0.5+0.5j), (0.5+0.5j)]]> 

Args:

  • backend: Optional Python object that specifies what backend this op should use when evaluating circuits. Can be any cirq.SimulatesFinalState. If not provided, the default C++ wavefunction simulator will be used.

Returns:

A callable with the following signature:


  • 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, size of state] that contains the state information of the circuit.