コード例 #1
0
ファイル: circuit_operation.py プロジェクト: towynlin/Cirq
    def with_params(self,
                    param_values: 'cirq.ParamResolverOrSimilarType',
                    recursive: bool = False) -> 'cirq.CircuitOperation':
        """Returns a copy of this operation with an updated ParamResolver.

        Any existing parameter mappings will have their values updated given
        the provided mapping, and any new parameters will be added to the
        ParamResolver.

        Note that any resulting parameter mappings with no corresponding
        parameter in the base circuit will be omitted.

        Args:
            param_values: A map or ParamResolver able to convert old param
                values to new param values. This map will be composed with any
                existing ParamResolver via single-step resolution.
            recursive: If True, resolves parameter values recursively over the
                resolver; otherwise performs a single resolution step. This
                behavior applies only to the passed-in mapping, for the current
                application. Existing parameters are never resolved recursively
                because a->b and b->a needs to be a valid mapping.

        Returns:
            A copy of this operation with its ParamResolver updated as specified
                by param_values.
        """
        new_params = {}
        for k in protocols.parameter_symbols(self.circuit):
            v = self.param_resolver.value_of(k, recursive=False)
            v = protocols.resolve_parameters(v,
                                             param_values,
                                             recursive=recursive)
            if v != k:
                new_params[k] = v
        return self.replace(param_resolver=new_params)
コード例 #2
0
ファイル: circuit_operation.py プロジェクト: daxfohl/Cirq
 def _parameter_names_generator(self) -> Iterator[str]:
     yield from protocols.parameter_names(self.repetitions)
     for symbol in protocols.parameter_symbols(self.circuit):
         for name in protocols.parameter_names(
                 protocols.resolve_parameters(symbol,
                                              self.param_resolver,
                                              recursive=False)):
             yield name
コード例 #3
0
 def _parameter_names_(self) -> AbstractSet[str]:
     return {
         name
         for symbol in protocols.parameter_symbols(self.circuit)
         for name in protocols.parameter_names(
             protocols.resolve_parameters(
                 symbol, self.param_resolver, recursive=False))
     }
コード例 #4
0
    def with_params(self, param_values: study.ParamResolverOrSimilarType) -> 'CircuitOperation':
        """Returns a copy of this operation with an updated ParamResolver.

        Note that any resulting parameter mappings with no corresponding
        parameter in the base circuit will be omitted.

        Args:
            param_values: A map or ParamResolver able to convert old param
                values to new param values. This map will be composed with any
                existing ParamResolver via single-step resolution.

        Returns:
            A copy of this operation with its ParamResolver updated as specified
                by param_values.
        """
        new_params = {}
        for k in protocols.parameter_symbols(self.circuit):
            v = self.param_resolver.value_of(k, recursive=False)
            v = protocols.resolve_parameters(v, param_values, recursive=False)
            if v != k:
                new_params[k] = v
        return self.replace(param_resolver=new_params)