OpenFermion-Cirq
OpenFermion-Cirq copied to clipboard
QubitOperator to cirq.PauliSum
We need a simple function to convert OpenFermion's QubitOperator to the corresponding Cirq object, PauliSum. Here's a snippet that does it:
def qubit_operator_to_pauli_sum(qubit_op):
psum = cirq.PauliSum()
for ind_ops, coeff in qubit_op.terms.items():
if ind_ops == tuple():
psum += coeff
continue
pstring = cirq.PauliString()
for ind, op in ind_ops:
if op == 'X':
op = cirq.X
elif op == 'Y':
op = cirq.Y
elif op == 'Z':
op = cirq.Z
pstring *= op(cirq.LineQubit(ind))
psum += pstring * coeff
return psum
but it needs tests and stuff
See also https://github.com/quantumlib/OpenFermion-Cirq/issues/368#issuecomment-584381039
Hi @mpharrigan ,
We could align this with my PR #395 . Do you mind if I take this function and we start a set of translator/serializers OpenFermion to OpenFermion-Cirq?
Best, Xavi
Please do! it might make reviewing easier if you keep some of the translators (like above) in a separate, small, easy-to-review PR that we can get in tout suite
Yes sure! I will make a new PR for this indeed. Thanks!