tfq.resolve_parameters

Replace symbols in a batch of programs with concrete values.

Used in the notebooks

Used in the tutorials

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───]

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.

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.