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

Update TketBackend to derive from BackendV2 #389

Merged
merged 4 commits into from
Sep 10, 2024
Merged

Update TketBackend to derive from BackendV2 #389

merged 4 commits into from
Sep 10, 2024

Conversation

cqc-alec
Copy link
Collaborator

@cqc-alec cqc-alec commented Sep 9, 2024

Closes #350 .

This change would break one of the examples in the manual, and perhaps also one or two places in the example notebooks (I haven't checked). This shouldn't affect the docs build since it's pinned to a specific version of pytket-qiskit, but we should probably revise those sections. It seems that the relevant parts of qiskit_algorithms (a community-maintained project) haven't yet been updated to use the new backend class.

This PR removes the last of the deprecation warnings from the qiskit tests that were coming from our code.

@cqc-alec cqc-alec changed the title Tketbackend Update TketBackend to derive from BackendV2 Sep 9, 2024
@cqc-alec cqc-alec marked this pull request as ready for review September 9, 2024 15:49
gate_name = _gate_str_2_optype_rev[optype]
if gate_name in standard_gate_mapping:
gate_obj = standard_gate_mapping[gate_name]
if gate_obj.num_qubits in [1, 2] or inspect.isclass(gate_obj):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See https://github.com/Qiskit/qiskit/blob/2ef371ae0d159a6dfd643805f3e5e5fdec37ab88/qiskit/transpiler/target.py#L1066 -- have to restrict the gateset to match what is accepted by the Target method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do I understand correctly that the gate_obj variable is not always a class? Presumably thats why the inspect check is needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, some gates such as CCX were rejected when I omitted this check. I am not sure when gate_obj is a class, but simply copied that from the code linked above.

Copy link
Contributor

@CalMacCQ CalMacCQ 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 :) just a few very minor comments

]
basis_gates = []
for optype in pred.gate_set:
if optype in _gate_str_2_optype_rev.keys():
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps worth adding a comment explaining what these "if" statements are for?

from pytket.architecture import FullyConnected


def _extract_basis_gates(backend: Backend) -> list[str]:
standard_gate_mapping = get_standard_gate_name_mapping()
for pred in backend.required_predicates:
if type(pred) == GateSetPredicate:
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather pedantic but is there a reason not to use "is" or "isinstance" here vs "=="?

Copy link
Contributor

@CalMacCQ CalMacCQ left a comment

Choose a reason for hiding this comment

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

Thanks :)

@cqc-alec cqc-alec merged commit 30855b1 into main Sep 10, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DeprecationWarning: V1 fake backends
2 participants