VQC¶
-
class
VQC
(optimizer, feature_map, var_form, training_dataset, test_dataset=None, datapoints=None, max_evals_grouped=1, minibatch_size=- 1, callback=None, use_sigmoid_cross_entropy=False, quantum_instance=None)[source]¶ Bases:
qiskit.aqua.algorithms.vq_algorithm.VQAlgorithm
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.use_sigmoid_cross_entropy (
bool
) – whether to use sigmoid cross entropy or not.quantum_instance (
Union
[QuantumInstance
,Backend
,BaseBackend
,None
]) – Quantum Instance or Backend
Note
We use label to denote numeric results and class the class names (str).
- Raises
AquaError – Missing feature map or missing training dataset.
Methods
batch data
set parameterized circuits to None
Construct circuit based on data and parameters in variational form.
Optimize to find the minimum cost value.
get optimal circuit
get optimal cost
get optimal vector
Helper function to get probability vectors for a set of params
get probabilities for counts
returns is gradient really supported
load model
Predict the labels for the data.
Execute the algorithm with selected backend.
save model
Sets backend with configuration.
Predict the labels for the data, and test against with ground truth labels.
Train the models, and save results.
Attributes
-
backend
¶ Returns backend.
- Return type
Union
[Backend
,BaseBackend
]
-
class_to_label
¶ returns class to label
-
datapoints
¶ return data points
-
feature_map
¶ Return the feature map.
- Return type
Union
[FeatureMap
,QuantumCircuit
,None
]
-
initial_point
¶ Returns initial point
- Return type
Optional
[ndarray
]
-
label_to_class
¶ returns label to class
-
optimal_params
¶ returns optimal parameters
-
optimizer
¶ Returns optimizer
- Return type
Optional
[Optimizer
]
-
quantum_instance
¶ Returns quantum instance.
- Return type
Optional
[QuantumInstance
]
-
random
¶ Return a numpy random.
-
ret
¶ returns result
-
test_dataset
¶ returns test dataset
-
training_dataset
¶ returns training dataset
-
var_form
¶ Returns variational form
- Return type
Union
[QuantumCircuit
,VariationalForm
,None
]