-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b155373
commit 91f0012
Showing
6 changed files
with
97 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
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
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,69 @@ | ||
# -*- 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. | ||
|
||
""" | ||
Pauli X (bit-flip) gate. | ||
Identity operator | ||
""" | ||
|
||
import numpy | ||
|
||
from qiskit.circuit import CompositeGate | ||
from qiskit.circuit import Gate | ||
from qiskit.circuit import QuantumCircuit | ||
from qiskit.circuit import QuantumRegister | ||
from qiskit.qasm import pi | ||
from qiskit.extensions.standard.u3 import U3Gate | ||
|
||
|
||
class IGate(Gate): | ||
"""Pauli X (bit-flip) gate.""" | ||
|
||
def __init__(self, label=None): | ||
"""Create new X gate.""" | ||
super().__init__("i", 1, [], label=label) | ||
|
||
def _define(self): | ||
""" | ||
gate x a { | ||
u3(pi,0,pi) a; | ||
} | ||
""" | ||
definition = [] | ||
q = QuantumRegister(1, "q") | ||
rule = [ | ||
(U3Gate(pi, 0, pi), [q[0]], []) | ||
] | ||
for inst in rule: | ||
definition.append(inst) | ||
self.definition = definition | ||
|
||
def inverse(self): | ||
"""Invert this gate.""" | ||
return IGate() # self-inverse | ||
|
||
def to_matrix(self): | ||
"""Return a Numpy.array for the X gate.""" | ||
return numpy.array([[1, 0], | ||
[0, i]], dtype=complex) | ||
|
||
|
||
def i(self, q): | ||
"""Apply X to q.""" | ||
return self.append(IGate(), [q], []) | ||
|
||
|
||
QuantumCircuit.i = i | ||
CompositeGate.i = i |
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