def profile_operator(self, name, operator, time): """ Store building time and resources information for a named quantum walk operator. Parameters ---------- name : str A name for the operator. operator : :obj:Operator The operator object. time : float The measured building time of the operator. Returns ------- dict The resources information measured for the operator. Raises ----- TypeError """ if self.logger: self.logger.info( 'profiling operator data for "{}"...'.format(name)) if not is_operator(operator): if self._logger: self._logger.error( 'Operator instance expected, not "{}"'.format( type(operator))) raise TypeError('Operator instance expected, not "{}"'.format( type(operator))) if name not in self._operators: self._operators[name] = [] self._operators[name].append(self._default_operator()) app_id = operator.spark_context.applicationId rdd_id = operator.data.id() data = self.request_rdd(app_id, rdd_id) if data is not None: for k, v in data.items(): if k in self._default_operator(): self._operators[name][-1][k] = v self._operators[name][-1]['buildingTime'] = time self._operators[name][-1]['numElements'] = operator.num_elements self._operators[name][-1][ 'numNonzeroElements'] = operator.num_nonzero_elements return self._operators[name][-1]
def walk_operator(self, wo): """ Parameters ---------- wo : Operator or list of Operator An Operator or a list of Operators (for multiparticle walk simulator). Raises ------ ValueError TypeError """ if is_operator(wo) or wo is None: self._walk_operator = wo elif isinstance(wo, (list, tuple)): if len(wo) != self._num_particles: if self._logger: self._logger.error( '{} walk operators expected, not {}'.format( self._num_particles, len(wo))) raise ValueError('{} walk operators expected, not {}'.format( self._num_particles, len(wo))) for o in wo: if not is_operator(o): if self._logger: self._logger.error( 'Operator instance expected, not "{}"'.format( type(wo))) raise TypeError( 'Operator instance expected, not "{}"'.format( type(wo))) else: if self._logger: self._logger.error( 'Operator instance expected, not "{}"'.format(type(wo))) raise TypeError('Operator instance expected, not "{}"'.format( type(wo)))
def coin_operator(self, co): """ Parameters ---------- co : Operator Raises ------ TypeError """ if is_operator(co): self._coin_operator = co else: if self._logger: self._logger.error( 'Operator instance expected, not "{}"'.format(type(co))) raise TypeError('Operator instance expected, not "{}"'.format( type(co)))
def interaction_operator(self, io): """ Parameters ---------- io : Operator Raises ------ TypeError """ if is_operator(io) or io is None: self._interaction_operator = io else: if self._logger: self._logger.error( 'Operator instance expected, not "{}"'.format(type(io))) raise TypeError('Operator instance expected, not "{}"'.format( type(io)))
def shift_operator(self, so): """ Parameters ---------- so : Operator Raises ------ TypeError """ if is_operator(so): self._shift_operator = so else: if self._logger: self._logger.error( 'Operator instance expected, not "{}"'.format(type(so))) raise TypeError('Operator instance expected, not "{}"'.format( type(so)))