-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding global_phase gate in qiskit-terra (#9251)
* created gphase.py file * completed glbalphase file & test_gate_defin * adding GphaseGate in @DaTa in test_gate_defn * added reno add-global-phase * added inv and matrix test in test_exten * test_gphase_inv * tox lint edit * renamed GLobalPhaseGate to Global_Phase_Gate * Changed the name to more competable GlobalPhaseGate class * # pylint: disable=E1101 * # pylint: disable=no-member * # pylint: error fixed * including phase in super * changed float to ParameterExp * modified test_globalphaseGate * phase to params[0] * renamed global_phase.py to gphase * test gphase new in extentions_std * debug 1 * debug 2 * debug 3 instructions set * debug 4 * debug 5 * debug 6 * debug 6 instructions set * debug 7 * debug 7 * added gphase in quantumcircuit.py * added method gphase in quantumcircuit.py * test_gphase_inv * gphase debug1 * gphase debug2 * gphase debug3 * inverse mtd in gphase.py * added _array in gphase.py * gphase.py array debug1 * test_matrix gphase complex dtype * test_matrix in @DDT * test_gphase_matrix * changed gphase to global_phase * removed extra comma l871 * typo in reno fixed * modified reno * Delete .vs directory Deleted .vs directory * Added test to check compatibility of gate with qc.attri * debugged pylint error1 * debugged pylint error2 * debugged pylint error2a * debugged -epy error debug1 * debugged -epy error debug 1 * debugged -epy error debug 2 * restored test_gate_definations * Revert "restored test_gate_definations" This reverts commit 642877b. * reverted mistakely edited the file on Github * Delete .vs directory Deleted .vs directory * restored test_gate_definations * Revert "restored test_gate_definations" This reverts commit 642877b. * reverted mistakely edited the file on Github * retrived test_gate_definitions * PR modifications new * commit feb 13 * range in append * [] in append * [0] in append * [0]->[] * [0] * [] * Operator(qc) * fixed test_ex_std * resolved changes suggested by Cryolis * Update global_phase.py Typo in year * Added transpiler consistancy test * restored the docstring * prevented cyclic imports and other changes * Fix spacing in docs * Fix lint * Add test of controlling global phase --------- Co-authored-by: Jake Lishman <[email protected]>
- Loading branch information
1 parent
c4602ea
commit da92478
Showing
7 changed files
with
135 additions
and
4 deletions.
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