-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Translate parameterized gates only in gradient calculations (Qiskit/q…
…iskit#9067) * translate parameterized gates only * TranslateParameterized to proper pass * update reno w/ new trafo pass * Only add cregs if required * rm unused import * directly construct DAG Co-authored-by: Matthew Treinish <[email protected]> * target support * qubit-wise support of unrolling * globally check for supported gates in target that's because this pass is run before qubit mapping * lint! * updates after merge from main Co-authored-by: Matthew Treinish <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7326947
commit c82f3f7
Showing
7 changed files
with
210 additions
and
59 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
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
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
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,49 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2022. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Test primitives that check what kind of operations are in the circuits they execute.""" | ||
|
||
from qiskit.primitives import Estimator, Sampler | ||
|
||
|
||
class LoggingEstimator(Estimator): | ||
"""An estimator checking what operations were in the circuits it executed.""" | ||
|
||
def __init__( | ||
self, | ||
circuits=None, | ||
observables=None, | ||
parameters=None, | ||
options=None, | ||
operations_callback=None, | ||
): | ||
super().__init__(circuits, observables, parameters, options) | ||
self.operations_callback = operations_callback | ||
|
||
def _run(self, circuits, observables, parameter_values, **run_options): | ||
if self.operations_callback is not None: | ||
ops = [circuit.count_ops() for circuit in circuits] | ||
self.operations_callback(ops) | ||
return super()._run(circuits, observables, parameter_values, **run_options) | ||
|
||
|
||
class LoggingSampler(Sampler): | ||
"""A sampler checking what operations were in the circuits it executed.""" | ||
|
||
def __init__(self, operations_callback): | ||
super().__init__() | ||
self.operations_callback = operations_callback | ||
|
||
def _run(self, circuits, parameter_values, **run_options): | ||
ops = [circuit.count_ops() for circuit in circuits] | ||
self.operations_callback(ops) | ||
return super()._run(circuits, parameter_values, **run_options) |
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
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
Oops, something went wrong.