VQC¶
- class VQC(optimizer, feature_map, var_form, training_dataset, test_dataset=None, datapoints=None, max_evals_grouped=1, minibatch_size=- 1, callback=None, quantum_instance=None)[source]¶
The Variational Quantum Classifier algorithm.
Similar to
QSVM
, the VQC algorithm also applies to classification problems. VQC uses the variational method to solve such problems in a quantum processor. Specifically, it optimizes a parameterized quantum circuit to provide a solution that cleanly separates the data.Note
The VQC stores the parameters of var_form and feature_map sorted by name to map the values provided by the optimizer to the circuit. This is done to ensure reproducible results, for example such that running the optimization twice with same random seeds yields the same result.
- Parameters
optimizer (
Optimizer
) – The classical optimizer to use.feature_map (
Union
[QuantumCircuit
,FeatureMap
]) – The FeatureMap instance to use.var_form (
Union
[QuantumCircuit
,VariationalForm
]) – The variational form instance.training_dataset (
Dict
[str
,ndarray
]) – The training dataset, in the format {‘A’: np.ndarray, ‘B’: np.ndarray, …}.test_dataset (
Optional
[Dict
[str
,ndarray
]]) – The test dataset, in same format as training_dataset.datapoints (
Optional
[ndarray
]) – NxD array, N is the number of data and D is data dimension.max_evals_grouped (
int
) – The maximum number of evaluations to perform simultaneously.minibatch_size (
int
) – The size of a mini-batch.callback (
Optional
[Callable
[[int
,ndarray
,float
,int
],None
]]) – a callback that can access the intermediate data during the optimization. Four parameter values are passed to the callback as follows during each evaluation. These are: the evaluation count, parameters of the variational form, the evaluated value, the index of data batch.quantum_instance (
Union
[QuantumInstance
,BaseBackend
,None
]) – Quantum Instance or Backend
Note
We use label to denotes numeric results and class the class names (str).
- Raises
AquaError – Missing feature map or missing training dataset.
Attributes
Returns backend.
returns class to label
return data points
Return the feature map.
Returns initial point
returns label to class
returns optimal parameters
Returns optimizer
Returns quantum instance.
Return a numpy random.
returns result
returns test dataset
returns training dataset
Returns variational form
Methods
VQC.batch_data
(data[, labels, minibatch_size])batch data
set parameterized circuits to None
VQC.construct_circuit
(x, theta[, measurement])Construct circuit based on data and parameters in variational form.
VQC.find_minimum
([initial_point, var_form, …])Optimize to find the minimum cost value.
get optimal circuit
get optimal cost
get optimal vector
VQC.get_prob_vector_for_params
(…[, …])Helper function to get probability vectors for a set of params
VQC.get_probabilities_for_counts
(counts)get probabilities for counts
returns is gradient really supported
VQC.load_model
(file_path)load model
VQC.predict
(data[, quantum_instance, …])Predict the labels for the data.
VQC.run
([quantum_instance])Execute the algorithm with selected backend.
VQC.save_model
(file_path)save model
VQC.set_backend
(backend, **kwargs)Sets backend with configuration.
VQC.test
(data, labels[, quantum_instance, …])Predict the labels for the data, and test against with ground truth labels.
VQC.train
(data, labels[, quantum_instance, …])Train the models, and save results.