2
$\begingroup$

I have executed an experiment using IBMQ and receive a Result object. I am writing the ASCII repr of the result with f.write(res) into a file and see a line like

Result(backend_name='ibmq_16_melbourne', backend_version='1.1.0',...

How can I reconstruct the Result object from that line? Which methods do I have to call?

$\endgroup$
3
$\begingroup$

I found a solution: to serialise instead of print(res) I need to do:

print(res.to_dict())

To load the serialized string (eg. line from a file)

dict = eval(line)
res = Result.from_dict(dict)

all of the above with

from qiskit.result import Result
$\endgroup$
1
$\begingroup$

You could recreate the object by reading the parameters and then creating a new result object result = Result(parameters). You can see the method that does this here.

If you have access to the account that submitted the job you can also simply retrieve the job from the backend again using get_job().

$\endgroup$
  • $\begingroup$ Thank you! You mean that I should first parse the string I have in the file? I did not want to use the remote API to get the results, because preferred the local way of analysis. That way I can send the analysis script to other people without send them the API key. $\endgroup$ – sandualuclopotaru Sep 24 at 11:35

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.