Unless I am mistaken, Pennylane uses the big endian format, while Qiskit uses the little endian format. We can observe this by running the following simple code:
(1) Pennylane:
import pennylane as qml
with qml.tape.QuantumTape() as tape:
qml.PauliX(1)
qml.probs(wires=[0, 1])
simulator = qml.device("default.qubit", wires=2)
qml.execute([tape], simulator)
The result is:
(array([0., 1., 0., 0.]),)
(2) Qiskit:
from qiskit.circuit import QuantumCircuit
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(2, name="xgate")
qc.x(1)
state = Statevector.from_instruction(qc)
np.abs(state.data) ** 2
The result is:
array([0., 0., 1., 0.])
The ordering of the simulation results is compatible with Pennylane using big endian format and Qiskit using little endian format.
Now I am comparing the results from using Evolution gate:
(1) Pennylane:
import pennylane as qml
H = 2.1 * qml.PauliX(0) - qml.PauliY(1)
time = 1
with qml.tape.QuantumTape() as tape:
qml.evolve(H, time, num_steps=1).queue()
qml.probs(wires=[0, 1])
simulator = qml.device("default.qubit", wires=2)
qml.execute([tape], simulator)
The result is:
(array([0.07440321, 0.18046638, 0.21752337, 0.52760704]),)
(2) Qiskit:
from qiskit.quantum_info import SparsePauliOp
from qiskit.circuit.library import PauliEvolutionGate
X = SparsePauliOp("X")
Y = SparsePauliOp("Y")
I = SparsePauliOp("I")
operator = 2.1 * (X ^ I) - (I ^ Y)
evo = PauliEvolutionGate(operator, time=1)
circuit = QuantumCircuit(2)
circuit.append(evo, [0,1])
state = Statevector.from_instruction(circuit)
np.abs(state.data) ** 2
The result is:
array([0.07440321, 0.18046638, 0.21752337, 0.52760704])
This time one can observe that the two results are the same, despite I expected that the order of entries in the two results should be different. Of course in principle the problem can be either in Qiskit or in Pennylane but, based on some independent result, I suspect that perhaps the entries in Pennylane result are not ordered correctly in this case.
Thanks for your help!
Name: PennyLane
Version: 0.41.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /home/radu/.pyenv/versions/pennylane-ionq/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing-extensions
Required-by: PennyLane-IonQ, PennyLane_Lightning
Platform info: Linux-6.8.0-57-generic-x86_64-with-glibc2.39
Python version: 3.11.0
Numpy version: 2.0.2
Scipy version: 1.15.1
Installed devices:
- default.clifford (PennyLane-0.41.0)
- default.gaussian (PennyLane-0.41.0)
- default.mixed (PennyLane-0.41.0)
- default.qubit (PennyLane-0.41.0)
- default.qutrit (PennyLane-0.41.0)
- default.qutrit.mixed (PennyLane-0.41.0)
- default.tensor (PennyLane-0.41.0)
- null.qubit (PennyLane-0.41.0)
- reference.qubit (PennyLane-0.41.0)
- lightning.qubit (PennyLane_Lightning-0.41.0)
- ionq.qpu (PennyLane-IonQ-0.40.0.dev0)
- ionq.simulator (PennyLane-IonQ-0.40.0.dev0)