Skip to content

Add phase property to Gate class#3930

Closed
chriseclectic wants to merge 9 commits into
Qiskit:masterfrom
chriseclectic:feature/gate-phase
Closed

Add phase property to Gate class#3930
chriseclectic wants to merge 9 commits into
Qiskit:masterfrom
chriseclectic:feature/gate-phase

Conversation

@chriseclectic
Copy link
Copy Markdown
Member

@chriseclectic chriseclectic commented Mar 4, 2020

Fixes #3304

Summary

  • Adds phase properties to Gate class for storing a gate phase
  • Adds Gate._matrix_definition function to standard gates that returns canonical (phase=0) gate
  • Changes Gate.to_matrix to return the matrix definition times the phase
  • Updates U1, U2, U3 gates and RX, RY, RZ rotation to use phase correctly (in init and inverse).
  • Adds phase correct matrix and definitions for RZ.
  • Make OneQubitEulerDecomposer have phase-correct synthesis

Details and comments

When constructing a gate a phase can be set using phase=theta kwarg. theta will be stored as a float [-2*pi, 2*pi] in the gate object, representing a complex coefficient exp(i theta) on the matrix definition of the gate.

After construction a gate object can have its phase modified using gate.phase = theta.

When calling to_matrix the returned matrix will be exp(i theta) * U_def where U_def is the matrix definition of the gate.

When unrolling any set phase parameter will be passed to one of the gates in the definition so that the unrolled circuit has the same global phase as the original gate.

Follow up PR work

  • Updating the rest of the standard gates with phases (in particular controlled gates)
  • Updating 2-qubit synthesis to preserve phase
  • Fixing transpiler passes to preserve phase where possible

@ewinston
Copy link
Copy Markdown
Contributor

This should address #3304

@1ucian0 1ucian0 marked this pull request as draft April 16, 2020 15:02
@1ucian0 1ucian0 mentioned this pull request Apr 23, 2020
@chriseclectic chriseclectic marked this pull request as ready for review May 12, 2020 18:00
@chriseclectic chriseclectic changed the title [WIP] Add phase property to Gate class Add phase property to Gate class May 12, 2020
These gates current fail control gate tests if they are made to be phase correct
since they should have a RZGate in their definition. To avoid these test
failures I have reverted them to using a U1Gate in their definition, which gives
an incorrect phase on decomposition, but passes the current tests. This should be
addressed and fixed in a follow up PR.
rule = [
(U3Gate(theta, phi - pi / 2, -phi + pi / 2), [q[0]], [])
self.definition = [
(U3Gate(theta, phi - pi / 2, -phi + pi / 2, phase=self.phase), [q[0]], [])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i dont think it is a good idea to make phase change. For R it is defined with phase 0

phase = self.phase - 0.5 * self.params[0]
self.definition = [
(U1Gate(self.params[0], phase=phase), [q[0]], [])
]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

here is where i would make it from a U1 but set it to be a phase that to make it Rz

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.

RzGate(alpha).to_matrix() is missing

3 participants