3
$\begingroup$

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]))?

$\endgroup$

1 Answer 1

1
$\begingroup$

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:
    print(cirq.DensePauliString(pauli_word_to_string(op)).sparse())

# 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)
])
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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