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 Issue #174

Open
luckyluke98 opened this issue Nov 22, 2023 · 1 comment
Open

Memory Issue #174

luckyluke98 opened this issue Nov 22, 2023 · 1 comment
Assignees

Comments

@luckyluke98
Copy link

Hi,
I'm having a memory problem, I'm simulating the BB84 + Cascade protocol on various pairs of QKD nodes. I start a simulation of 1 second and the various couples begin to exchange keys, unfortunately I notice that the simulation consumes an enormous amount of memory, in fact for 1 second of simulation it consumes around 12 GB. Since I checked if the problem was mine but it isn't (I don't have objects that fill and don't empty) I think it's very likely that there is a memory leak in the implementation of the Cascade or BB84 protocol.

I hope I explained myself.

Thank you

Luca

@luckyluke98
Copy link
Author

Hi, I'll try to be more explicit. I'll simplify with an example that I found on the "tests/qkd/test_cascade.py" folder, which I modified slightly.

The simulation occupies 4.7 GB of RAM, for a simulation on two QKD Nodes.

Luca

class Parent(StackProtocol):
    def __init__(self, own: "Node", keysize: int, keynum: int):
        super().__init__(own, "")
        self.upper_protocols = []
        self.lower_protocols = []
        self.keysize = keysize
        self.keynum = keynum
        self.keys = []
        self.counter = 0

    def init(self):
        pass

    def pop(self, key):
        self.keys.append(key)
        self.counter += 1

    def push(self):
        self.lower_protocols[0].push(self.keysize, self.keynum)

    def received_message(self):
        pass


def test_cascade_run():
    KEYSIZE = 128
    KEYNUM = math.inf

    tl = Timeline(1e12)

    ls_arg = {"LightSource" : 
                        {
                            "mean_photon_num" : 1
                        }
                    }

    alice = QKDNode("alice", tl, component_templates = ls_arg)
    bob = QKDNode("bob", tl)
    alice.set_seed(0)
    bob.set_seed(0)
    pair_bb84_protocols(alice.protocol_stack[0], bob.protocol_stack[0])
    pair_cascade_protocols(alice.protocol_stack[1], bob.protocol_stack[1])

    qc0 = QuantumChannel("qc0", tl, distance=1e3, attenuation=0.00000,
                         polarization_fidelity=1)
    qc1 = QuantumChannel("qc1", tl, distance=1e3, attenuation=0.00000,
                         polarization_fidelity=1)
    
    qc0.set_ends(alice, bob.name)
    qc1.set_ends(bob, alice.name)
    cc0 = ClassicalChannel("cc0", tl, distance=1e3)
    cc1 = ClassicalChannel("cc1", tl, distance=1e3)
    cc0.set_ends(alice, bob.name)
    cc1.set_ends(bob, alice.name)

    # Parent
    pa = Parent(alice, KEYSIZE, KEYNUM)
    pb = Parent(bob, KEYSIZE, KEYNUM)
    alice.protocol_stack[1].upper_protocols.append(pa)
    pa.lower_protocols.append(alice.protocol_stack[1])
    bob.protocol_stack[1].upper_protocols.append(pb)
    pb.lower_protocols.append(bob.protocol_stack[1])

    process = Process(pa, "push", [])
    event = Event(0, process)
    tl.schedule(event)

    tl.init()
    tl.run()

@caitaozhan caitaozhan self-assigned this Mar 15, 2024
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

2 participants