-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add phase property to Gate class
#3930
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0b78d59
Add phase attribute to Gate
chriseclectic 9576752
Update U1, U2, U3 with phase
chriseclectic 00a74fb
Update R, Rx, Ry, Rz with phase
chriseclectic 049161c
Update OneQubitEulerDecomposer to be phase correct
chriseclectic 57aea60
Update RXX, RYY, RZZ, RZX gates with phase
chriseclectic 891fed6
Handle case of ParameterExpression for phase
chriseclectic bfdbac3
Linting
chriseclectic 7ed4c03
Revert adding phase to two-qubit pauli rotation gates
chriseclectic d8b7b43
Add release note
chriseclectic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
|
|
||
| """Rotation around the Z axis.""" | ||
|
|
||
| import numpy as np | ||
|
|
||
| from qiskit.circuit.gate import Gate | ||
| from qiskit.circuit.controlledgate import ControlledGate | ||
| from qiskit.circuit.quantumregister import QuantumRegister | ||
|
|
@@ -56,23 +58,20 @@ class RZGate(Gate): | |
| `1612.00858 <https://arxiv.org/abs/1612.00858>`_ | ||
| """ | ||
|
|
||
| def __init__(self, phi, label=None): | ||
| def __init__(self, phi, phase=0, label=None): | ||
| """Create new RZ gate.""" | ||
| super().__init__('rz', 1, [phi], label=label) | ||
| super().__init__('rz', 1, [phi], phase=phase, label=label) | ||
|
|
||
| def _define(self): | ||
| """ | ||
| gate rz(phi) a { u1(phi) a; } | ||
| """ | ||
| from .u1 import U1Gate | ||
| definition = [] | ||
| q = QuantumRegister(1, 'q') | ||
| rule = [ | ||
| (U1Gate(self.params[0]), [q[0]], []) | ||
| phase = self.phase - 0.5 * self.params[0] | ||
| self.definition = [ | ||
| (U1Gate(self.params[0], phase=phase), [q[0]], []) | ||
| ] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| for inst in rule: | ||
| definition.append(inst) | ||
| self.definition = definition | ||
|
|
||
| def control(self, num_ctrl_qubits=1, label=None, ctrl_state=None): | ||
| """Return a (mutli-)controlled-RZ gate. | ||
|
|
@@ -86,7 +85,7 @@ def control(self, num_ctrl_qubits=1, label=None, ctrl_state=None): | |
| Returns: | ||
| ControlledGate: controlled version of this gate. | ||
| """ | ||
| if num_ctrl_qubits == 1: | ||
| if num_ctrl_qubits == 1 and self.phase == 0: | ||
| gate = CRZGate(self.params[0], label=label, ctrl_state=ctrl_state) | ||
| gate.base_gate.label = self.label | ||
| return gate | ||
|
|
@@ -97,15 +96,13 @@ def inverse(self): | |
|
|
||
| :math:`RZ(\lambda){\dagger} = RZ(-\lambda)` | ||
| """ | ||
| return RZGate(-self.params[0]) | ||
|
|
||
| # TODO: this is the correct matrix however the control mechanism | ||
| # cannot distinguish U1 and RZ yet. | ||
| # def to_matrix(self): | ||
| # """Return a numpy.array for the RZ gate.""" | ||
| # lam = float(self.params[0]) | ||
| # return np.array([[np.exp(-1j * lam / 2), 0], | ||
| # [0, np.exp(1j * lam / 2)]], dtype=complex) | ||
| return RZGate(-self.params[0], phase=-self.phase) | ||
|
|
||
| def _matrix_definition(self): | ||
| """Return a numpy.array for the RZ gate.""" | ||
| lam = float(self.params[0]) | ||
| return np.array([[np.exp(-1j * lam / 2), 0], | ||
| [0, np.exp(1j * lam / 2)]], dtype=complex) | ||
|
|
||
|
|
||
| class CRZMeta(type): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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