3030class Expectation (tf .keras .layers .Layer ):
3131 """A Layer that calculates an expectation value.
3232
33+ Args:
34+ backend (Union[str, cirq.sim.simulator.SimulatesExpectationValues],
35+ optional):
36+ Backend simulator to use. Default is 'noiseless'.
37+ differentiator (Optional[tfq.differentiators.Differentiator]):
38+ Differentiation scheme for gradients.
39+ **kwargs: Additional keyword arguments for the parent class.
40+
41+ Input shape:
42+ - circuits: tf.Tensor or list of shape [batch_size], each entry a
43+ serialized circuit (from tfq.convert_to_tensor).
44+ - symbol_names: list or tf.Tensor of shape [n_symbols], names of
45+ circuit parameters (optional).
46+ - symbol_values: tf.Tensor of shape [batch_size, n_symbols], values for
47+ circuit parameters (optional).
48+ - operators: list or tf.Tensor of shape [n_ops], observables to measure
49+ (optional).
50+ - repetitions: int or tf.Tensor, number of measurement repetitions
51+ (optional, only for noisy backend).
52+
53+ Output shape:
54+ tf.Tensor of shape [batch_size, n_ops], expectation values for each
55+ circuit and operator.
56+
3357 Given an input circuit and set of parameter values, prepare a quantum state
3458 and output expectation values taken on that state with respect to some
3559 observables to the tensorflow graph.
@@ -199,10 +223,9 @@ class Expectation(tf.keras.layers.Layer):
199223 something like `tfq.layers.Expectation()(cirq.Circuit(...), ...)` please
200224 be sure to instead use `tfq.layers.Expectation()(circuit_input, ...)`
201225 where `circuit_input` is a `tf.keras.Input` that is filled with
202- `tfq.conver_to_tensor ([cirq.Circuit(..)] * batch_size)` at runtime. This
226+ `tfq.convert_to_tensor ([cirq.Circuit(..)] * batch_size)` at runtime. This
203227 is because compiled Keras models require non keyword layer `call` inputs to
204228 be traceable back to a `tf.keras.Input`.
205-
206229 """
207230
208231 def __init__ (self , backend = 'noiseless' , differentiator = None , ** kwargs ):
@@ -225,6 +248,7 @@ def __init__(self, backend='noiseless', differentiator=None, **kwargs):
225248 which uses `tfq.differentiators.ParameterShift()`. If
226249 `backend` is also 'noiseless' then default is
227250 `tfq.differentiators.Adjoint`.
251+ **kwargs: Additional keyword arguments for the parent class.
228252
229253 """
230254 super ().__init__ (** kwargs )
@@ -273,15 +297,23 @@ def call(self,
273297 initializer = tf .keras .initializers .RandomUniform (0 , 2 * np .pi )):
274298 """Keras call function.
275299
276- Input options:
277- `inputs`, `symbol_names`, `symbol_values`:
278- see `input_checks.expand_circuits`
279- `operators`: see `input_checks.expand_operators`
280-
281- Output shape:
282- `tf.Tensor` with shape [batch_size, n_ops] that holds the
283- expectation value for each circuit with each op applied to it
284- (after resolving the corresponding parameters in).
300+ Args:
301+ inputs (tf.Tensor or list): Circuits to execute, shape [batch_size].
302+ symbol_names (list or tf.Tensor, optional): Names of circuit
303+ parameters, shape [n_symbols].
304+ symbol_values (tf.Tensor, optional): Values for circuit parameters,
305+ shape [batch_size, n_symbols].
306+ operators (list or tf.Tensor, optional): Observables to measure,
307+ shape [n_ops].
308+ repetitions (int or tf.Tensor, optional): Number of measurement
309+ repetitions (for noisy backend).
310+ initializer (tf.keras.initializers.Initializer, optional):
311+ Initializer for circuit parameters.
312+
313+ Returns:
314+ tf.Tensor: Tensor of shape [batch_size, n_ops] that holds the
315+ expectation value for each circuit with each op applied to it
316+ (after resolving the corresponding parameters in).
285317 """
286318 values_empty = False
287319 if symbol_values is None :
0 commit comments