Skip to content

Update target from_configuration#11461

Closed
MozammilQ wants to merge 26 commits into
Qiskit:mainfrom
MozammilQ:update_target_from_configuration
Closed

Update target from_configuration#11461
MozammilQ wants to merge 26 commits into
Qiskit:mainfrom
MozammilQ:update_target_from_configuration

Conversation

@MozammilQ
Copy link
Copy Markdown
Contributor

Summary

This PR updates logic of method:from_configuration() of class:Target in qiskit/transpiler/target.py

Credit:
@nkanazawa1989 , this logic is heavily influenced by Qiskit/qiskit-ibm-provider#413
@to24toro , for all the kind help and motivation :)
fixes: #10168

@MozammilQ MozammilQ requested a review from a team as a code owner December 27, 2023 17:48
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Dec 27, 2023
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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:

  • @Qiskit/terra-core

@MozammilQ
Copy link
Copy Markdown
Contributor Author

MozammilQ commented Dec 27, 2023

I am done :)

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 29, 2023

Pull Request Test Coverage Report for Build 8315422102

Details

  • 115 of 131 (87.79%) changed or added relevant lines in 1 file are covered.
  • 12 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 89.306%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/target.py 115 131 87.79%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 2 92.7%
qiskit/providers/backend_compat.py 10 80.22%
Totals Coverage Status
Change from base Build 8310563987: 0.02%
Covered Lines: 59825
Relevant Lines: 66989

💛 - Coveralls

@MozammilQ
Copy link
Copy Markdown
Contributor Author

I am sure this requires some further work, if the code remains the same there has to be some changes in the docstrings.
Probably should add some more tests to increase coverage :)
A review could provide me with better guidance for next steps :)

@nkanazawa1989 , please see if this good enough :)

@nkanazawa1989 nkanazawa1989 added the mod: transpiler Issues and PRs related to Transpiler label Jan 5, 2024
Copy link
Copy Markdown
Contributor

@to24toro to24toro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. I have a quick look and have some minor comments.

Comment thread qiskit/transpiler/target.py Outdated
concurrent_measurements=concurrent_measurements,
)
name_mapping = get_standard_gate_name_mapping()
required_operations = {"measure", "delay"}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Q] I don't still catch up fully, but are any errors detected if the delay operation here is not added.

Copy link
Copy Markdown
Contributor Author

@MozammilQ MozammilQ Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Copy Markdown
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Comment thread qiskit/transpiler/target.py Outdated
if name in qiskit_inst_mapping:
inst_name_map[name] = qiskit_inst_mapping[name]
else:
warnings.warn(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original implementation this raises KeyError, and this is sort of breaking API change since user may write try-except code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread qiskit/transpiler/target.py Outdated
Comment thread qiskit/transpiler/target.py Outdated
else:
raise TranspilerError(
f"The specified basis gate: {gate} has {gate_obj.num_qubits} "
f"The specified basis gate: {name} has {inst.num_qubits} "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me why this doesn't support >2 qubits? I just want to remember why we implemented like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread qiskit/transpiler/target.py Outdated
Comment thread qiskit/transpiler/target.py
Comment thread qiskit/transpiler/target.py
prop_name_map["measure"] = {}
for qubit_idx in range(num_qubits):
qubit_prop = backend_properties.qubit_property(qubit_idx)
duration = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Comment thread qiskit/transpiler/target.py
Comment thread qiskit/transpiler/target.py Outdated
# 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bit fragile because there is no guarantee that op is always single qubit operation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MozammilQ
Copy link
Copy Markdown
Contributor Author

MozammilQ commented Jan 5, 2024

I am done :)

@MozammilQ
Copy link
Copy Markdown
Contributor Author

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 ?

Not, sure my vote counts, but
1 Vote in for "adding required_operations as class attribute in Target"

@MozammilQ
Copy link
Copy Markdown
Contributor Author

@nkanazawa1989 , please see if this is good enough :)

@MozammilQ
Copy link
Copy Markdown
Contributor Author

@nkanazawa1989 , Please, see if this is good enough :)

@MozammilQ
Copy link
Copy Markdown
Contributor Author

@1ucian0 , Things have changed in Qiskit, I doubt if the PR is required anymore,
does this PR stands a chance of merging, if yes, what should be the direction of this PR ?

@jakelishman
Copy link
Copy Markdown
Member

Closing as stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: transpiler Issues and PRs related to Transpiler

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Target.from_configuration doesn't take measure instruction

6 participants