1
  • qiskit version : 0.18.0
  • numpy version : 1.21.1
  • qiskit_machine_learning version : 0.2.0
  • qiskit.aqua version : 0.9.4

I am trying to run a simple code as described in Qiskit's tutorial on Machine Learning.

feature_dim=2
training_dataset_size=20
testing_dataset_size=10
random_seed=10598
shots=10000

sample_Total,training_input,test_input,class_labels = 
ad_hoc_data(training_size=training_dataset_size,
                                                               test_size=testing_dataset_size,
                                                               gap=0.3,
                                                               n=feature_dim,
                                                               plot_data=True)
datapoints,class_to_label=split_dataset_to_data_and_labels(test_input)

But I receive the error

AttributeError                            Traceback (most recent call last)
<ipython-input-11-f11e4f763266> in <module>
     10                                                                n=feature_dim,
     11                                                                plot_data=True)
---> 12 datapoints,class_to_label=split_dataset_to_data_and_labels(test_input)
   

~\anaconda3\lib\site-packages\qiskit\aqua\utils\dataset_helper.py in split_dataset_to_data_and_labels(dataset, class_names)
     83     labels = []
     84     if class_names is None:
---> 85         sorted_classes_name = sorted(list(dataset.keys()))
     86         class_to_label = {k: idx for idx, k in enumerate(sorted_classes_name)}
     87     else:

AttributeError: 'numpy.ndarray' object has no attribute 'keys'

By which I assume (and checked by printing it) that ad_hoc_data(...) is resulting in test_input in numpy.ndarray type as opposed to the expected dict type.

Is there something trivial I'm missing here or is there an actual issue with the code?

Thanks in advance

shaw1801
  • 11
  • 2
  • Hi @shaw1801, this seems more like a Qiskit specific bug report instead of a Quantum Computing question. If you open an issue on Qiskits GutHub repo there the developers can have a look. – Cryoris Jul 31 '21 at 11:31
  • Yes. I thought so but just wanted to make sure I am not missing anything. Anyways thank you @Cryoris – shaw1801 Jul 31 '21 at 12:14
  • Are you mixing and matching Aqua and/or qiskit.ml with the new Qiskit Machine Learning i.e. qiskit.machine_learning? If I add appropriate Aqua imports (as below) to your sample - given the error you show refers to qiskit\aqua\utils\dataset_helper, so I assume you are using Aqua in there at least, then it works fine for me and shows a plot: from qiskit.ml.datasets import ad_hoc_data from qiskit.aqua.utils import split_dataset_to_data_and_labels – Steve Wood Jul 31 '21 at 16:07
  • Yes. @SteveWood Thank You. That is exactly what happened. Importing from qiskit.ml.datasets works fine (though gives a Deprecation Warning). But on importing from qiskit_machine_learning the above problem occurs. I don't understand why (as I even checked the code for ad_hoc_data in the new repository). Any clarification would be appreciated. Thank you. – shaw1801 Jul 31 '21 at 17:34
  • You need to use all code from Aqua (which contains ML code as it was formerly) or use all code from Qiskit Machine Learning. The data_helper above, as per the error msg, if from Aqua. Aqua was deprecated, meaning its support is ending, and the code moved to Qiskit Machine Learning, Optimization etc. Code was also refactored and re-organized and the newly relocated code is not necessarily compatible with what was in Aqua. As I indicated the dataset access is compatible what how things were in Aqua - using Aqua imports. – Steve Wood Jul 31 '21 at 22:31

0 Answers0