forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ma5x <[email protected]> Co-authored-by: strickroman <[email protected]>
- Loading branch information
Showing
6 changed files
with
172 additions
and
2 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 |
---|---|---|
|
@@ -44,3 +44,4 @@ | |
from .crz import CrzGate | ||
from .cu3 import Cu3Gate | ||
from .rzz import RZZGate | ||
from .rxx import RXXGate |
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,80 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2017, 2019. | ||
# | ||
# 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. | ||
|
||
""" | ||
Two-qubit XX-rotation gate. | ||
""" | ||
import numpy as np | ||
from qiskit.circuit import Gate | ||
from qiskit.circuit import QuantumCircuit | ||
from qiskit.circuit import QuantumRegister | ||
from qiskit.extensions.standard.cx import CnotGate | ||
from qiskit.extensions.standard.u1 import U1Gate | ||
from qiskit.extensions.standard.u2 import U2Gate | ||
from qiskit.extensions.standard.u3 import U3Gate | ||
from qiskit.extensions.standard.h import HGate | ||
|
||
|
||
class RXXGate(Gate): | ||
"""Two-qubit XX-rotation gate. | ||
This gate corresponds to the rotation U(θ) = exp(-1j * θ * X⊗X / 2) | ||
""" | ||
|
||
def __init__(self, theta): | ||
"""Create new rxx gate.""" | ||
super().__init__("rxx", 2, [theta]) | ||
|
||
def _define(self): | ||
"""Calculate a subcircuit that implements this unitary.""" | ||
definition = [] | ||
q = QuantumRegister(2, "q") | ||
theta = self.params[0] | ||
rule = [ | ||
(U3Gate(np.pi / 2, theta, 0), [q[0]], []), | ||
(HGate(), [q[1]], []), | ||
(CnotGate(), [q[0], q[1]], []), | ||
(U1Gate(-theta), [q[1]], []), | ||
(CnotGate(), [q[0], q[1]], []), | ||
(HGate(), [q[1]], []), | ||
(U2Gate(-np.pi, np.pi - theta), [q[0]], []), | ||
] | ||
for inst in rule: | ||
definition.append(inst) | ||
self.definition = definition | ||
|
||
def inverse(self): | ||
"""Invert this gate.""" | ||
return RXXGate(-self.params[0]) | ||
|
||
# NOTE: we should use the following as the canonical matrix | ||
# definition but we don't include it yet since it differs from | ||
# the circuit decomposition matrix by a global phase | ||
# def to_matrix(self): | ||
# """Return a Numpy.array for the RXX gate.""" | ||
# theta = float(self.params[0]) | ||
# return np.array([ | ||
# [np.cos(theta / 2), 0, 0, -1j * np.sin(theta / 2)], | ||
# [0, np.cos(theta / 2), -1j * np.sin(theta / 2), 0], | ||
# [0, -1j * np.sin(theta / 2), np.cos(theta / 2), 0], | ||
# [-1j * np.sin(theta / 2), 0, 0, np.cos(theta / 2)]], dtype=complex) | ||
|
||
|
||
def rxx(self, theta, qubit1, qubit2): | ||
"""Apply RXX to circuit.""" | ||
return self.append(RXXGate(theta), [qubit1, qubit2], []) | ||
|
||
|
||
# Add to QuantumCircuit class | ||
QuantumCircuit.rxx = rxx |
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,59 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2017, 2019. | ||
# | ||
# 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. | ||
|
||
# pylint: disable=invalid-name | ||
|
||
""" | ||
Decomposition methods for trapped-ion basis gates RXXGate, RXGate, RYGate. | ||
""" | ||
|
||
import numpy as np | ||
|
||
from qiskit.circuit.quantumcircuit import QuantumCircuit | ||
from qiskit.extensions.standard.ry import RYGate | ||
from qiskit.extensions.standard.rx import RXGate | ||
from qiskit.extensions.standard.rxx import RXXGate | ||
|
||
|
||
def cnot_rxx_decompose(plus_ry=True, plus_rxx=True): | ||
"""Decomposition of CNOT gate. | ||
NOTE: this differs to CNOT by a global phase. | ||
The matrix returned is given by exp(1j * pi/4) * CNOT | ||
Args: | ||
plus_ry (bool): positive initial RY rotation | ||
plus_rxx (bool): positive RXX rotation. | ||
Returns: | ||
QuantumCircuit: The decomposed circuit for CNOT gate (up to | ||
global phase). | ||
""" | ||
# Convert boolean args to +/- 1 signs | ||
if plus_ry: | ||
sgn_ry = 1 | ||
else: | ||
sgn_ry = -1 | ||
if plus_rxx: | ||
sgn_rxx = 1 | ||
else: | ||
sgn_rxx = -1 | ||
|
||
circuit = QuantumCircuit(2) | ||
circuit.append(RYGate(sgn_ry * np.pi / 2), [0]) | ||
circuit.append(RXXGate(sgn_rxx * np.pi / 2), [0, 1]) | ||
circuit.append(RXGate(-sgn_rxx * np.pi / 2), [0]) | ||
circuit.append(RXGate(-sgn_rxx * sgn_ry * np.pi / 2), [1]) | ||
circuit.append(RYGate(-sgn_ry * np.pi / 2), [0]) | ||
return circuit |
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