This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 377
CircuitSampler fails on expressions consisting only of OperatorStateFns #1321
Comments
def to_circuit_op(self):
csfn = CircuitStateFn(self.primitive.to_circuit()) * self.coeff
return csfn.adjoint() if self.is_measurement else csfn |
@molar-volume Thanks. I think using Do you continue this issue? |
Hi @ikkoham, I have not work on it since the pull request, you can go ahead, if you want to continue :) |
OK, thanks |
ikkoham
added a commit
to ikkoham/qiskit-aqua
that referenced
this issue
Oct 26, 2020
manoelmarques
pushed a commit
to manoelmarques/qiskit-aqua
that referenced
this issue
Nov 9, 2020
* fix qiskit-community#1311 * fix qiskit-community#1317 * add a test of reps for trotterization * fix tests for qiskit-community#1311 * fix typing * fix qiskit-community#1321 * add release note * fix qiskit-community#1381 * add a test for to_opflow * Update qiskit/aqua/operators/converters/circuit_sampler.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> * remove None from constructor * simplify logic * Revert "remove None from constructor" This reverts commit c884ebb. * add releasenote * simplify logic (not iscomplex to isreal) * remove Optional * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> Co-authored-by: Panagiotis Barkoutsos <bpa@zurich.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
mtreinish
pushed a commit
to mtreinish/qiskit-core
that referenced
this issue
Nov 20, 2020
* fix qiskit-community/qiskit-aqua#1311 * fix qiskit-community/qiskit-aqua#1317 * add a test of reps for trotterization * fix tests for qiskit-community/qiskit-aqua#1311 * fix typing * fix qiskit-community/qiskit-aqua#1321 * add release note * fix qiskit-community/qiskit-aqua#1381 * add a test for to_opflow * Update qiskit/aqua/operators/converters/circuit_sampler.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> * remove None from constructor * simplify logic * Revert "remove None from constructor" This reverts commit c884ebba123adee22f252e11f90964a6defaec38. * add releasenote * simplify logic (not iscomplex to isreal) * remove Optional * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> Co-authored-by: Panagiotis Barkoutsos <bpa@zurich.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
manoelmarques
pushed a commit
to manoelmarques/qiskit-terra
that referenced
this issue
Dec 2, 2020
* fix qiskit-community/qiskit-aqua#1311 * fix qiskit-community/qiskit-aqua#1317 * add a test of reps for trotterization * fix tests for qiskit-community/qiskit-aqua#1311 * fix typing * fix qiskit-community/qiskit-aqua#1321 * add release note * fix qiskit-community/qiskit-aqua#1381 * add a test for to_opflow * Update qiskit/aqua/operators/converters/circuit_sampler.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> * remove None from constructor * simplify logic * Revert "remove None from constructor" This reverts commit c884ebba123adee22f252e11f90964a6defaec38. * add releasenote * simplify logic (not iscomplex to isreal) * remove Optional * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> Co-authored-by: Panagiotis Barkoutsos <bpa@zurich.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
manoelmarques
pushed a commit
to manoelmarques/qiskit-terra
that referenced
this issue
Dec 7, 2020
* fix qiskit-community/qiskit-aqua#1311 * fix qiskit-community/qiskit-aqua#1317 * add a test of reps for trotterization * fix tests for qiskit-community/qiskit-aqua#1311 * fix typing * fix qiskit-community/qiskit-aqua#1321 * add release note * fix qiskit-community/qiskit-aqua#1381 * add a test for to_opflow * Update qiskit/aqua/operators/converters/circuit_sampler.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> * remove None from constructor * simplify logic * Revert "remove None from constructor" This reverts commit c884ebba123adee22f252e11f90964a6defaec38. * add releasenote * simplify logic (not iscomplex to isreal) * remove Optional * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py * Update qiskit/aqua/operators/legacy/weighted_pauli_operator.py Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> Co-authored-by: Panagiotis Barkoutsos <bpa@zurich.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Information
What is the current behavior?
When the
convert
method ofCircuitSampler
ataqua/operators/converters/circuit_sampler.py
is called with such an operator which neither contains anyCircuitStateFn
, nor any of the contained operators can be converted toCircuitStateFn
, the following error is raisedSteps to reproduce the problem
Currently, the only thing which has a non-implemented
to_circuit_op()
method isOperatorStateFn
, so constructing a circuit entirely comprised ofOperatorStateFn
raises the exception:Incidentally, you necessarily need to have some composition of
OperatorStateFn
s to get the above error. If the operator to be converted contains only a singleOperatorStateFn
, you will get aNotImplementedError
The reason for this is that the
to_circuit_op()
function inListOp
explicitly checks forOperatorStateFn
and does not call its not implementedto_circuit_op()
function, while in the case of a singleOperatorStateFn
the function on it is called directly inCircuitSampler.convert()
.What is the expected behavior?
Raise a more descriptive error, or just work siletly.
Suggested solutions
CircuitSampler
to explicitly state that it not only approximates theCircuitStateFns
found in the given operator, but also converts anything else to circuits and approximates them as well (except of courseOperatorStateFn
, which does not support the conversion).circs
is an empty list and do not call theself.sample_circuits
inCircuitSampler.convert()
. Maybe priniting a warning message would be helpfull for users, so that they know why nothing was converted in their operator, but I am not sure.assemble_circuits()
inassembler/assemble_circuits.py
to explicitly check for emptycircuits
and raise a descriptive error, and aqua might try-catch this error, instead of explicitly checking for emptycircs
The text was updated successfully, but these errors were encountered: