Closed ElePT closed 3 years ago
Update: There is a confirmed bug in RawFeatureVector
regarding the bind_parameters()
method (I'll make a PR fixing it). Now we can see that if the parameters are bound, the following error arises:
File "/Users/elena/Documents/Code/qiskit/qiskit-machine-learning/qiskit_machine_learning/neural_networks/neural_network.py", line 126, in _validate_input
raise QiskitMachineLearningError(
qiskit_machine_learning.exceptions.QiskitMachineLearningError: 'Input data has incorrect shape, last dimension is not
equal to the number of inputs: 0, but got: 4.'
This makes sense, as binding the parameters reduces the number of inputs.... Maybe there should be a way of avoiding the parameter initialization when RawFeatureVector
is used as a feature map? Or should it just not be used in this context? In that case, in what context is it useful?
Information
What is the current behavior?
In both
CircuitQNN
andOpflowQNN
, ifRawFeatureVector
is used as feature map, the following warning arises during the network initialization step:This behavior was originally pointed out on issue #95, but it was only noted for the case where
CircuitStateFn
is used, and I initially thought that it wasOpflow
-related. I have now noticed that this is not aOpflowQNN
orCircuitStateFn
issue, but a more generalized one. I have tested out different examples usingRawFeatureVector
and QNNs, and all of them end up triggering this warning, including the code shown in the Creating Your First Machine Learning Programming Experiment in Qiskit section of this repo's ReadMe (not ideal).I have traced back this warning to the following error message:
raise QiskitError("Cannot define a ParameterizedInitialize with unbound parameters")
Binding the parameters looks like a solution to this message, but I am not 100% sure that it is what we want. After all, we want the feature map to be parametrized, and if we bind the parameters, it's not parametrized anymore.
During my investigation I have found some potential bugs in either
RawFeatureVector
or its base classBlueprintCircuit
. I plan to make the corresponding issues in the Terra repo and link them below for reference, but I think that it is helpful to also keep track of the issue on theqiskit-machine-learning
side.Steps to reproduce the problem
Run the following code:
What is the expected behavior?
I would expect this warning not to appear. Furthermore, if you run the code above, you can see that the testing accuracy is still 100%, despite the warning. This is probably due to the simplicity of the dataset used (I have not found any other explanation at the moment, but haven't extensively tested this one either).
Suggested solutions
The specific error that triggers this warning is:
raise QiskitError("Cannot define a ParameterizedInitialize with unbound parameters")
Doing something like
feature_map = feature_map.bind_parameters([bound1, bound2, bound3, bound4])
would prevent this error. However, this line of code does not work as expected (neither doesfeature_map = feature_map.assign_parameters()
), so these should be fixed first.