Skip to content

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented Apr 4, 2023

Summary

Add flag to filter faulty qubits and gates to BackendV2Converter

This commit adds a flag to filter faulty qubits or gates from the
created target when using BackendV2Converter. The BackendProperties
object had a rarely used feature to annotate qubits or gates as being
non-operational and previously the BackendV2Converter would
unconditionally include qubits and gates with this flag set in the
output Target and BackendV2 instance. This new flag will enable users to
filter these if that is more desireable behavior. When filtering is set
the backend will still be listed as full width but any faulty qubits
will just not include any operations.

Details and comments

Fixes #9910

@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Apr 4, 2023
@mtreinish mtreinish added this to the 0.24.0 milestone Apr 4, 2023
@qiskit-bot
Copy link
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

@coveralls
Copy link

coveralls commented Apr 4, 2023

Pull Request Test Coverage Report for Build 4618888219

  • 15 of 16 (93.75%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.008%) to 85.441%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/providers/backend_compat.py 15 16 93.75%
Totals Coverage Status
Change from base Build 4617662891: 0.008%
Covered Lines: 67657
Relevant Lines: 79186

💛 - Coveralls

This commit adds a flag to filter faulty qubits or gates from the
created target when using `BackendV2Converter`. The BackendProperties
object had a rarely used feature to annotate qubits or gates as being
non-operational and previously the BackendV2Converter would
unconditionally include qubits and gates with this flag set in the
output Target and BackendV2 instance. This new flag will enable users to
filter these if that is more desireable behavior. When filtering is set
the backend will still be listed as full width but any faulty qubits
will just not include any operations.

Fixes Qiskit#9910
@mtreinish mtreinish changed the title [WIP] Add flag to filter faulty qubits and gates to BackendV2Converter Add flag to filter faulty qubits and gates to BackendV2Converter Apr 5, 2023
@mtreinish mtreinish marked this pull request as ready for review April 5, 2023 12:05
@mtreinish mtreinish requested review from a team and jyu00 as code owners April 5, 2023 12:05
jakelishman
jakelishman previously approved these changes Apr 5, 2023
Copy link
Member

@jakelishman jakelishman 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 relatively straightforwards to me. Transpilation can't succeed on faulty qubits in this form until we have #9840 as well, but I checked that this produces backends that are correctly handled end-to-end in transpile if there's faulty gates but the coupling map is still connected.

For example (Yorktown is a 5q bowtie with qubit 2 at the centre):

import datetime
import itertools

from qiskit import QuantumCircuit, transpile
from qiskit.providers.fake_provider import FakeYorktown
from qiskit.providers.models import BackendProperties
from qiskit.providers import BackendV2Converter

non_operational = {
    "date": datetime.datetime.now(),
    "name": "operational",
    "unit": "",
    "value": 0,
}

def remove_gate(backend):
    props = backend.properties().to_dict()
    for gate in props["gates"]:
        if tuple(sorted(gate["qubits"])) == (0, 1):
            gate["parameters"].append(non_operational)
    backend._properties = BackendProperties.from_dict(props)
    return backend

def connected(n):
    out = QuantumCircuit(n)
    for x, y in itertools.product(range(n), range(n)):
        if x == y:
            continue
        out.cx(x, y)
    return out

transpiled = transpile(
    connected(5),
    BackendV2Converter(remove_gate(FakeYorktown()), filter_faulty=True),
    initial_layout=[0, 1, 2, 3, 4],
)
connections = [tuple(sorted(transpiled.find_bit(q).index for q in x.qubits)) for x in transpiled.data]
assert (0, 1) not in connections

It might be nice to add an integration test to that effect, since we're anticipating this kind of thing being useful to providers. We could also potentially look to merge #9840 ahead of this, and then also add a similar test that a faulty qubit isn't assigned any operations, etc.

I don't feel super strongly, though, so I'd be ok merging as-is if there's a better PR ordering.

@mtreinish
Copy link
Member Author

I'll add a test based on your code here. It's good to test that. We can expand the testing further after #9840 merges to test with disconnected faulty qubits. I left out the full path testing because I was waiting for #9840 but I hadn't considered having a connected coupling graph with a faulty edge like that.

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Looks good to me. As you say, we can add more tests after we've got proper disjoint-map support.

