Comments (2)
The following utility function can be used to get the Pauli decomposition (linear combination of tensor products between Pauli matrices) of any valid quantum gate represented as a sympy matrix, including parametric gates such as XXMinusYYGate
and XXPlusYYGate
(see here for the mathematical formulation).
import itertools
import numpy as np
from sympy.physics.quantum import TensorProduct
from qiskit_symb.circuit.library import IGate, XGate, YGate, ZGate
paulis = {
'I': IGate().to_sympy(),
'X': XGate().to_sympy(),
'Y': YGate().to_sympy(),
'Z': ZGate().to_sympy()
}
def pauli_decomposition(matrix):
num_qubits = int(np.log2(matrix.shape[0]))
factor = 1 / 2**num_qubits
pauli_terms = {}
for pauli_tuple in itertools.product('IXYZ', repeat=num_qubits):
trace = (TensorProduct(*[paulis[p] for p in pauli_tuple]) * matrix).trace()
if trace:
pauli_string = ''.join(pauli_tuple)
pauli_terms[pauli_string] = factor * trace
return pauli_terms
from qiskit-symb.
Here are the Pauli terms decomposition of the XXMinusYYGate
, XXPlusYYGate
, and DCXGate
computed by calling the pauli_decomposition
function defined above and passing the corresponding sympy matrix.
from sympy import Symbol, cos, sin, exp, I
from sympy.matrices import Matrix
theta = Symbol('θ')
beta = Symbol('β')
xx_minus_yy = Matrix([[cos(theta/2), 0, 0, -I*sin(theta/2)*exp(-I*beta)],
[0, 1, 0, 0],
[0, 0, 1, 0],
[-I*sin(theta/2)*exp(I*beta), 0, 0, cos(theta/2)]])
xx_plus_yy = Matrix([[1, 0, 0, 0],
[0, cos(theta/2), -I*sin(theta/2)*exp(-I*beta), 0],
[0, -I*sin(theta/2)*exp(I*beta), cos(theta/2), 0],
[0, 0, 0, 1]])
dcx = Matrix([[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 1, 0, 0],
[0, 0, 1, 0]])
########## XXMinusYYGate ##########
{'II': 0.5*cos(θ/2) + 0.5,
'XX': -0.25*I*exp(I*β)*sin(θ/2) - 0.25*I*exp(-I*β)*sin(θ/2),
'XY': -0.25*exp(I*β)*sin(θ/2) + 0.25*exp(-I*β)*sin(θ/2),
'YX': -0.25*exp(I*β)*sin(θ/2) + 0.25*exp(-I*β)*sin(θ/2),
'YY': 0.25*I*exp(I*β)*sin(θ/2) + 0.25*I*exp(-I*β)*sin(θ/2),
'ZZ': 0.5*cos(θ/2) - 0.5}
########## XXPlusYYGate ##########
{'II': 0.5*cos(θ/2) + 0.5,
'XX': -0.25*I*exp(I*β)*sin(θ/2) - 0.25*I*exp(-I*β)*sin(θ/2),
'XY': 0.25*exp(I*β)*sin(θ/2) - 0.25*exp(-I*β)*sin(θ/2),
'YX': -0.25*exp(I*β)*sin(θ/2) + 0.25*exp(-I*β)*sin(θ/2),
'YY': -0.25*I*exp(I*β)*sin(θ/2) - 0.25*I*exp(-I*β)*sin(θ/2),
'ZZ': 0.5 - 0.5*cos(θ/2)}
########## DCXGate ##########
{'II': 0.25,
'IX': 0.25,
'IY': -0.25*I,
'IZ': 0.25,
'XI': 0.25,
'XX': 0.25,
'XY': 0.25*I,
'XZ': -0.25,
'YI': 0.25*I,
'YX': -0.25*I,
'YY': 0.25,
'YZ': -0.25*I,
'ZI': 0.25,
'ZX': -0.25,
'ZY': 0.25*I,
'ZZ': 0.25}
from qiskit-symb.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qiskit-symb.