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

fix: Allow circuits containing CnZ gates to run on AerBackend #369

Merged
merged 12 commits into from
Sep 10, 2024

Conversation

yoshi-qc
Copy link
Contributor

Description

Replace CnY and CnZ in qiskit gates
519a512?diff=split&w=1

Make a test function
9412856?diff=split&w=0

Related issues

#368

Checklist

  • I have performed a self-review of my code.
  • I have commented hard-to-understand parts of my code.
  • I have made corresponding changes to the public API documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the changelog with any user-facing changes.

@yoshi-qc yoshi-qc self-assigned this Jul 23, 2024
@yoshi-qc yoshi-qc requested a review from cqc-melf as a code owner July 23, 2024 06:44
@@ -702,7 +702,9 @@ def append_tk_command_to_qiskit(
if optype == OpType.CnY:
return qcirc.append(qiskit_gates.YGate().control(len(qargs) - 1), qargs)
if optype == OpType.CnZ:
return qcirc.append(qiskit_gates.ZGate().control(len(qargs) - 1), qargs)
new_gate = qiskit_gates.ZGate().control(len(qargs) - 1)
new_gate.name = "mcz"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you freely choose this name? Could we do cnz?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately 'cnz' doesn't work because AerSimulater accepts the name 'mcz'.
In general, AerSimulater accepts the gete list on blow
#368 (comment)

tests/backend_test.py Outdated Show resolved Hide resolved
@CalMacCQ
Copy link
Contributor

CalMacCQ commented Aug 20, 2024

Maybe the changelog should be updated as well for this fix?

https://github.com/CQCL/pytket-qiskit/blob/main/docs/changelog.rst

@cqc-alec cqc-alec requested a review from CalMacCQ September 10, 2024 10:18
@@ -13,6 +13,7 @@ Unreleased
* Add conversion of controlled unitary gates from qiskit to tket.
* Initialize `TketAutoPass` with a `BackendV2`.
* Update `TketBackend` to derive from `BackendV2`.
* Fix to allow `AerBackend` to work with multi-controlled Y and Z gates.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the handling of multi-controlled-Y gates has been changed in this PR. I think its just multi-controlled-Z gates that are given a different name.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes you're right.

compilation_pass = b.default_compilation_pass(i)
compilation_pass.apply(circ)
unitary_after = circ.get_unitary()
assert compare_unitaries(unitary_before, unitary_after)
Copy link
Contributor

@CalMacCQ CalMacCQ Sep 10, 2024

Choose a reason for hiding this comment

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

Is unitary comparision needed in this test? I guess we just want to verify that the circuit containing the CnZ is runable on AerBackend. Not sure what the purpose of checking that the unitary is the same before/after compilation is for. Guess it does no harm.

I don't think the handling of the other multi-controlled gates has changed at all

Copy link
Collaborator

Choose a reason for hiding this comment

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

True, it would be more useful to have a test that the circuit ran correctly, to confirm that the conversion was correct. I'll change the test.

@cqc-alec cqc-alec requested a review from CalMacCQ September 10, 2024 10:48
@CalMacCQ CalMacCQ changed the title Replace CnY and CnZ in qiskit gates fix: Allow circuits containing CnZ gates to Run on AerBackend Sep 10, 2024
@CalMacCQ CalMacCQ changed the title fix: Allow circuits containing CnZ gates to Run on AerBackend fix: Allow circuits containing CnZ gates to run on AerBackend Sep 10, 2024
@CalMacCQ
Copy link
Contributor

Changed the PR title for clarity

@cqc-alec cqc-alec merged commit 59d733d 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.

AerBackend fails to run circuits containing c3z instructions
4 participants