-
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
Conversation
I think this is fine to temporarily make the |
47553d9
to
23a3c1a
Compare
qiskit/_result.py
Outdated
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 comment
The 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 next(x for x in result['result'] if blah)
(not really blocking anyway).
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 try to avoid this kind of one-liners since they are, usually, harder to read. I can move it inside copy_qasm_from_qobj_into_result
as an auxiliary function or a lambda variable, though.
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 also dislike lots of small functions, but your choice.
qiskit/_result.py
Outdated
if experiment_result['name'] == name: | ||
return experiment_result | ||
|
||
return None |
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.
This one I'm a bit more concerned about: is there really a case where it could really return None
? If that is the case, line 427 would fail at:
experiment_result['compiled_circuit_qasm'] = qasm
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.
As far as I know, nope, it would expose an inconsistency between the Qobj
and Result
instances but the linter complained if I did not add a return value for this code-path. I can add a warning and avoid accessing it if None
is returned. Does it make sense?
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.
Yeah I think explicitly taking care of the None
case would be good.
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'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 copy_qasm_from_qobj_into_result
function, makes the function hard to read.
@@ -414,3 +414,22 @@ 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): |
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 the Result
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.
qiskit/_result.py
Outdated
|
||
|
||
def copy_qasm_from_qobj_into_result(qobj, result): | ||
"""Find the several QASM belonging to the Qobj experiments and copy them |
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.
grammar nit: "Find the QASMs belonging to ..."
qiskit/_result.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I also dislike lots of small functions, but your choice.
qiskit/_result.py
Outdated
if experiment_result['name'] == name: | ||
return experiment_result | ||
|
||
return None |
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.
Yeah I think explicitly taking care of the None
case would be good.
test/python/test_wrapper_helpers.py
Outdated
self.circuit.ccx(q[0], q[1], q[2]) | ||
self.circuit.measure(q, c) | ||
|
||
def test_local_execute_and_get_ran_qasm(self): |
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.
Why create a new test file? Can you include in the the already existing test_wrapper.py
?
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 did it because test_wrapper.py
seems to be testing the functions related to register()
and adding this functionality was somehow polluting the test case.
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.
Yeah but it should not just test register
. As the name suggests, it should test the wrapper, which has several components (available_backends, register, execute).
Our test_wrapper.py
needs to get more complete and this is a good addition to it.
@delapuente I see you modified the |
Unfortunately, I was trying to test if remote backends return the QASM but they took too long (more than 20 min.) |
7b48eab
to
52f500a
Compare
The online simulator should be quick. |
I can confirm |
52f500a
to
64d2125
Compare
42b9e85
to
94c3d70
Compare
Ok great. I added the qasm to the result generated by local_unitary_simulator too which seemed left out. |
* Adding the regression test * Adding compiled QASM to the result * Disable CPP backends if not available * Avoid copying unexistent QASM code * Moving `get_ran_qasm` test into the `test_wrapper.py` test suite. * add qasm to the unitary simulator too
Fix #671
Details and comments
Compiled QASM is part of the Qobj entity but it is required by the
Result
interface. This patch copies the QASM to theResult
instance to make it available.