-
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.
Add global Molmer-Sorenson gate (#3149)
* add global ms gate * clean up * Update qiskit/extensions/standard/ms.py Co-Authored-By: Kevin Krsulich <[email protected]> * Update qiskit/extensions/standard/ms.py Co-Authored-By: Kevin Krsulich <[email protected]> * clean up
- Loading branch information
Showing
4 changed files
with
65 additions
and
14 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 |
---|---|---|
|
@@ -45,3 +45,4 @@ | |
from .cu3 import Cu3Gate | ||
from .rzz import RZZGate | ||
from .rxx import RXXGate | ||
from .ms import MSGate |
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,53 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2017. | ||
# | ||
# 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 | ||
|
||
""" | ||
Molmer-Sorensen gate. | ||
""" | ||
|
||
|
||
from qiskit.circuit import Gate | ||
from qiskit.circuit import QuantumCircuit | ||
from qiskit.circuit import QuantumRegister | ||
from qiskit.extensions.standard.rxx import RXXGate | ||
|
||
|
||
class MSGate(Gate): | ||
"""Global Molmer-Sorensen gate.""" | ||
|
||
def __init__(self, n_qubits, theta): | ||
"""Create new MS gate.""" | ||
super().__init__("ms", n_qubits, [theta]) | ||
|
||
def _define(self): | ||
definition = [] | ||
q = QuantumRegister(self.num_qubits, "q") | ||
rule = [] | ||
for i in range(self.num_qubits): | ||
for j in range(i+1, self.num_qubits): | ||
rule += [(RXXGate(self.params[0]), [q[i], q[j]], [])] | ||
|
||
for inst in rule: | ||
definition.append(inst) | ||
self.definition = definition | ||
|
||
|
||
def ms(self, theta, qubits): | ||
"""Apply MS to q1 and q2.""" | ||
return self.append(MSGate(len(qubits), theta), qubits) | ||
|
||
|
||
QuantumCircuit.ms = ms |
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