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

Optimal Synthesis into RXX(theta) #6551

Merged
merged 20 commits into from
Nov 3, 2021
Merged

Optimal Synthesis into RXX(theta) #6551

merged 20 commits into from
Nov 3, 2021

Conversation

ecpeterson
Copy link
Contributor

@ecpeterson ecpeterson commented Jun 9, 2021

Summary

This PR installs moves a few TwoQubitBasisDecomposer constructors into a helper, then constructs an XXDecomposer if the target gateset includes rzx. This implements some internal, nearly-published theory work.

Details and comments

Here's a brief usage demonstration:

from qiskit import transpile, QuantumRegister, QuantumCircuit
from qiskit.quantum_info import random_unitary
import numpy as np

# generate a random unitary
u = random_unitary(4)

q = QuantumRegister(2)
circuit = QuantumCircuit(q)
circuit.append(u, q)
output_circuit, = transpile([circuit], optimization_level=1, basis_gates=['rzx', 'rz', 'sx'], translation_method='synthesis')

print(output_circuit)

@ajavadia
Copy link
Member

The rzx angles are not mentioned anywhere in the sample code. I know this is a limitation of basis_gates but how do you supply that?

@ecpeterson
Copy link
Contributor Author

ecpeterson commented Jun 14, 2021

@ajavadia : At present, this is hard-coded in the internal package, exactly because I didn't want to make a decision about how basis_gates should be modified to cope with parameters. I'd love to hear opinions, of course.

@ecpeterson ecpeterson changed the title Synthesis into RZX via monodromy Synthesis into RZX Oct 28, 2021
@ecpeterson ecpeterson marked this pull request as ready for review October 28, 2021 19:40
@ecpeterson ecpeterson requested review from chriseclectic and a team as code owners October 28, 2021 19:40
@ajavadia ajavadia self-assigned this Nov 1, 2021
Copy link
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

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

I'm checking the code functionality. When I run this:

from qiskit import transpile, QuantumRegister, QuantumCircuit
from qiskit.quantum_info import random_unitary
import numpy as np

# generate a random unitary
u = random_unitary(4, seed=9)

q = QuantumRegister(2)
circuit = QuantumCircuit(q)
circuit.append(u, q)
output_circuit = transpile(circuit, basis_gates=['rzx', 'rz', 'sx'], translation_method='synthesis')

output_circuit.draw('mpl')

I get two uses of RZX(pi/4) and one use of CX:

image

However when I change translation_method='translator' I get something that can be simplified to just two uses of RZX(pi/4) (not sure why it emits RZX(-pi/4) at all, but it does). this

image

And finally when I use translation_method='unroller' it errors (I guess that's separate from this PR but it would be good to get to the bottom of it).

qiskit/quantum_info/synthesis/rzx_decompose/__init__.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/rzx_decompose/__init__.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/rzx_decompose/circuits.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/rzx_decompose/circuits.py Outdated Show resolved Hide resolved
@ajavadia ajavadia changed the title Synthesis into RZX Optimal Synthesis into RXX(theta) Nov 2, 2021
Copy link
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

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

This is looking mostly good, and thanks for the recent updates. I left some comments which shouldn't be too much work, mostly around documenting user interfaces.

I think the main thing that I will work on after this is for a way to automatically convert transpiler basis_gates to embodiments in this decomposer. I like that the option exists to request certain XX embodiments, but using it is a bit involved at the moment. e.g. if I want XX everywhere and CX instead of XX(pi/2), I need to do:

xx_circuit = QuantumCircuit(2)
theta = Parameter('theta')
xx_circuit.rxx(theta, 0, 1)

cx_circuit = QuantumCircuit(2)
cx_circuit.h(0)
cx_circuit.cx(0, 1)
cx_circuit.h(1)
cx_circuit.s(0)
cx_circuit.s(1)
cx_circuit.h(0)
cx_circuit.h(1)
cx_circuit.global_phase += np.pi / 4
embodiments = {t: xx_circuit.bind_parameters({theta: t}) for t in [np.pi/4, np.pi/6]}
embodiments.update({np.pi/2: cx_circuit})

decomposer = XXDecomposer(euler_basis='U3', embodiments=embodiments)
output_circuit = decomposer(u, basis_fidelity=.99)

qiskit/quantum_info/synthesis/xx_decompose/decomposer.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/xx_decompose/circuits.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/xx_decompose/decomposer.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/xx_decompose/decomposer.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/xx_decompose/decomposer.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/xx_decompose/polytopes.py Outdated Show resolved Hide resolved
qiskit/quantum_info/synthesis/xx_decompose/weyl.py Outdated Show resolved Hide resolved
@ecpeterson
Copy link
Contributor Author

I agree that the "embodiments" stuff is not super slick, mainly since it hasn't been flexed much. I'm sure you'll be able to find ergonomic improvements as you poke around.

@coveralls
Copy link

coveralls commented Nov 3, 2021

Pull Request Test Coverage Report for Build 1418807430

  • 399 of 441 (90.48%) changed or added relevant lines in 11 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.05%) to 82.37%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 11 13 84.62%
qiskit/quantum_info/synthesis/xx_decompose/paths.py 37 40 92.5%
qiskit/quantum_info/synthesis/xx_decompose/circuits.py 88 96 91.67%
qiskit/quantum_info/synthesis/xx_decompose/polytopes.py 95 103 92.23%
qiskit/quantum_info/synthesis/xx_decompose/decomposer.py 103 113 91.15%
qiskit/transpiler/passes/utils/gate_direction.py 3 14 21.43%
Files with Coverage Reduction New Missed Lines %
qiskit/pulse/library/waveform.py 3 90.38%
Totals Coverage Status
Change from base Build 1418224622: 0.05%
Covered Lines: 49655
Relevant Lines: 60283

💛 - Coveralls

@mergify mergify bot merged commit 0a4c666 into Qiskit:main Nov 3, 2021
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Nov 11, 2021
In Qiskit#6551 a few debug prints slipped into the unittests which are dumping
arrays to stdout during unit test runs. This commit just cleans those up
and removes the stray prints.
mergify bot added a commit that referenced this pull request Nov 12, 2021
In #6551 a few debug prints slipped into the unittests which are dumping
arrays to stdout during unit test runs. This commit just cleans those up
and removes the stray prints.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@kdk kdk added this to the 0.19 milestone Nov 15, 2021
@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Dec 6, 2021
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.

6 participants