@jakelishman jakelishman enabled auto-merge April 5, 2023 13:18
@jakelishman jakelishman added this pull request to the merge queue Apr 5, 2023
Merged via the queue into Qiskit:main with commit 06ca177 Apr 5, 2023
@mtreinish mtreinish deleted the filter-faulty branch April 5, 2023 20:12
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Apr 6, 2023
Building off Qiskit#9840 which adds full path support in all the preset pass
managers for targetting backends with a disconnected coupling graph,
this commit adds support for ignoring qubits that do not support any
operations. When a Target is generated from Qiskit#9911 with `filter_faulty`
set to `True` this will potentially result in qubits being present in
the `Target` without any supported operations. In these cases the
layout passes in the transpiler might inadvertently use these qubits
only to fail in the basis translator because there are no instructions
available. This commit adds filtering of connected components from the
list of output connected components if the `Target` does have any
supported instructions on a qubit.

This works by building a copy of the coupling map's internal graph
that removes the nodes which do not have any supported operations.
Then when we compute the connected components of this graph it will
exclude any components of isolated qubits without any operations
supported. A similar change is made to the coupling graph we pass to
rustworkx.vf2_mapping() inside the vf2 layout family of passes.
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Apr 13, 2023
Building off Qiskit#9840 which adds full path support in all the preset pass
managers for targetting backends with a disconnected coupling graph,
this commit adds support for ignoring qubits that do not support any
operations. When a Target is generated from Qiskit#9911 with `filter_faulty`
set to `True` this will potentially result in qubits being present in
the `Target` without any supported operations. In these cases the
layout passes in the transpiler might inadvertently use these qubits
only to fail in the basis translator because there are no instructions
available. This commit adds filtering of connected components from the
list of output connected components if the `Target` does have any
supported instructions on a qubit.

This works by building a copy of the coupling map's internal graph
that removes the nodes which do not have any supported operations.
Then when we compute the connected components of this graph it will
exclude any components of isolated qubits without any operations
supported. A similar change is made to the coupling graph we pass to
rustworkx.vf2_mapping() inside the vf2 layout family of passes.
giacomoRanieri pushed a commit to giacomoRanieri/qiskit-terra that referenced this pull request Apr 16, 2023
…kit#9911)

* Add flag to filter faulty qubits and gates to BackendV2Converter

This commit adds a flag to filter faulty qubits or gates from the
created target when using `BackendV2Converter`. The BackendProperties
object had a rarely used feature to annotate qubits or gates as being
non-operational and previously the BackendV2Converter would
unconditionally include qubits and gates with this flag set in the
output Target and BackendV2 instance. This new flag will enable users to
filter these if that is more desireable behavior. When filtering is set
the backend will still be listed as full width but any faulty qubits
will just not include any operations.

Fixes Qiskit#9910

* Add full path transpile tests

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Apr 17, 2023
Building off Qiskit#9840 which adds full path support in all the preset pass
managers for targetting backends with a disconnected coupling graph,
this commit adds support for ignoring qubits that do not support any
operations. When a Target is generated from Qiskit#9911 with `filter_faulty`
set to `True` this will potentially result in qubits being present in
the `Target` without any supported operations. In these cases the
layout passes in the transpiler might inadvertently use these qubits
only to fail in the basis translator because there are no instructions
available. This commit adds filtering of connected components from the
list of output connected components if the `Target` does have any
supported instructions on a qubit.

This works by building a copy of the coupling map's internal graph
that removes the nodes which do not have any supported operations.
Then when we compute the connected components of this graph it will
exclude any components of isolated qubits without any operations
supported. A similar change is made to the coupling graph we pass to
rustworkx.vf2_mapping() inside the vf2 layout family of passes.
kevinhartman added a commit that referenced this pull request Apr 18, 2023
* Filter/ignore qubits in Target without any operations

Building off #9840 which adds full path support in all the preset pass
managers for targetting backends with a disconnected coupling graph,
this commit adds support for ignoring qubits that do not support any
operations. When a Target is generated from #9911 with `filter_faulty`
set to `True` this will potentially result in qubits being present in
the `Target` without any supported operations. In these cases the
layout passes in the transpiler might inadvertently use these qubits
only to fail in the basis translator because there are no instructions
available. This commit adds filtering of connected components from the
list of output connected components if the `Target` does have any
supported instructions on a qubit.

This works by building a copy of the coupling map's internal graph
that removes the nodes which do not have any supported operations.
Then when we compute the connected components of this graph it will
exclude any components of isolated qubits without any operations
supported. A similar change is made to the coupling graph we pass to
rustworkx.vf2_mapping() inside the vf2 layout family of passes.

* Expand testing

* Make filtered qubit coupling map a Target.build_coupling_map option

This commit reworks the logic to construct a filtered coupling map as an
optional argument on `Target.build_coupling_map()`. This makes the
filtering a function of the Target object itself, which is where the
context/data about which qubits support operations or not lives. The
previous versions of this PR had a weird mix of responsibilities where
the target would generate a coupling map and then we'd pass the target
to that coupling map to do an additional round of filtering on it.

* Apply suggestions from code review

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>

* Fix incorrect set construction

* Expand docstring on build_coupling_map argument

* Rework logic in vf2 passes for filtering

* Update argument name in disjoint_utils.py

* Inline second argument for require_layout_isolated_to_component

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Update qiskit/transpiler/passes/layout/vf2_post_layout.py

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Apply suggestions from code review

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Remove unnecessary len()

* Inline second arg for dense_layout too

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Kevin Hartman <kevin@hart.mn>
king-p3nguin pushed a commit to king-p3nguin/qiskit-terra that referenced this pull request May 22, 2023
…kit#9911)

* Add flag to filter faulty qubits and gates to BackendV2Converter

This commit adds a flag to filter faulty qubits or gates from the
created target when using `BackendV2Converter`. The BackendProperties
object had a rarely used feature to annotate qubits or gates as being
non-operational and previously the BackendV2Converter would
unconditionally include qubits and gates with this flag set in the
output Target and BackendV2 instance. This new flag will enable users to
filter these if that is more desireable behavior. When filtering is set
the backend will still be listed as full width but any faulty qubits
will just not include any operations.

Fixes Qiskit#9910

* Add full path transpile tests

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
king-p3nguin pushed a commit to king-p3nguin/qiskit-terra that referenced this pull request May 22, 2023
* Filter/ignore qubits in Target without any operations

Building off Qiskit#9840 which adds full path support in all the preset pass
managers for targetting backends with a disconnected coupling graph,
this commit adds support for ignoring qubits that do not support any
operations. When a Target is generated from Qiskit#9911 with `filter_faulty`
set to `True` this will potentially result in qubits being present in
the `Target` without any supported operations. In these cases the
layout passes in the transpiler might inadvertently use these qubits
only to fail in the basis translator because there are no instructions
available. This commit adds filtering of connected components from the
list of output connected components if the `Target` does have any
supported instructions on a qubit.

This works by building a copy of the coupling map's internal graph
that removes the nodes which do not have any supported operations.
Then when we compute the connected components of this graph it will
exclude any components of isolated qubits without any operations
supported. A similar change is made to the coupling graph we pass to
rustworkx.vf2_mapping() inside the vf2 layout family of passes.

* Expand testing

* Make filtered qubit coupling map a Target.build_coupling_map option

This commit reworks the logic to construct a filtered coupling map as an
optional argument on `Target.build_coupling_map()`. This makes the
filtering a function of the Target object itself, which is where the
context/data about which qubits support operations or not lives. The
previous versions of this PR had a weird mix of responsibilities where
the target would generate a coupling map and then we'd pass the target
to that coupling map to do an additional round of filtering on it.

* Apply suggestions from code review

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>

* Fix incorrect set construction

* Expand docstring on build_coupling_map argument

* Rework logic in vf2 passes for filtering

* Update argument name in disjoint_utils.py

* Inline second argument for require_layout_isolated_to_component

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Update qiskit/transpiler/passes/layout/vf2_post_layout.py

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Apply suggestions from code review

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Remove unnecessary len()

* Inline second arg for dense_layout too

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Kevin Hartman <kevin@hart.mn>
ElePT pushed a commit to ElePT/qiskit-ibm-provider that referenced this pull request Oct 9, 2023
…kit/qiskit#9911)

* Add flag to filter faulty qubits and gates to BackendV2Converter

This commit adds a flag to filter faulty qubits or gates from the
created target when using `BackendV2Converter`. The BackendProperties
object had a rarely used feature to annotate qubits or gates as being
non-operational and previously the BackendV2Converter would
unconditionally include qubits and gates with this flag set in the
output Target and BackendV2 instance. This new flag will enable users to
filter these if that is more desireable behavior. When filtering is set
the backend will still be listed as full width but any faulty qubits
will just not include any operations.

Fixes Qiskit/qiskit#9910

* Add full path transpile tests

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add handling for operational, faulty_{qubits,gates} to convert_to_target
4 participants