Skip to content
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

Add a new argument concurrent_measurements to target class #10258

Merged
merged 35 commits into from
Jul 20, 2023

Conversation

to24toro
Copy link
Contributor

@to24toro to24toro commented Jun 12, 2023

Summary

Make the Target class be aware of meas_map (concurrent_measurements is an alias). I added a new attribute concurrent_measurements to the from_configuration function and we can prepare for the Target class that has the info of the ScheduleConfig.

Details and comments

Need to review after #10150.
related to #10200.

@to24toro to24toro requested review from a team, eggerdj and wshanks as code owners June 12, 2023 01:59
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @nkanazawa1989

@nkanazawa1989 nkanazawa1989 self-assigned this Jun 12, 2023
@nkanazawa1989 nkanazawa1989 added the mod: pulse Related to the Pulse module label Jun 12, 2023
@to24toro to24toro changed the title Add a new argument meas_map to target.from_configuration Add a new argument meas_map to target class Jun 12, 2023
@nkanazawa1989 nkanazawa1989 added the Changelog: New Feature Include in the "Added" section of the changelog label Jun 12, 2023
Copy link
Collaborator

@TsafrirA TsafrirA left a comment

Choose a reason for hiding this comment

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

I have some minor suggestions for the doc strings which relate to the next point.

This goes beyond the scope of this PR, but I am not a fan of the fact that we use meas_map to describe two different representations (list vs. dict). At the very least, I think we should be clearly documenting this - What is accepted as input? What is the actual format used later on?

@@ -287,6 +290,7 @@ def __init__(
matches the qubit number the properties are defined for. If some
qubits don't have properties available you can set that entry to
``None``
meas_map(list, dict): List of sets of qubits that must be measured together.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The two representations of meas_map are accepted as input, but only one is documented here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So far, most part of the meas_map type is list and this is converted into Dict in inner codes. However, I think that 'meas_map' accepts Dict, e.g. macros.measure, in some cases because Dict of meas_map is easy to understand intuitively rather than List if there exist hardware constraints.

I treated the meas_map type as Dict and implemented macros.measure in backendV2. (It seems that format_measmap was implemented because it is easier to use for Dict than for List.)
So, if the input is a List, I would like to use format_measmap to convert the List to a Dict, and accept both List and Dict as input.

@@ -1263,6 +1269,7 @@ def from_configuration(
instruction_durations: Optional instruction durations for instructions. If specified
it will take priority for setting the ``duration`` field in the
:class:`~InstructionProperties` objects for the instructions in the target.
meas_map: List of sets of qubits that must be measured together.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, only one of the two accepted formats is documented here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you pointed out, the document is not easy for users or developers to understand.
I fixed at 407f87d .

@@ -322,6 +326,7 @@ def __init__(
"length of the input qubit_properties list"
)
self.qubit_properties = qubit_properties
self.meas_map = format_meas_map(meas_map) if isinstance(meas_map, list) else meas_map
Copy link
Collaborator

Choose a reason for hiding this comment

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

Despite documenting the list option in the doc string, we actually convert to the dictionary option here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to convert the data format here? Probably this is bit confusing to users if input data is implicitly modified. Since formatted meas map is useful for implementing pulse scheduling, probably we can do this format in the scheduler. Then we can restrict the input to list format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed at dc45405.

@@ -1306,6 +1313,7 @@ def from_configuration(
pulse_alignment=pulse_alignment,
acquire_alignment=acquire_alignment,
qubit_properties=qubit_properties,
meas_map=format_meas_map(meas_map) if isinstance(meas_map, list) else meas_map,
Copy link
Collaborator

Choose a reason for hiding this comment

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

And again, the inconsistency between the doc string and the actual format used later.

@coveralls
Copy link

coveralls commented Jun 18, 2023

Pull Request Test Coverage Report for Build 5597675106

  • 4 of 5 (80.0%) changed or added relevant lines in 3 files are covered.
  • 17 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.007%) to 86.048%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/providers/fake_provider/utils/backend_converter.py 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
qiskit/extensions/quantum_initializer/squ.py 2 80.0%
crates/qasm2/src/lex.rs 3 91.14%
crates/qasm2/src/parse.rs 12 96.18%
Totals Coverage Status
Change from base Build 5597428209: -0.007%
Covered Lines: 72684
Relevant Lines: 84469

💛 - Coveralls

nkanazawa1989
nkanazawa1989 previously approved these changes Jul 18, 2023
Copy link
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.

This looks good to me. Just to make sure

@mtreinish Are you fine with updating the Target model at Qiskit level? Alternatively we can do this in IBM provider, however pulse and circuit scheduler may rely on this constraint and exposing this in general Target makes sense to me (as long as Qiskit provides schedulers).

@wshanks We assume concurrent_measurements (aka meas_map) is just a static list of sub qubits measured together. Can future/non-IBM backend expose different constraints? If so probably we should make Target.concurrent_measurements a method so that we can do some formatting/operation in future.

qiskit/transpiler/target.py Outdated Show resolved Hide resolved
qiskit/transpiler/target.py Outdated Show resolved Hide resolved
@wshanks
Copy link
Contributor

wshanks commented Jul 18, 2023

We assume concurrent_measurements (aka meas_map) is just a static list of sub qubits measured together. Can future/non-IBM backend expose different constraints? If so probably we should make Target.concurrent_measurements a method so that we can do some formatting/operation in future.

@nkanazawa1989 Do you have anything specific in mind? The current status is that all IBM hardware backends currently put all qubits into one measurement group. I think this is mainly a software constraint left over from how the system was originally designed with a single acquisition trigger. Beyond that, I could imagine qubits being split into groups based on multiplexed readout -- requiring qubits on the same output line to be measured simultaneously (I could also imagine not having this constraint). Those are the most concrete constraints I can suggest. I don't know other qubit architectures that well though.

@mtreinish
Copy link
Member

@mtreinish Are you fine with updating the Target model at Qiskit level? Alternatively we can do this in IBM provider, however pulse and circuit scheduler may rely on this constraint and exposing this in general Target makes sense to me (as long as Qiskit provides schedulers).

I'm fine with adding it. I'll defer to both you and @wshanks on how common you think it'll be. If you guys think it's a common constraint that is not just a custom implementation detail for IBM hardware then I'm fine adding it as an optional field to the target. My thinking is for multiplexed readout it feels like this would be a common thing if other hardware does that and we want to support scheduling for that. But I'm also much less familiar with these hardware constraints.

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
@nkanazawa1989
Copy link
Contributor

Thanks @wshanks , @mtreinish sounds like we can go with current assumption. What I had in mind was some edge case that cannot bootstrap sub-qubit lists, e.g. qubit group may change depending on inclusion of a particular qubit -- in this case concurrent_measurements should take some input (it's pretty tough to promote attribute to method). Likely this is just an overengineering.

I'll merge this PR as-is. Thanks for your input!

@nkanazawa1989 nkanazawa1989 changed the title Add a new argument meas_map to target class Add a new argument concurrent_measurements to target class Jul 19, 2023
@mtreinish mtreinish added this to the 0.25.0 milestone Jul 19, 2023
@nkanazawa1989 nkanazawa1989 added this pull request to the merge queue Jul 20, 2023
Merged via the queue into Qiskit:main with commit f492c45 Jul 20, 2023
13 checks passed
ElePT pushed a commit to ElePT/qiskit-ibm-provider that referenced this pull request Oct 4, 2023
…skit#10258)

* fix measure_v2

* modify measure_all

* dispatch backend

* add test of the builder with backendV2

* reconfigure test codes and some func

* refactoring

* add reno

* fix _measure_v2

* fix backend.meas_map in measure_v2

* fix reno

* delete get_qubit_channels from utils

* add get_qubits_channels in qubit_channels

* recostruct test about the builder with backendV2

* add meas_map to Target class

* fix after mergin main branch

* fix documents about meas_map

* format target.py

* add reno

* add meas_map to target in convert_to_target

* add the more description about meas_map

* Update releasenotes/notes/enable_target_aware_meas_map-0d8542402a74e9d8.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* fix test_meas_map

* remove format_meas_map

* rename meas_map in target to concurrent_measuments

* change reno

* remove Unused Union Dict

* concurrent_measurements set as getattr(configuration, meas_map)

* Update qiskit/transpiler/target.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* Update qiskit/transpiler/target.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* format

---------

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
ElePT pushed a commit to ElePT/qiskit-ibm-runtime that referenced this pull request Oct 10, 2023
…skit#10258)

* fix measure_v2

* modify measure_all

* dispatch backend

* add test of the builder with backendV2

* reconfigure test codes and some func

* refactoring

* add reno

* fix _measure_v2

* fix backend.meas_map in measure_v2

* fix reno

* delete get_qubit_channels from utils

* add get_qubits_channels in qubit_channels

* recostruct test about the builder with backendV2

* add meas_map to Target class

* fix after mergin main branch

* fix documents about meas_map

* format target.py

* add reno

* add meas_map to target in convert_to_target

* add the more description about meas_map

* Update releasenotes/notes/enable_target_aware_meas_map-0d8542402a74e9d8.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* fix test_meas_map

* remove format_meas_map

* rename meas_map in target to concurrent_measuments

* change reno

* remove Unused Union Dict

* concurrent_measurements set as getattr(configuration, meas_map)

* Update qiskit/transpiler/target.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* Update qiskit/transpiler/target.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* format

---------

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
ElePT pushed a commit to ElePT/qiskit that referenced this pull request Oct 12, 2023
)

* fix measure_v2

* modify measure_all

* dispatch backend

* add test of the builder with backendV2

* reconfigure test codes and some func

* refactoring

* add reno

* fix _measure_v2

* fix backend.meas_map in measure_v2

* fix reno

* delete get_qubit_channels from utils

* add get_qubits_channels in qubit_channels

* recostruct test about the builder with backendV2

* add meas_map to Target class

* fix after mergin main branch

* fix documents about meas_map

* format target.py

* add reno

* add meas_map to target in convert_to_target

* add the more description about meas_map

* Update releasenotes/notes/enable_target_aware_meas_map-0d8542402a74e9d8.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* fix test_meas_map

* remove format_meas_map

* rename meas_map in target to concurrent_measuments

* change reno

* remove Unused Union Dict

* concurrent_measurements set as getattr(configuration, meas_map)

* Update qiskit/transpiler/target.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* Update qiskit/transpiler/target.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* format

---------

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
ElePT pushed a commit to ElePT/qiskit-ibm-runtime that referenced this pull request Dec 8, 2023
…skit#10258)

* fix measure_v2

* modify measure_all

* dispatch backend

* add test of the builder with backendV2

* reconfigure test codes and some func

* refactoring

* add reno

* fix _measure_v2

* fix backend.meas_map in measure_v2

* fix reno

* delete get_qubit_channels from utils

* add get_qubits_channels in qubit_channels

* recostruct test about the builder with backendV2

* add meas_map to Target class

* fix after mergin main branch

* fix documents about meas_map

* format target.py

* add reno

* add meas_map to target in convert_to_target

* add the more description about meas_map

* Update releasenotes/notes/enable_target_aware_meas_map-0d8542402a74e9d8.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* fix test_meas_map

* remove format_meas_map

* rename meas_map in target to concurrent_measuments

* change reno

* remove Unused Union Dict

* concurrent_measurements set as getattr(configuration, meas_map)

* Update qiskit/transpiler/target.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* Update qiskit/transpiler/target.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* format

---------

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog mod: pulse Related to the Pulse module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants