-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding compiled QASM to the result #688
Changes from 6 commits
e7b7cf6
ba82b87
a804c9b
64d2125
94c3d70
2907bd8
31edca7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,16 @@ | |
|
||
"""Module for working with Results.""" | ||
|
||
import logging | ||
import copy | ||
import numpy | ||
from ._qiskiterror import QISKitError | ||
from ._quantumcircuit import QuantumCircuit | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Result(object): | ||
""" Result Class. | ||
|
||
|
@@ -414,3 +418,23 @@ def get_qubitpol_vs_xval(self, nqubits, xvals_dict=None): | |
circuit_name, z_dicts[qubit_ind]) | ||
|
||
return qubitpol, xvals | ||
|
||
|
||
def copy_qasm_from_qobj_into_result(qobj, result): | ||
"""Find the QASMs belonging to the Qobj experiments and copy them | ||
into the corresponding result entries.""" | ||
for experiment in qobj.experiments: | ||
name = experiment.header.name | ||
qasm = getattr(experiment.header, 'compiled_circuit_qasm', None) | ||
experiment_result = _find_experiment_result(result, name) | ||
if qasm and experiment_result: | ||
experiment_result['compiled_circuit_qasm'] = qasm | ||
|
||
|
||
def _find_experiment_result(result, name): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you reeevaluate if this function is really needed? Seems we could avoid an extra function if it is made a one-liner with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try to avoid this kind of one-liners since they are, usually, harder to read. I can move it inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also dislike lots of small functions, but your choice. |
||
for experiment_result in result['result']: | ||
if experiment_result['name'] == name: | ||
return experiment_result | ||
|
||
logger.warning('No result found for experiment %s', name) | ||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one I'm a bit more concerned about: is there really a case where it could really return
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I know, nope, it would expose an inconsistency between the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think explicitly taking care of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to keep this as a private function. With the one-liner, I can not add the warning and by moving it inside the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be a private method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. It is related to the
Result
type but it does not seem like an operation on theResult
type. Ideally, it should be placed near the simulators which are the ones using it but I did not want to add a new file nor I was sure about where to add it.