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

Memory leak #6

Open
davidsbyfield opened this issue Sep 30, 2024 · 4 comments
Open

Memory leak #6

davidsbyfield opened this issue Sep 30, 2024 · 4 comments
Assignees

Comments

@davidsbyfield
Copy link

davidsbyfield commented Sep 30, 2024

Hi LDPC V2 team!

Thank you for open sourcing this repo, it's very exciting to try new decoders.

In trying to use BP-LSD for decoding some circuits, I've run into a memory leak issue. I'm decoding about 18 circuits by varying distance and a physical noise parameter, as is standard. I'm using the SinterLsdDecoder object, which I had to import from ldpc.sinter_decoders instead of from src_python.ldpc.sinter_decoders.sinter_lsd_decoder import SinterLsdDecoder as in the examples, as this latter option didn't work for me (src_python was not found, despite existing. I think its a path issue, and that the repo may need to be re-organised a bit to fix it.)

Over the course of the experiment, my memory usage climbs up and up until eventually it maxes out and starts using the swap space on my device. Eventually, this is full too, and I have to restart the job. I have 24GB of ram and I don't run into this issue with any other codes, even when running much larger experiments.

I believe a possible fix to this issue may be implementing the compile_decoder_for_dem method on SinterLsdDecoder so that so many files for decoding do not need to be written and read from disk/memory, as is currently the case per the decode_via_files method used if compile_decoder_for_dem is not implemented.

I also attach below my general decoding script so that you may recreate the experiment. FWIW, I am running on WSL on a Windows laptop. I have allocated 12 physical cores and 24GB RAM to the WSL environment, and an 8GB swap. Please let me know if I am doing anything wrong - I followed the examples as close as I could.

import sinter
import stim
from ldpc.sinter_decoders import SinterLsdDecoder
from matplotlib import pyplot as plt
from pathlib import Path

def main():
    samples = sinter.collect(
        num_workers=12,
        max_shots=10_000,
        max_errors=100,
        tasks=load_circuit(),
        decoders=['bplsd'],
        custom_decoders={
            'bplsd': SinterLsdDecoder(
                max_iter=15,
                bp_method="ps",
                ms_scaling_factor=0.625,
                schedule="parallel",
                lsd_order=15),
        },

        print_progress=True,
        save_resume_filepath=f'bplsd.csv',
    )

    # Print samples as CSV data.
    print(sinter.CSV_HEADER)
    for sample in samples:
        print(sample.to_csv_line())

    # Render a matplotlib plot of the data.
    fig, ax = plt.subplots(1, 1)
    sinter.plot_error_rate(
        ax=ax,
        stats=samples,
        group_func=lambda stat: f"Code d={stat.json_metadata['d']}",
        x_func=lambda stat: stat.json_metadata['p'],
    )
    ax.loglog()
    ax.set_ylim(1e-5, 1)
    ax.grid()
    ax.set_title('Logical Error Rate vs Physical Error Rate')
    ax.set_ylabel('Logical Error Probability (per shot)')
    ax.set_xlabel('Physical Error Rate')
    ax.legend()

    # Save to file and also open in a window.
    fig.savefig('plot.png')
    plt.show()


if __name__ == '__main__':
    main()

@davidsbyfield
Copy link
Author

NB: this leak appears to also be present for SinterBpOsdDecoder

@quantumgizmos
Copy link
Owner

Thanks @davidsbyfield for reporting this. We will take a look at this and report back.

@timohillmann
Copy link
Collaborator

We had found a memory leak back in the days for the LSD decoder and thought we had fixed it. Do you know by any chance if you observe it for the overlapping window decoders as well?
You can use them for standard decoding as well of course.

@davidsbyfield
Copy link
Author

Hi both, thanks for responding and sorry for my slow response! On testing the SinterDecoder_BPOSD_OWD, SinterDecoder_LSD_OWD, SinterDecoder_PyMatching_OWD decoders, they do not seem to have the leak. Thanks for looking into this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants