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 support for SwapGate, iSwapGate, and DCXGate #294

Merged
merged 21 commits into from
Jul 5, 2023
Merged

Add support for SwapGate, iSwapGate, and DCXGate #294

merged 21 commits into from
Jul 5, 2023

Conversation

garrison
Copy link
Member

@garrison garrison commented Jun 30, 2023

I might clean this up a bit, but hey -- it works. 🙂

Remaining action items

  • fix coverage (one line is currently missing)
  • clean up & add comments
  • add to release note (might need to rebase after Add support for cut ECRGate #292 is merged to please reno)
  • possibly add additional tests of kappa values from other recent gates
  • update supported gates in docstring

@garrison garrison added enhancement New feature or request cutting QPD-based circuit cutting code labels Jun 30, 2023
@garrison
Copy link
Member Author

This should get us 90% of the way to #186, as well. I'll know for sure once I get tests to pass for arbitrary gates.

@coveralls
Copy link

coveralls commented Jul 1, 2023

Pull Request Test Coverage Report for Build 5467379144

  • 53 of 53 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 90.286%

Totals Coverage Status
Change from base Build 5467253744: 0.2%
Covered Lines: 2435
Relevant Lines: 2697

💛 - Coveralls

@garrison garrison changed the title Add support for SwapGate Add support for SwapGate and iSwapGate Jul 1, 2023
@garrison garrison marked this pull request as ready for review July 1, 2023 03:10
@garrison garrison changed the title Add support for SwapGate and iSwapGate Add support for SwapGate, iSwapGate, and DCXGate Jul 1, 2023
garrison added a commit that referenced this pull request Jul 2, 2023
(np.abs(u[2]) ** 2, [YGate()], [YGate()]),
(np.abs(u[3]) ** 2, [ZGate()], [ZGate()]),
# Second line
(2 * np.real(uu01), A0x, A0x),
Copy link
Collaborator

@caleb-johnson caleb-johnson Jul 3, 2023

Choose a reason for hiding this comment

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

I'm a little confused why there are so many terms associated with lines 2 (and also 3) of eq 19. That summation should have 6 terms, and each of those terms looks like (uaua'* + ua'ua*)(Aaa' - Baa'). Can't quite figure out why there are 30 terms here

Copy link
Member Author

@garrison garrison Jul 3, 2023

Choose a reason for hiding this comment

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

The sum is over six possibilities, but on line two, there are actually two terms within the parentheses, so you'd expect 12 terms total. However, each boldface A or B operator actually is the sum (difference, really) of two channels [Eqs. (13) and (14)]. That's what the variables that end in p or m are about -- they're actually "plus" and "minus" versions of these channels. It turns out, we don't need to keep track of the "plus" and "minus" channels individually for ones that involve a mid-circuit measurement because QPDMeasure handles both cases, rather than thinking of them as two different projectors.

Everything above can be said for the third line, as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I was just coming here to say I see that it's 6+12+12. Thanks! :)

Copy link
Collaborator

@caleb-johnson caleb-johnson 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 great. Thanks for adding the tests we missed in earlier PRs 👍

@garrison garrison merged commit b76f9c6 into main Jul 5, 2023
9 checks passed
@garrison garrison deleted the swap-gate branch July 5, 2023 20:22
garrison added a commit that referenced this pull request Jul 26, 2023
* Add support for `SwapGate`

* Reorder terms

[ci skip]

* Add missing terms

* DRY the coefficients

* Fix coverage

* Add support for `iSwapGate`

* Fix black

* Add to release note

* Fix type hint

* Gates without parameters are nicer to work with

and can be singletons, one day!

* Remove a line

* Add comments describing channels

* `_copy_unique_sublists`

* Add `DCXGate`

* Tweak

* Implement cutting of general 2-qubit unitaries

Builds on #294.  Closes #186.

* Add tests of additional gates

* Fix type annotation

* Add explanatory comments

* `supported_gates()` -> `explicitly_supported_gates()`

* Add to references

* Improved error message and test about `to_matrix` conversion failing

* Add xref to `QPDBasis` in docstrings

* Add `qpdbasis_from_gate` to Sphinx build

* Make `explicitly_supported_gates` private and remove its release note

It's not clear that this function remains useful now that we
support essentially all 2-qubit gates.  If we find a use for it
in the future, we can re-introduce it (or something like it) as a
public interface.

* Fix intersphinx link

* Release note

* Update qpd.py: remove extraneous `from None`
caleb-johnson pushed a commit that referenced this pull request Jul 28, 2023
* Add support for `SwapGate`

* Reorder terms

[ci skip]

* Add missing terms

* DRY the coefficients

* Fix coverage

* Add support for `iSwapGate`

* Fix black

* Add to release note

* Fix type hint

* Gates without parameters are nicer to work with

and can be singletons, one day!

* Remove a line

* Add comments describing channels

* `_copy_unique_sublists`

* Add `DCXGate`

* Tweak

* Implement cutting of general 2-qubit unitaries

Builds on #294.  Closes #186.

* Add tests of additional gates

* Fix type annotation

* Add explanatory comments

* `supported_gates()` -> `explicitly_supported_gates()`

* Add to references

* Improved error message and test about `to_matrix` conversion failing

* Add xref to `QPDBasis` in docstrings

* Add `qpdbasis_from_gate` to Sphinx build

* Make `explicitly_supported_gates` private and remove its release note

It's not clear that this function remains useful now that we
support essentially all 2-qubit gates.  If we find a use for it
in the future, we can re-introduce it (or something like it) as a
public interface.

* Fix intersphinx link

* Release note

* Update qpd.py: remove extraneous `from None`
caleb-johnson added a commit that referenced this pull request Aug 14, 2023
* Don't batch unnecessarily

* mypy

* black

* Missing varname

* fix bug

* Clean up code

* Improve comments

* release note

* release note

* Update batch-by-sampler-c4ae836df9997b1d.yaml

* Update batch-by-sampler-c4ae836df9997b1d.yaml

* Update batch-by-sampler-c4ae836df9997b1d.yaml

* Bump Python version in Dockerfile to 3.11 (#331)

Now that CKT supports Python 3.11, we might as well use the latest version in the Dockerfile.

* Fix formatting of example in `reduce_bitstrings` docstring (#332)

* Implement cutting of general 2-qubit unitaries (#302)

* Add support for `SwapGate`

* Reorder terms

[ci skip]

* Add missing terms

* DRY the coefficients

* Fix coverage

* Add support for `iSwapGate`

* Fix black

* Add to release note

* Fix type hint

* Gates without parameters are nicer to work with

and can be singletons, one day!

* Remove a line

* Add comments describing channels

* `_copy_unique_sublists`

* Add `DCXGate`

* Tweak

* Implement cutting of general 2-qubit unitaries

Builds on #294.  Closes #186.

* Add tests of additional gates

* Fix type annotation

* Add explanatory comments

* `supported_gates()` -> `explicitly_supported_gates()`

* Add to references

* Improved error message and test about `to_matrix` conversion failing

* Add xref to `QPDBasis` in docstrings

* Add `qpdbasis_from_gate` to Sphinx build

* Make `explicitly_supported_gates` private and remove its release note

It's not clear that this function remains useful now that we
support essentially all 2-qubit gates.  If we find a use for it
in the future, we can re-introduce it (or something like it) as a
public interface.

* Fix intersphinx link

* Release note

* Update qpd.py: remove extraneous `from None`

* Improve the instructions regarding pandoc (#336)

I've also tried to make the developer documentation easier to discover

* Make the repository link more obvious from the Sphinx build (#338)

* Make the repository link more obvious from the Sphinx build

* Enable "edit" link in the header

* Add comment

* Add README badge linking to stable documentation (#339)

* Add docs badge to link to stable docs

* Add ruff badge

* Remove ruff

* Update README.md (#340)

Making directions on opening the docs a little more succinct.

* Change var name

* Add SECURITY.md (#337)

* Implement wire cutting as a two-qubit instruction (#174)

* Implement wire cutting as a two-qubit instruction

* Update type annotation

* s/gate/instruction/

* Add overhead test for `Move` instruction

* Add wire cutting tutorial

* Add `Move` to Sphinx build

* Doc updates suggested by Caleb

* Add release note and link to new tutorial

* Clarify wording

following #174 (comment)

* Improvements to `Move` docstring

* Use svg as the plot format

This avoids pixelation on high-dpi displays

* Remove unnecessary uses of `CircuitInstruction`

https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/pull/174/files#r1278067109

* The notebook tests should ignore any files that crop up in `docs/_build`

`matplotlib.sphinxext.plot_directive` likes to leave python files there

---------

Co-authored-by: Jim Garrison <garrison@ibm.com>
Co-authored-by: Ibrahim Shehzad <75153717+IbrahimShehzad@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cutting QPD-based circuit cutting code enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants