`update_initial_operator` keeps old identity term even when the new operator doesn't have it
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start with MajoranaPropagator.update_initial_operator and the identity core_term handling mentioned in detail/monomial_propagator/MonomialPropagator.inl around line 150. Run the reproduction in the issue in both Schrödinger and Heisenberg modes, then check the relevant tests for omitted operator terms. Done means updating without an identity term produces the expected value of 1.0 in both modes.
Written by the indexing model from the issue text.
Description
Bug description
Summary: MajoranaPropagator.update_initial_operator drops every term of the old initial operator that is missing from new_operator, except the identity term (). Any constant in the original operator then leaks into every later expectation_value(). This happens in both the Schrödinger and the Heisenberg picture.
Likely cause: the constructor stores the identity separately as core_term ("Store the core term separately…" in detail/monomial_propagator/MonomialPropagator.inl, around line 150). The update path appears to replace only the non-identity terms and never resets core_term.
Workaround: always include (): 0.0 (or the intended constant) in new_operator.
Suggested fix: reset the identity coefficient to new_operator.terms.get((), 0) on update, consistent with how other omitted terms are treated. Alternatively, document the asymmetry in the update_initial_operator docstring.
Steps to reproduce
from monoprop import MajoranaOperator, MajoranaPropagator
from monoprop.circuit import Circuit
n, hf = 2, [0] # 2 modes, mode 0 occupied, so <i g0 g1> = +1
for sc in (4, None): # Schrodinger, Heisenberg
mp = MajoranaPropagator(MajoranaOperator({(): 5.0, (0, 1): 1j}, n), hf,
cutoff=4, schrodinger_cutoff=sc)
mp.propagate(Circuit([], n))
mp.update_initial_operator(MajoranaOperator({(0, 1): 1j}, n))
print(mp.expectation_value()) # prints 6.0, expected 1.0
Expected behavior
Expected a full update of the initial observable, but instead you get your new observable + identity, and this has an effect on e.g expectation values, as show below.
| Initial operator | Update to | Expected | Actual |
|---|---|---|---|
{(): 5, (0,1): 1j} |
{(0,1): 1j} |
1.0 | 6.0 (both pictures) |
{(): 5, (0,1): 1j} |
{(): 0, (0,1): 1j} |
1.0 | 1.0 (removing identity manually) |
{(0,1): 1j, (2,3): 1j} |
{(0,1): 1j} |
1.0 | 1.0 (since non-identity terms are correctly dropped) |
So omitted terms are dropped, but the identity is treated differently.
Operating system
macOS (Apple Silicon)
monoprop version
0.9.2a1
Python version
3.11.15
Additional context
No response
- Dominant language
- C++
- Stars
- 52
- Forks
- 2
- Avg merge
- 17h 30m
- Merged PRs (30d)
- 29
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Algorithmiq/monoprop
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Algorithmiq/monoprop#193 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Algorithmiq/monoprop#192 ·
Maintainers usually reply within 1 day
-
bug performance
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Algorithmiq/monoprop#191 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Algorithmiq/monoprop#189 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
Algorithmiq/monoprop#405 ·
Maintainers usually reply within 1 day
All issues in Algorithmiq/monoprop
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nasa/fprime#6225 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement source/qq
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
metasequoiaime/msime-windows#1054 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
amnezia-vpn/amnezia-client#3297 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
metasequoiaime/msime#8620 ·
Maintainers usually reply within 1 day
-
area/docs type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ChiR24/Unreal_mcp#679 ·
Maintainers usually reply within 1 day