I want to use Q# to evaluate the real resources of an operation, but some problems happen. I want to evaluate the resource of training model operation for the example of half-moons data classification.
The evaluation target is TrainHalMoonModel operaion.
Firstly I use code like the below:
if __name__ == "__main__":
with open('data.json') as f:
data = json.load(f)
parameter_starting_points = [
[0.060057, 3.00522, 2.03083, 0.63527, 1.03771, 1.27881, 4.10186, 5.34396],
[0.586514, 3.371623, 0.860791, 2.92517, 1.14616, 2.99776, 2.26505, 5.62137],
[1.69704, 1.13912, 2.3595, 4.037552, 1.63698, 1.27549, 0.328671, 0.302282],
[5.21662, 6.04363, 0.224184, 1.53913, 1.64524, 4.79508, 1.49742, 1.545]
]
trainingVectors=data['TrainingData']['Features'],
trainingLabels=data['TrainingData']['Labels'],
initialParameters=parameter_starting_points
#qubit_result = TrainHalfMoonModel.estimate_resources(trainingVectors=trainingVectors,trainingLabels=trainingLabels,initialParameters=initialParameters)
qubit_result = TrainHalfMoonModel.estimate_resources()
print(qubit_result)
The error information shows below:
Received invalid parameters. Please fix and try again: trainingVectors: missing. trainingLabels: missing. initialParameters: missing. Traceback (most recent call last): File "D:\vscode_python\HelloQ\learnQ\machineLearning\evaluate.py", line 30, in qubit_result = TrainHalfMoonModel.estimate_resources() File "D:\software\python\Anaconda3\envs\qsharp-env\lib\site-packages\qsharp\loader.py", line 101, in estimate_resources return qsharp.client.estimate(self, **kwargs) File "D:\software\python\Anaconda3\envs\qsharp-env\lib\site-packages\qsharp\clients\iqsharp.py", line 191, in estimate for row in raw_counts: TypeError: 'NoneType' object is not iterable
The trainingVectors,trainingLabels,initialParameters are exactly parameters of TrainHalfMoonModel,I guess the estimate_resources() method may need parameters in this condition. so I use code like this:
if __name__ == "__main__":
with open('data.json') as f:
data = json.load(f)
parameter_starting_points = [
[0.060057, 3.00522, 2.03083, 0.63527, 1.03771, 1.27881, 4.10186, 5.34396],
[0.586514, 3.371623, 0.860791, 2.92517, 1.14616, 2.99776, 2.26505, 5.62137],
[1.69704, 1.13912, 2.3595, 4.037552, 1.63698, 1.27549, 0.328671, 0.302282],
[5.21662, 6.04363, 0.224184, 1.53913, 1.64524, 4.79508, 1.49742, 1.545]
]
trainingVectors=data['TrainingData']['Features'],
trainingLabels=data['TrainingData']['Labels'],
initialParameters=parameter_starting_points
qubit_result = TrainHalfMoonModel.estimate_resources(trainingVectors=trainingVectors,trainingLabels=trainingLabels,initialParameters=initialParameters)
#qubit_result = TrainHalfMoonModel.estimate_resources()
print(qubit_result)
The error information shows like this. It seems that the parameters can't be parsed correctly.
Received invalid parameters. Please fix and try again:
trainingVectors: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Microsoft.Quantum.Simulation.Core.IQArray`1[System.Double]]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path '@type', line 1, position 9.
trainingLabels: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[System.Int64]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path '@type', line 1, position 9.
Traceback (most recent call last):
File "D:\vscode_python\HelloQ\learnQ\machineLearning\evaluate.py", line 19, in <module>
qubit_result = TrainHalfMoonModel.estimate_resources(trainingVectors=trainingVectors,trainingLabels=trainingLabels,initialParameters=initialParameters)
File "D:\software\python\Anaconda3\envs\qsharp-env\lib\site-packages\qsharp\loader.py", line 101, in estimate_resources
return qsharp.client.estimate(self, **kwargs)
File "D:\software\python\Anaconda3\envs\qsharp-env\lib\site-packages\qsharp\clients\iqsharp.py", line 191, in estimate
for row in raw_counts:
TypeError: 'NoneType' object is not iterable
qubit_result = TrainHalfMoonModel.estimate_resources({'trainingVectors':trainingVectors,'trainingLabels':trainingLabels,'initialParameters':initialParameters})
or
qubit_result = TrainHalfMoonModel.estimate_resources([trainingVectors,trainingLabels,initialParameters])
They all can't work. So what's the properly format of argument of estimate_resources method when the operation that needed to be evaluated have arguments?