Skip to content

Add OBPEstimator #90

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

samanthavbarron
Copy link
Contributor

This PR adds an Estimator interface to OBP. This allows the user to compute expectation values using qiskit_addon_obp.backpropagate. This interface allows for arbitrarily shaped EstimatorPubs, handles parameter bindings, etc.

There are likely some remaining questions before this should be merged if at all, but IMO an Estimator interface of some sort is a natural addition.

For example, currently: if the remaining circuit after backpropagation is non-empty, the OBPEstimator will raise a NotImplementedError. I left a comment with a potential suggestion for how to handle this case:

            # In this case, one alternative is to have the user supply an auxiliary estimator
            # The auxiliary estimator would compute the expectation value wrt the remaining
            # slices. E.g. The primary use case would likely be providing an estimator which
            # uses an actual backend to compute the remaining expectation value, etc.

Usage

import numpy as np
from qiskit import QuantumCircuit
from qiskit.primitives.containers.estimator_pub import EstimatorPub
from qiskit.primitives.containers.observables_array import ObservablesArray
from qiskit.quantum_info import SparsePauliOp
from qiskit_addon_utils.slicing import slice_by_barriers

from qiskit_addon_obp.obp_estimator import OBPEstimator

# Make your EstimatorPub

theta = np.pi / 6
qc = QuantumCircuit(1)
qc.rz(theta, 0)
qc.barrier()
qc.ry(theta, 0)
obs = SparsePauliOp("X")
pub = EstimatorPub(qc, ObservablesArray([obs]))

# Compute EVs with OBP
OBPEstimator(slicer=slice_by_barriers).run([pub]).result()[0].data.evs
array([0.5+0.j])

@coveralls
Copy link

Pull Request Test Coverage Report for Build 15192597933

Details

  • 22 of 65 (33.85%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-7.8%) to 92.238%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_addon_obp/utils/broadcast_indices_iter.py 2 11 18.18%
qiskit_addon_obp/obp_estimator.py 20 54 37.04%
Totals Coverage Status
Change from base Build 15172425156: -7.8%
Covered Lines: 511
Relevant Lines: 554

💛 - Coveralls

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

Successfully merging this pull request may close these issues.

2 participants