Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Correct coefficient propagation in the operators #1077

Merged
merged 7 commits into from
Jun 29, 2020

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Jun 26, 2020

Summary

The coefficients of some operators (especially SummedOp and ComposedOp) are lost on conversion, which is fixed. Also state coefficients in an expectation should be applied squared, since the state is applied from both sides.

Details and comments

Some before-and-after comparisons:

op = 0 * (I + Z)
state = Plus
print((~StateFn(op) @ state).eval())
# before: (1+6.1e-17j), coefficient ignored!
# now: 0j

op = I
state = 0 * (Plus + Minus)
backend = Aer.get_backend('qasm_simulator')
sampler = CircuitSampler(backend).convert(~StateFn(op) @ state)
print(sampler.eval()) 
# before: (2+0j), coefficent ignored!
# now: 0j

op = I
state = (Plus + Minus) / numpy.sqrt(2)
sampler = CircuitSampler(backend).convert(~StateFn(op) @ state)
print(sampler.eval())
# before: (2+0j), same as with 0 coefficient
# now: (1+0j), correctly normalized

@Cryoris Cryoris added the Changelog: Bugfix Include in the Fixed section of the changelog label Jun 26, 2020
@Cryoris Cryoris added this to the 0.8 milestone Jun 26, 2020
@woodsp-ibm woodsp-ibm added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Jun 26, 2020
@Cryoris Cryoris merged commit bbb083f into qiskit-community:master Jun 29, 2020
@Cryoris Cryoris deleted the apply-all-coeffs-in-eval branch June 29, 2020 07:29
manoelmarques pushed a commit to manoelmarques/qiskit-aqua that referenced this pull request Jul 28, 2020
* factor in the coeff of ListOp

* fix coeff in composedop reduce

* state coeff must be squared (applied left and right)

* fix norm

* add test

* add reno
pbark pushed a commit to pbark/qiskit-aqua that referenced this pull request Sep 16, 2020
* factor in the coeff of ListOp

* fix coeff in composedop reduce

* state coeff must be squared (applied left and right)

* fix norm

* add test

* add reno
mtreinish pushed a commit to mtreinish/qiskit-core that referenced this pull request Nov 20, 2020
…skit-aqua#1077)

* factor in the coeff of ListOp

* fix coeff in composedop reduce

* state coeff must be squared (applied left and right)

* fix norm

* add test

* add reno
manoelmarques pushed a commit to manoelmarques/qiskit-terra that referenced this pull request Dec 2, 2020
…skit-aqua#1077)

* factor in the coeff of ListOp

* fix coeff in composedop reduce

* state coeff must be squared (applied left and right)

* fix norm

* add test

* add reno
manoelmarques pushed a commit to manoelmarques/qiskit-terra that referenced this pull request Dec 7, 2020
…skit-aqua#1077)

* factor in the coeff of ListOp

* fix coeff in composedop reduce

* state coeff must be squared (applied left and right)

* fix norm

* add test

* add reno
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Changelog: Bugfix Include in the Fixed section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants