Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observables #8

Open
garrison opened this issue Oct 31, 2024 · 2 comments
Open

Observables #8

garrison opened this issue Oct 31, 2024 · 2 comments

Comments

@garrison
Copy link
Member

So far, when taking expectation values, I convert to quimb operators manually. For instance, given a CircuitMPS:

mps.local_expectation(quimb.pauli('Z') & quimb.pauli('Z'), (3, 4)).real.item()

I wonder if there's a better way, or a way we could enable users to use SparsePauliOp and its successor and have the conversion to quimb be automatic.

@kevinsung
Copy link
Collaborator

I dug up this function I wrote at some point, but I don't remember how I used it. Not sure if it's useful.

def quimb_paulis(pauli_list: PauliList):
    result = []
    for qiskit_pauli in pauli_list:
        quimb_pauli_list = []
        for i, p in enumerate(reversed(qiskit_pauli.to_label())):
            if p != "I":
                quimb_pauli_list.append((quimb.pauli(p), i))
        if quimb_pauli_list:
            paulis, qubits = zip(*quimb_pauli_list)
            pauli = functools.reduce(lambda a, b: a & b, paulis)
        else:
            pauli = 1.0
            qubits = []
        result.append((pauli, qubits))
    return result

@garrison
Copy link
Member Author

OK, that is probably going to be useful to reference.

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

No branches or pull requests

2 participants