Package: dc-qiskit-qml
qiskitis an open-source compilation framework capable of targeting various
types of hardware and a high-performance quantum computer simulator with emulation capabilities and various
compiler plug-ins.This library implements so far one quantum machine learning classifier which has been introduced by F.Petruccione,
M. Schuld and M. Fingerhuth (http://stacks.iop.org/0295-5075/119/i=6/a=60002). Athough this is the only classifier
implemented so far, this library is to be used as a repository for more classifiers using qiskit as a background
framework.FeaturesDistance & Majority based Hadamard-gate classifierGeneric real valued vector space input data (slow)Binary valued vector space input data (faster)Feature map pre-processing for non-linear classificationInstallationThis library requires Python version 3.5 and above, as well as qiskit.
Installation of this library, as well as all dependencies, can be done using pip:$python-mpipinstalldc_qiskit_aqmlTo test that the algorithms are working correctly you can run$maketestGetting startedYou can check out the classifier as followsimportnumpyasnpfromsklearn.datasetsimportload_irisfromsklearn.preprocessingimportStandardScaler,Normalizerfromsklearn.model_selectionimporttrain_test_splitfromsklearn.pipelineimportPipelineimportqiskitfromdc_qiskit_qml.feature_mapsimportNormedAmplitudeEncodingfromdc_qiskit_qml.distance_based.hadamardimportQmlHadamardNeighborClassifierfromdc_qiskit_qml.distance_based.hadamard.stateimportQmlGenericStateCircuitBuilderfromdc_qiskit_qml.distance_based.hadamard.state.sparsevectorimportMöttönenStatePreparationX,y=load_iris(True)# Only the first two features and only get two labels# This is a toy example!X=np.asarray([x[0:2]forx,yyinzip(X,y)ifyy!=2])y=np.asarray([yyforx,yyinzip(X,y)ifyy!=2])preprocessing_pipeline=Pipeline([('scaler',StandardScaler()),('l2norm',Normalizer(norm='l2',copy=True))])X=preprocessing_pipeline.fit_transform(X,y)X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.10)# Using the generic wave function (state vector) routine using the 'Möttönen'# state preparation algorithminitial_state_builder=QmlGenericStateCircuitBuilder(MöttönenStatePreparation())# The normed amplitude encoding ensures that the data is normalized# This is a somewhat unnecessary step as above we do that alreadyfeature_map=NormedAmplitudeEncoding()execution_backend:BaseBackend=qiskit.Aer.get_backend('qasm_simulator')qml=QmlHadamardNeighborClassifier(backend=execution_backend,shots=8192,classifier_circuit_factory=initial_state_builder,feature_map=feature_map)qml.fit(X_train,y_train)prediction=qml.predict(X_test)"Test Accuracy:{}".format(sum([1ifp==telse0forp,tinzip(prediction,y_test)])/len(prediction))prediction_train=qml.predict(X_train)"Train Accuracy:{}".format(sum([1ifp==telse0forp,tinzip(prediction_train,y_train)])/len(prediction_train))The details are a bit more involved as to how this works and the classifier can be configured with a circuit factory
or a feature map.Please refer to thedocumentation of the dc qiskit qml library.ContributingWe welcome contributions - simply fork the repository of this plugin, and then make apull requestcontaining your contribution.
All contributers to this plugin will be listed as authors on the releases.We also encourage bug reports, suggestions for new features and enhancements, and even links to cool projects or applications built on PennyLane.AuthorsCarsten BlankSupportSource Code:https://github.com/carstenblank/dc-qiskit-qmlIssue Tracker:https://github.com/carstenblank/dc-qiskit-qml/issuesIf you are having issues, please let us know by posting the issue on our Github issue tracker.LicenseThe data cybernetics qiskit algorithms plugin isfreeandopen source, released under
theApache License, Version 2.0.