tensorflow_quantum/python/layers/circuit_executors/expectation.py [310:349]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            reps_need_tile = False
            if isinstance(repetitions, numbers.Integral):
                # Must tile it up to size to match operators if many operators
                # were provided but only one number was provided.
                repetitions = tf.ones(tf.shape(operators),
                                      dtype=tf.dtypes.int32) * repetitions

            if isinstance(repetitions, (list, tuple, np.ndarray)):
                if not isinstance(repetitions[0], (list, tuple, np.ndarray)):
                    repetitions = [repetitions]
                    reps_need_tile = True

                repetitions = tf.convert_to_tensor(repetitions,
                                                   dtype=tf.dtypes.int32)

            if reps_need_tile:
                # Don't tile up if the user gave a python list that was
                # precisely the correct size to match circuits outer batch dim.
                repetitions = tf.tile(repetitions, [circuit_batch_dim, 1])

            if not tf.is_tensor(repetitions):
                raise TypeError("repetitions cannot be parsed to int32 tensor"
                                " given input: ".format(repetitions))

        if values_empty:
            # No symbol_values were provided. So we assume the user wants us
            # to create and manage variables for them. We will do so by
            # creating a weights variable and tiling it up to appropriate
            # size of [batch, num_symbols].

            if self._w is None:
                # don't re-add variable.
                self._w = self.add_weight(name='circuit_learnable_parameters',
                                          shape=symbol_names.shape,
                                          initializer=initializer)

            symbol_values = tf.tile(tf.expand_dims(self._w, axis=0),
                                    tf.stack([circuit_batch_dim, 1]))

        num_samples = repetitions  # needed to help autographer.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py [300:339]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        reps_need_tile = False
        if isinstance(repetitions, numbers.Integral):
            # Must tile it up to size to match operators if many operators
            # were provided but only one number was provided.
            repetitions = tf.ones(tf.shape(operators),
                                  dtype=tf.dtypes.int32) * repetitions

        if isinstance(repetitions, (list, tuple, np.ndarray)):
            if not isinstance(repetitions[0], (list, tuple, np.ndarray)):
                repetitions = [repetitions]
                reps_need_tile = True

            repetitions = tf.convert_to_tensor(repetitions,
                                               dtype=tf.dtypes.int32)

        if reps_need_tile:
            # Don't tile up if the user gave a python list that was precisely
            # the correct size to match circuits outer batch dim.
            repetitions = tf.tile(repetitions, [circuit_batch_dim, 1])

        if not tf.is_tensor(repetitions):
            raise TypeError("repetitions cannot be parsed to int32 tensor"
                            " given input: ".format(repetitions))

        if values_empty:
            # No symbol_values were provided. So we assume the user wants us
            # to create and manage variables for them. We will do so by
            # creating a weights variable and tiling it up to appropriate
            # size of [batch, num_symbols].

            if self._w is None:
                # don't re-add variable.
                self._w = self.add_weight(name='circuit_learnable_parameters',
                                          shape=symbol_names.shape,
                                          initializer=initializer)

            symbol_values = tf.tile(tf.expand_dims(self._w, axis=0),
                                    tf.stack([circuit_batch_dim, 1]))

        num_samples = repetitions
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



