1
$\begingroup$

Could someone guide me on how to create my own qiskit.result.models.ExperimentResultData object? I would simply like to create an object with some self-created dict of counts.

Creating qiskit.result.models.ExperimentalResults object is somehow easy, since by calling it from qiskit.result.models.ExperimentResults, I simply pass the required attributes. But somehow I was not able to figure out how to do the same with qiskit.result.models.ExperimentResultData, which should be passed as "data" attribute to qiskit.result.models.ExperimentalResults object.

$\endgroup$
1
$\begingroup$

You should be able to do this by simply creating an instance of the class. This can be done as follows

from qiskit.validation import base
raw_counts = {'0x0': 4, '0x2': 10}
data = models.ExperimentResultData(counts=base.Obj(**raw_counts))

There are lot of examples of how to do this in the testing file for these classes.

$\endgroup$
  • 1
    $\begingroup$ Ah, great, thank you for the solution and great reference! I was only looking at files in the qiskit package (downloaded via pip) and I did not find such testing file, so I'll use github one for future issues. $\endgroup$ – Filip Maciejewski Nov 21 at 17:08
  • 1
    $\begingroup$ @FilipMaciejewski If this answer helped, consider accepting it by clicking on the checkmark at the left. $\endgroup$ – Sanchayan Dutta Nov 21 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.