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

Expectation Value snapshot extension #305

Closed
chriseclectic opened this issue Jul 29, 2019 · 0 comments · Fixed by #386
Closed

Expectation Value snapshot extension #305

chriseclectic opened this issue Jul 29, 2019 · 0 comments · Fixed by #386
Labels
enhancement New feature or request
Milestone

Comments

@chriseclectic
Copy link
Member

What is the expected behavior?

This will be used by various methods of the QasmSimulator to return snapshots of expectation value outcomes <M> for some operator M.

Eventually we will allow different input classes for M but for now we will allow N-qubit Operator objects (which can be constructed from other Operators, lists, np.arrays, Paulis, etc). Behind the scenes these should be converted into either pauli expectation value snapshots, or dense matrix snapshots.

The qobj format for Pauli expectation value snapshot params is a list [[coeff, pauli], ...] where coeff is a complex number (JSON: [re, im]), and pauli is a string containing only IXYZ for the Pauli term (qubit 0 to N-1 are characters right to left).

class SnapshotExpectationValue(Snapshot):
    __init__(self, label, op, pauli=True, variance=False):
        # num_qubits can be inferred form size of operator.
        # If Pauli is true convert to Pauli expval snapshot
       # type: "expectation_value_pauli" or ""expectation_value_pauli_with_variance"
       # otherwise we use general matrix ones
      # type: "expectation_value_matrix" or ""expectation_value_matrix_with_variance"
      # See `operations.hpp` for input format

# Monkey patch function
def snapshot_expectation_value(self, label, op, qubits=None, variance=False):
     # If qubits is None snapshot all qubits.

circuit.snapshot_expectation_value = snapshot_expectation_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant