-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Adding global_phase gate in qiskit-terra #9251
Merged
Merged
Changes from all commits
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
aa8f608
created gphase.py file
89157f8
Merge branch 'Qiskit:main' into branch1
sumit-kale e2c97a7
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into br…
14f5599
completed glbalphase file & test_gate_defin
edcf7ba
adding GphaseGate in @data in test_gate_defn
87a2ade
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into br…
1aac540
Merge branch 'branch1' of https://github.com/sumit-kale/qiskit-terra …
6a3e453
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into br…
8051f10
added reno add-global-phase
9be8cda
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into br…
d06e4f4
added inv and matrix test in test_exten
b5320ef
test_gphase_inv
55e874b
tox lint edit
c7b3390
renamed GLobalPhaseGate to Global_Phase_Gate
9f2ba8a
Changed the name to more competable GlobalPhaseGate class
9c9d77f
# pylint: disable=E1101
64f5d7f
# pylint: disable=no-member
22573b2
# pylint: error fixed
c3d484e
including phase in super
be943b0
Merge branch 'Qiskit:main' into branch1
sumit-kale 86267bc
Merge branch 'branch1' of https://github.com/sumit-kale/qiskit-terra …
025912e
changed float to ParameterExp
618816c
modified test_globalphaseGate
32a4401
phase to params[0]
371fbc3
renamed global_phase.py to gphase
615c9fc
test gphase new in extentions_std
c910dcd
debug 1
0661cd5
debug 2
b071cd6
debug 3 instructions set
6461819
debug 4
ab74fd9
debug 5
afd9a24
debug 6
0edba4c
debug 6 instructions set
fa4baa3
debug 7
4373619
debug 7
1f6b742
added gphase in quantumcircuit.py
ba96b3f
added method gphase in quantumcircuit.py
3df2949
test_gphase_inv
89be2d0
gphase debug1
1729cfc
gphase debug2
dfa77aa
gphase debug3
19ea5b1
inverse mtd in gphase.py
8a2b11f
added _array in gphase.py
4b40a04
gphase.py array debug1
201e30c
test_matrix gphase complex dtype
36e38d2
test_matrix in @ddt
1fb12c5
test_gphase_matrix
d643e03
changed gphase to global_phase
e1fa6dc
removed extra comma l871
efa551a
typo in reno fixed
b42dd84
modified reno
9aa08c4
Delete .vs directory
sumit-kale bb94760
Added test to check compatibility of gate with qc.attri
b8beb27
debugged pylint error1
7be3938
debugged pylint error2
0f384c0
debugged pylint error2a
c2fb3cd
debugged -epy error debug1
f441c0a
debugged -epy error debug 1
422a991
debugged -epy error debug 2
1d405bc
Merge branch 'global_phase' of https://github.com/sumit-kale/qiskit-t…
642877b
restored test_gate_definations
sumit-kale e0bec24
Revert "restored test_gate_definations"
ae83f16
reverted mistakely edited the file on Github
08c7ef5
Merge branch 'Qiskit:main' into global_phase
sumit-kale 0c139a6
Delete .vs directory
sumit-kale 0672ab3
restored test_gate_definations
sumit-kale 72259b7
Revert "restored test_gate_definations"
a1afc5c
reverted mistakely edited the file on Github
2599360
Merge branch 'main' into global_phase
sumit-kale a2b6256
retrived test_gate_definitions
be489a0
Merge branch 'global_phase' of https://github.com/sumit-kale/qiskit-t…
ba0db3e
PR modifications new
87f1a0c
commit feb 13
48f7c12
range in append
d79782b
[] in append
bd46049
[0] in append
8c05971
[0]->[]
91ac5fc
[0]
26e0802
[]
adaa23a
Operator(qc)
8e431eb
fixed test_ex_std
2a15a6b
resolved changes suggested by Cryolis
166214f
Update global_phase.py
sumit-kale 57939ba
Merge branch 'main' into global_phase
sumit-kale e4989e9
..
098d85b
resolved merge conflicts
a1bac05
Added transpiler consistancy test
eedbf55
restored the docstring
sumit-kale 546872e
prevented cyclic imports and other changes
394e4f4
Fix spacing in docs
jakelishman 7dc02bb
Merge remote-tracking branch 'ibm/main' into global_phase
jakelishman eb2b7bc
Fix lint
jakelishman 64ea9e6
Add test of controlling global phase
jakelishman 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 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 |
---|---|---|
|
@@ -124,6 +124,7 @@ | |
XGate | ||
YGate | ||
ZGate | ||
GlobalPhaseGate | ||
|
||
Standard Directives | ||
=================== | ||
|
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2023. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Global Phase Gate""" | ||
|
||
from typing import Optional | ||
import numpy | ||
from qiskit.circuit.gate import Gate | ||
from qiskit.circuit.quantumregister import QuantumRegister | ||
from qiskit.circuit.quantumcircuit import QuantumCircuit | ||
from qiskit.circuit.parameterexpression import ParameterValueType | ||
|
||
|
||
class GlobalPhaseGate(Gate): | ||
r"""The global phase gate (:math:`e^{i\theta}`). | ||
|
||
Can be applied to a :class:`~qiskit.circuit.QuantumCircuit` | ||
|
||
**Mathamatical Representation:** | ||
|
||
.. math:: | ||
\text{GlobalPhaseGate}\ = | ||
\begin{pmatrix} | ||
e^{i\theta} | ||
\end{pmatrix} | ||
""" | ||
|
||
def __init__(self, phase: ParameterValueType, label: Optional[str] = None): | ||
""" | ||
Args: | ||
phase: The value of phase it takes. | ||
label: An optional label for the gate. | ||
""" | ||
super().__init__("global_phase", 0, [phase], label=label) | ||
|
||
def _define(self): | ||
|
||
q = QuantumRegister(0, "q") | ||
qc = QuantumCircuit(q, name=self.name, global_phase=self.params[0]) | ||
|
||
self.definition = qc | ||
|
||
def inverse(self): | ||
r"""Return inverted GLobalPhaseGate gate. | ||
|
||
:math:`\text{GlobalPhaseGate}(\lambda){\dagger} = \text{GlobalPhaseGate}(-\lambda)` | ||
""" | ||
return GlobalPhaseGate(-self.params[0]) | ||
|
||
def __array__(self, dtype=complex): | ||
"""Return a numpy.array for the global_phase gate.""" | ||
theta = self.params[0] | ||
return numpy.array([[numpy.exp(1j * theta)]], dtype=dtype) |
This file contains 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
6 changes: 6 additions & 0 deletions
6
releasenotes/notes/add-global-phase-gate-b52c5b25ab8a3cf6.yaml
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
features: | ||
- | | ||
Added :class:`.GlobalPhaseGate` which can be applied to add a global phase | ||
on the :class:`.QuantumCircuit`. | ||
|
This file contains 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 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
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.
Add a test to check consistency with the
QuantumCircuit.global_phase
attribute. Do this by creating two circuits, one that has a GlobalPhaseGate, and the other that is initialized by passing the global phase as argument. Check that the two circuits have the same unitary.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.
A new test has been added in to check the compatibility of the GLobalPhaseGate with the preexisting feature.