-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add apply_layout method to SparsePauliOp This commit adds a new method, `apply_layout`, to the `SparsePauliOp` class. It takes in either a `TranspileLayout` object or a list of indices that represent a layout transformation caused by the transpiler and then returns a new SparsePauliOp object that applies a matching transformation. * Fix docs typo * Update releasenotes/notes/sparse-pauli-op-apply-layout-43149125d29ad015.yaml * Apply suggestions from code review Co-authored-by: Kevin Hartman <[email protected]> * Fix release note typo --------- Co-authored-by: Kevin Hartman <[email protected]>
- Loading branch information
1 parent
8651d34
commit 947e175
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
releasenotes/notes/sparse-pauli-op-apply-layout-43149125d29ad015.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
features: | ||
- | | ||
Added a new method, :meth:`~.SparsePauliOp.apply_layout`, | ||
to the :class:~.SparsePauliOp` class. This method is used to apply | ||
a :class:`~.TranspileLayout` layout from the transpiler | ||
to a :class:~.SparsePauliOp` observable that was built for an | ||
input circuit to the transpiler. This enables working with | ||
:class:`~.BaseEstimator` implementations and local transpilation more | ||
easily. For example:: | ||
from qiskit.circuit.library import RealAmplitudes | ||
from qiskit.quantum_info import SparsePauliOp | ||
from qiskit.primitives import BackendEstimator | ||
from qiskit.compiler import transpile | ||
from qiskit.providers.fake_provider import FakeNairobiV2 | ||
psi = RealAmplitudes(num_qubits=2, reps=2) | ||
H1 = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)]) | ||
backend = FakeNairobiV2() | ||
estimator = BackendEstimator(backend=backend, skip_transpilation=True) | ||
thetas = [0, 1, 1, 2, 3, 5] | ||
transpiled_psi = transpile(psi, backend, optimization_level=3) | ||
permuted_op = H1.apply_layout(transpiled_psi.layout) | ||
res = estimator.run(transpiled_psi, permuted_op, thetas) | ||
where an input circuit is transpiled locally before it's passed to | ||
:class:`~.BaseEstimator.run`. Transpilation expands the original | ||
circuit from 2 to 7 qubits (the size of ``backend``) and permutes its layout, | ||
which is then applied to ``H1`` using :meth:`~.SparsePauliOp.apply_layout` | ||
to reflect the transformations performed by :func:`~.transpile`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters