I have recently started looking at the qubit tapering and its application in quantum chemistry. Is there anyway to count the number of CNOT gates or Pauli gates in a given Hamiltonian. So, it can be used to compare the no. of gates in a Hamiltonian before and qubit tapering.
I am not quiet sure, how to print the no. of gates involved. Actually, I want to know how many Pauli Gates are there for the Hamiltonian of a system. For eg. the Hamiltonian for H2 molecule can be obtained as.
symbols = [“H”, “H”]
x = np.array([8.14341433,1.84432727,0.00000000,
Hamil = qml.qchem.molecular_hamiltonian(symbols, x,
So now , there are many attributes to the Hamil such as
Hamil.coeffs [give coefficients of Pauli gates acting on each qubit]
Hi @raghavv. I asked a colleague about this and he put together a function that does what you need. It might not be super stable but it seems to work. You can modify it to count a specific Pauli operator if that’s what you need.
from pennylane.ops.qubit.non_parametric_ops import PauliX, PauliY, PauliZ
from pennylane.operation import Tensor
Counts the number of Pauli operations in a Hamiltonian. Note that each Pauli
operator contained in tensor products are counted individually e.g:
qml.PauliX(0) @ qml.PauliX(1) counts as 2. Identity operations are not
counted as Pauli operations here.
H (qml.Hamiltonian): The Hamiltonian containing operations to be counted
count (int): the number of Pauli operations contained in the Hamiltonian
pauli_types = (PauliX, PauliY, PauliZ)
count = 0
for op in H.ops:
if type(op) == Tensor:
for obs in op.obs:
if type(obs) in pauli_types:
count += 1
elif type(op) in pauli_types:
count += 1
Hi @CatalinaAlbornoz. One can run the command Hamiltonian.ops and then list the Pauli gates and save it to a text file. And the run the grep command (grep -o PauliZ Pauli_Gates.txt | wc -l). Hope that is clear.