I have a matrix that I would like to decompose into a Pauli String. Pennylane's qml.utils.decompose_hamiltonian does this and returns a list of coefficients and a list of operations representing the decomposition.

Is there any simple way to convert the format of the returned operations, i.e. from Identity(wires=[0]) @ PauliZ(wires=[1]) (Pennylane syntax) to cirq.PauliString(cirq.I(qubits[0]), cirq.Z(qubits[1]))?


1 Answer 1


Use Pennylane's pauli_word_to_string function to convert Identity(wires=[0]) @ PauliZ(wires=[1]) to string. Then use cirq.DensePauliString(str).sparse() to convert this string to PauliString:

coeffs, obs_list = decompose_hamiltonian(A)

# Get PauliStrings:
for op in obs_list:

# Get PauliSum:
pauli_sum = cirq.PauliSum.from_pauli_strings([
    cirq.DensePauliString(pauli_word_to_string(op), coefficient = coeffs[index]).sparse()
        for index, op in enumerate(obs_list)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.