Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-Linear memory for BaseLayerIterator #16

Open
robinhundt opened this issue Apr 23, 2024 · 1 comment
Open

Sub-Linear memory for BaseLayerIterator #16

robinhundt opened this issue Apr 23, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@robinhundt
Copy link
Collaborator

In 1ba607e we already improved the BaseLayerIter. However, there is an easy improvement we could do to the iteration code to reduce the memory from O(|base_circuit|) to something less than that. Currently, this linear memory cost is due to storing the inputs needed for each gate in a flat vec and calculating this for each gate in constructor. A, hopefully, better way would be to store a mapping of HashMap<GateId, u32> where we only store the inputs needed for gates of which at least one predecessor has already been processed and remove them when they are zero.
The intuition is that a gate for which no predecessor has been processed can't be yielded and once we yield a gate we can not yield it again, thus we don't need to store how many inputs are needed for these gates. Albeit a little more computationally costly, this should significantly reduce the memory cost of iteration objects for large base circuits.

@robinhundt robinhundt added enhancement New feature or request good first issue Good for newcomers labels Apr 23, 2024
@robinhundt
Copy link
Collaborator Author

Hi, sorry for the late reply. Yes, you can definitely give it a try. If you have questions, don't hesitate yo ask. The last weeks were stressful, but I have more time now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant