Skip to content

Qiskit Machine Learning 0.4.0

Compare
Choose a tag to compare
@manoelmarques manoelmarques released this 29 Apr 17:12
· 202 commits to main since this release
63ecb31

Changelog

New Features

  • In the previous releases at the backpropagation stage of CircuitQNN and OpflowQNN gradients were computed for each sample in a dataset individually and then the obtained values were aggregated into one output array. Thus, for each sample in a dataset at least one job was submitted. Now, gradients are computed for all samples in a dataset in one go by passing a list of values for a single parameter to CircuitSampler. Therefore, a number of jobs required for such computations is significantly reduced. This improvement may speed up training process in the cloud environment, where queue time for submitting a job may be a major contribution in the overall training time.

  • Introduced two new classes, EffectiveDimension and LocalEffectiveDimension, for calculating the capacity of quantum neural network models through the computation of the Fisher Information Matrix. The local effective dimension bounds the generalization error of QNNs and only accepts single parameter sets as inputs. The global effective dimension (or just effective dimension) can be used as a measure of the expressibility of the model, and accepts multiple parameter sets.

  • Objective functions constructed by the neural network classifiers and regressors now include an averaging factor that is evaluated as 1 / number_of_samples. Computed averaged objective values are passed to a user specified callback if any. Users may notice a dramatic decrease in the objective values in their callbacks. This is due to this averaging factor.

  • Added support for saving and loading machine learning models. This support is introduced in TrainableModel, so all sub-classes can be saved and loaded. Also, kernel based models can be saved and loaded. A list of models that support saving and loading models:

      NeuralNetworkClassifier
    
      NeuralNetworkRegressor
    
      VQC
    
      VQR
    
      QSVC
    
      QSVR
    
      PegasosQSVC
    
  • When model is saved all model parameters are saved to a file, including a quantum instance that is referenced by internal objects. That means if a model is loaded from a file and is used, for instance, for inference, the same quantum instance and a corresponding backend will be used even if a cloud backend was used.

  • Added a new feature in CircuitQNN that ensures unbound_pass_manager is called when caching the QNN circuit and that bound_pass_manager is called when QNN parameters are assigned.

  • Added a new feature in QuantumKernel that ensures the bound_pass_manager is used, when provided via the QuantumInstance, when transpiling the kernel circuits.

Upgrade Notes

  • Added support for running with Python 3.10. At the the time of the release, Torch didn’t have a python 3.10 version.

  • The previously deprecated BaseBackend class has been removed. It was originally deprecated in the Qiskit Terra 0.18.0 release.

  • Support for running with Python 3.6 has been removed. To run Machine Learning you need a minimum Python version of 3.7.

Deprecation Notes

  • The functions breast_cancer, digits, gaussian, iris and wine in the datasets module are deprecated and should not be used.

  • Class CrossEntropySigmoidLoss is deprecated and marked for removal.

  • Removed support of l2 and l1 values as loss function definitions. Please, use absolute_error and squared_error respectively.

Bug Fixes

  • Fixes in Ad Hoc dataset. Fixed an ValueError when n=3 is passed to ad_hoc_data. When the value of n is not 2 or 3, a ValueError is raised with a message that the only supported values of n are 2 and 3.

  • Previously, VQC would throw an error if trained on batches of data where not all of the target labels that can be found in the full dataset were present. This is because VQC interpreted the number of unique targets in the current batch as the number of classes. Currently, VQC is hard-coded to expect one-hot-encoded targets. Therefore, VQC will now determine the number of classes from the shape of the target array.

  • Fixes an issue where VQC could not be trained on multiclass datasets. It returned nan values on some iterations. This is fixed in 2 ways. First, the default parity function is now guaranteed to be able to assign at least one output bitstring to each class, so long as 2**N >= C where N is the number of output qubits and C is the number of classes. This guarantees that it is at least possible for every class to be predicted with a non-zero probability. Second, even with this change it is still possible that on a given training instance a class is predicted with 0 probability. Previously this could lead to nan in the CrossEntropyLoss calculation. We now replace 0 probabilities with a small positive value to ensure the loss cannot return nan.

  • Fixes an issue in QuantumKernel where evaluating a quantum kernel for data with dimension d>2 raised an error. This is fixed by changing the hard-coded reshaping of one-dimensional arrays in QuantumKernel.evaluate().

  • Fixes an issue where VQC would fail with warm_start=True. The extraction of the initial_point in TrainableModel from the final point of the minimization had not been updated to reflect the refactor of optimizers in qiskit-terra; the old optimize method, that returned a tuple was deprecated and new method minimize was created that returns an OptimizerResult object. We now correctly recover the final point of the minimization from previous fits to use for a warm start in subsequent fits.

  • Added GPU support to TorchConnector. Now, if a hybrid PyTorch model is being trained on GPU, TorchConnector correctly detaches tensors, moves them to CPU, evaluate forward and backward passes and places resulting tensors to the same device they came from.

  • Fixed a bug when a sparse array is passed to VQC as labels. Sparse arrays can be easily observed when labels are encoded via OneHotEncoder from SciKit-Learn. Now both NeuralNetworkClassifier and VQC support sparse arrays and convert them dense arrays in the implementation.