Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

QubitOperator to cirq.PauliSum #372

Open
mpharrigan opened this issue Mar 5, 2020 · 3 comments
Open

QubitOperator to cirq.PauliSum #372

mpharrigan opened this issue Mar 5, 2020 · 3 comments

Comments

@mpharrigan
Copy link
Contributor

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 #368 (comment)

@xabomon
Copy link

xabomon commented Apr 21, 2020

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

@mpharrigan
Copy link
Contributor Author

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

@xabomon
Copy link

xabomon commented Apr 22, 2020

Yes sure! I will make a new PR for this indeed. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants