Update target from_configuration#11461
Conversation
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
|
I am done :) |
Pull Request Test Coverage Report for Build 8315422102Details
💛 - Coveralls |
|
I am sure this requires some further work, if the code remains the same there has to be some changes in the docstrings. @nkanazawa1989 , please see if this good enough :) |
to24toro
left a comment
There was a problem hiding this comment.
Thanks for your contribution. I have a quick look and have some minor comments.
| concurrent_measurements=concurrent_measurements, | ||
| ) | ||
| name_mapping = get_standard_gate_name_mapping() | ||
| required_operations = {"measure", "delay"} |
There was a problem hiding this comment.
[Q] I don't still catch up fully, but are any errors detected if the delay operation here is not added.
There was a problem hiding this comment.
if 'delay' is removed here,
target does not have delay, because you see,
'delay' is only added when delay is present in 'required_operations'
'delay' is added into inst_name_map through required_operations
then, delay is added to prop_name_map
then finally, delay is added to target through inst_name_map and prop_name_map
To avoid all this hassle,
One, could just write something like this at the very end before return target
if in_data_target['num_qubits'] is not None:
target.add_instruction(
instruction=qiskit_inst_mapping.get('delay'),
properties={(q,): None for q in range(num_qubits) if q not in faulty_qubits},
name='delay'
)My opinion is, it's just a personal preference :)
Naoki , Kento, please correct me if I am missing something :)
nkanazawa1989
left a comment
There was a problem hiding this comment.
Thanks @MozammilQ this is nice improvements. Overall implementation looks good, however, since multiple sources for duration are allowed in the current logic, implementation must become more complicated. Probably we need more test cases with multiple sources with different duration values.
I often see implicitly defined required_operations (they are mostly measure and delay) in multiple places in the Qiskit codebase. I think Target must provide this information with its class attribute so that developers can easily find the minimum instruction requirements for transpiler. What do you think @mtreinish ?
| if name in qiskit_inst_mapping: | ||
| inst_name_map[name] = qiskit_inst_mapping[name] | ||
| else: | ||
| warnings.warn( |
There was a problem hiding this comment.
In the original implementation this raises KeyError, and this is sort of breaking API change since user may write try-except code.
There was a problem hiding this comment.
Yes, you are right keeping 'KeyError' is wise move here, because user might catch the error, add something in custom_name_mapping or basis_gates etc and run .from_configuration() all over again to get the target.
I thought I would change it to TranspilerError, if you do not like I would put KeyError back.
| else: | ||
| raise TranspilerError( | ||
| f"The specified basis gate: {gate} has {gate_obj.num_qubits} " | ||
| f"The specified basis gate: {name} has {inst.num_qubits} " |
There was a problem hiding this comment.
Can you remind me why this doesn't support >2 qubits? I just want to remember why we implemented like this.
There was a problem hiding this comment.
I really didn't want to keep it like that, but I am very reluctant to do changes in original code base, so I kept it that way.
This is all I have got:
https://github.com/Qiskit/qiskit/pull/9255/files#r1162884200
and,
#11405 (comment)
Apologies
| prop_name_map["measure"] = {} | ||
| for qubit_idx in range(num_qubits): | ||
| qubit_prop = backend_properties.qubit_property(qubit_idx) | ||
| duration = ( |
There was a problem hiding this comment.
The same logic must be applied here because instruction duration and inst map can be also another source of duration (this design itself is not good though).
There was a problem hiding this comment.
I was not sure if the docstrings should be changed or the logic itself should be changed. That's why I request your guidance :)
Applied suggestion :)
I request you to tell a bit more about the flaw in the design :)
| # Map required ops to each operational qubit | ||
| if prop_name_map[op] is None: | ||
| prop_name_map[op] = { | ||
| (q,): None for q in range(num_qubits) if q not in faulty_qubits |
There was a problem hiding this comment.
This is bit fragile because there is no guarantee that op is always single qubit operation.
There was a problem hiding this comment.
removed the logic all together,
[humble suggestion]:
when we will add something which is not a single qubit operation in required_operations, then in the same PR we will deal with this at that time.
|
I am done :) |
Not, sure my vote counts, but |
|
@nkanazawa1989 , please see if this is good enough :) |
|
@nkanazawa1989 , Please, see if this is good enough :) |
|
@1ucian0 , Things have changed in Qiskit, I doubt if the PR is required anymore, |
|
Closing as stale |
Summary
This PR updates logic of method:
from_configuration()of class:Targetinqiskit/transpiler/target.pyCredit:
@nkanazawa1989 , this logic is heavily influenced by Qiskit/qiskit-ibm-provider#413
@to24toro , for all the kind help and motivation :)
fixes: #10168