def init_args(self, oracle, incremental=False, num_iterations=1): if QuantumAlgorithm.is_statevector_backend(self.backend): raise ValueError( 'Selected backend "{}" does not support measurements.'.format( QuantumAlgorithm.backend_name(self.backend))) self._oracle = oracle self._max_num_iterations = 2**(len(self._oracle.variable_register()) / 2) self._incremental = incremental self._num_iterations = num_iterations if incremental: logger.debug( 'Incremental mode specified, ignoring "num_iterations".') else: if num_iterations > self._max_num_iterations: logger.warning( 'The specified value {} for "num_iterations" might be too high.' .format(num_iterations))
def init_args(self, training_dataset, test_dataset, datapoints, optimizer, feature_map, var_form): """Initialize the object Args: training_dataset (dict): {'A': numpy.ndarray, 'B': numpy.ndarray, ...} test_dataset (dict): the same format as `training_dataset` datapoints (numpy.ndarray): NxD array, N is the number of data and D is data dimension optimizer (Optimizer): Optimizer instance feature_map (FeatureMap): FeatureMap instance var_form (VariationalForm): VariationalForm instance Notes: We used `label` denotes numeric results and `class` means the name of that class (str). """ if QuantumAlgorithm.is_statevector_backend(self.backend): raise ValueError('Selected backend "{}" is not supported.'.format( QuantumAlgorithm.backend_name(self.backend))) if training_dataset is None: raise AlgorithmError('Training dataset must be provided') self._training_dataset, self._class_to_label = split_dataset_to_data_and_labels( training_dataset) if test_dataset is not None: self._test_dataset = split_dataset_to_data_and_labels( test_dataset, self._class_to_label) self._label_to_class = { label: class_name for class_name, label in self._class_to_label.items() } self._num_classes = len(list(self._class_to_label.keys())) self._datapoints = datapoints self._optimizer = optimizer self._feature_map = feature_map self._var_form = var_form self._num_qubits = self._feature_map.num_qubits