from pennylane import FermiC, FermiA
from pennylane import jordan_wigner
from pennylane import numpy as np
h1 = 0.01 * (FermiC(0) * FermiA(0) + FermiC(1) * FermiA(1))
h2 = -0.02 * (FermiC(0) * FermiA(1) + FermiC(1) * FermiA(0))
h = h1 + h2
print(h)
h = jordan_wigner(h)
val, vec = np.linalg.eigh(h.sparse_matrix().toarray())
print(f"eigenvalues:\n{val}")
print()
print(f"eigenvectors:\n{np.real(vec.T)}")
error: ValueError: Output dtype not compatible with inputs.
Hey @jeet_sharma,
This code works fine for me and outputs the following:
0.01 * a⁺(0) a(0)
+ 0.01 * a⁺(1) a(1)
+ -0.02 * a⁺(0) a(1)
+ -0.02 * a⁺(1) a(0)
eigenvalues:
[-0.01 0. 0.02 0.03]
eigenvectors:
[[-0. -0.70710678 -0.70710678 -0. ]
[ 1. 0. 0. 0. ]
[ 0. 0. 0. 1. ]
[ 0. -0.70710678 0.70710678 0. ]]
Here is my qml.about()
:
Name: PennyLane
Version: 0.35.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: /Users/isaac/.virtualenvs/pennylane-stable/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane_Lightning
Platform info: macOS-14.4-arm64-arm-64bit
Python version: 3.11.6
Numpy version: 1.26.4
Scipy version: 1.12.0
Installed devices:
- default.clifford (PennyLane-0.35.0)
- default.gaussian (PennyLane-0.35.0)
- default.mixed (PennyLane-0.35.0)
- default.qubit (PennyLane-0.35.0)
- default.qubit.autograd (PennyLane-0.35.0)
- default.qubit.jax (PennyLane-0.35.0)
- default.qubit.legacy (PennyLane-0.35.0)
- default.qubit.tf (PennyLane-0.35.0)
- default.qubit.torch (PennyLane-0.35.0)
- default.qutrit (PennyLane-0.35.0)
- null.qubit (PennyLane-0.35.0)
- lightning.qubit (PennyLane_Lightning-0.35.0)
Make sure you’re using the most up-to-date version of PennyLane! You can do so by doing pip install --upgrade pennylane
. Hope this helps.