Schrodinger graph construction is O(layers^2): every append front-inserts into a std::vector
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 46/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- cpp
- Domain
- performance
Research direction
Start with cpp/include/monoprop/MPGraph.h and trace the layer container and append operations, then inspect the listed call sites in MPGraphViews.h, MPGraph.cpp, PareGraph.cpp, and cpp/tests/mp_graph_tests.cpp. Confirm how iterator types, construction, compaction, and memory accounting depend on the container before making a change. Run just test, just test-mpi "1;2;4", and just test-wide; done means the graph tests pass and deep Schrödinger graph construction no longer incurs quadratic front-insertion work.
Written by the indexing model from the issue text.
Description
🤖 AI text below 🤖
What
In the Schrödinger picture every graph layer is inserted at the front of a std::vector, making
graph construction quadratic in the layer count.
cpp/include/monoprop/MPGraph.h:56-58
auto append_position() -> LayerIterator {
return schrodinger_ ? active_begin_iterator() : active_end_iterator();
}
auto append_layer(Layer layer) -> void { layers_.emplace(append_position(), std::move(layer)); }
active_begin_iterator() is layers_.begin() + front_offset_, so each Schrödinger append
move-assigns every layer already in the vector.
Why this is a problem
Layer (cpp/monoprop/detail/graph/MPGraphLayers.h) is a shared_ptr<const LayerCore> plus an
optional<CosMask>, and CosMask owns a vector<pair<size_t, uint64_t>> — so each move is a real
move-assignment, not a memmove. Building an L-layer Schrödinger graph therefore costs
L(L-1)/2 move-assignments:
| layers | move-assignments |
|---|---|
| 1 000 | ~5·10^5 |
| 10 000 | ~5·10^7 |
| 100 000 | ~5·10^9 |
Heisenberg appends at the back and is unaffected, so this only bites deep Schrödinger-picture
circuits — but those are exactly the ones where layer counts get large.
Suggested fix
Change layers_ to std::deque<Layer> and push at the appropriate end. Touch points:
cpp/include/monoprop/MPGraph.h— theLayerIterator/ConstLayerIteratortypedefs, the
std::vector<Layer>constructor overload,append_layer.cpp/monoprop/detail/graph/MPGraphViews.h:57,78—MPGraphView's container reference and pointer.cpp/monoprop/MPGraph.cpp—maybe_compact_layers:33(dequeerasefrom the front is already
cheap),slice_graph:61, andstorage_memory_usage, which useslayers_.capacity(); a deque has
nocapacity(), so usesize().cpp/monoprop/detail/pare/PareGraph.cpp:119andcpp/tests/mp_graph_tests.cpp:120, which build a
std::vector<Layer>to hand to theMPGraphconstructor.
Alternative considered and not recommended. Always push_back and reverse on read, reusing the
reverse_ flag MPGraphView already has. This is a smaller diff on paper but riskier: every
MPGraph::get_layer(i) caller assumes index 0 is first-in-replay-order — graph_gate_arrays_,
set_parameter_mapping, n_gates, cos_index_count_, graph_data, build_cos_callbacks — and each
would need its indexing inverted for the Schrödinger case. Prefer the deque.
Verification
- Time
build_graphon a deep Schrödinger circuit (a few thousand layers) before and after; the curve
should flatten from quadratic to linear. just test,just test-mpi "1;2;4",just test-wide— this touches graph storage, which the MPI
and wide-index legs both cover.
Found by a code-reading review of the repository at 29a8050. No build tree was available, so the
analysis is from source inspection and should be confirmed by measurement.
- Dominant language
- C++
- Stars
- 52
- Forks
- 2
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 22
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 4/5 3-5 days Newbie friendliness 44/100
Algorithmiq/monoprop#442 ·
Maintainers usually reply within 1 day
All issues in Algorithmiq/monoprop
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
? - Needs Triage bot_watch bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NVIDIA/cudf-spark-jni#5594 ·
Maintainers usually reply within 1 day
-
Branch-master
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
TrinityCore/TrinityCore#32177 ·
Maintainers usually reply within 10 days
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
mw00/project-maya#1499 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day