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

Unusual Memory Usage Patterns with 40 and 60 Qubits in ProjectQ #480

Open
saifawan2703 opened this issue Nov 6, 2024 · 1 comment
Open

Comments

@saifawan2703
Copy link

saifawan2703 commented Nov 6, 2024

#479 According to the response _(@damiansteiger),_ the memory issue is related to the number of qubits, with 40 qubits requiring 16TB of RAM. However, I have tested another circuit with 60 qubits and it runs successfully while using only 1GB of RAM. Below is the code for that:

from projectq import MainEngine
from projectq.ops import H, X, CNOT, Measure,Toffoli
from projectq.backends import CircuitDrawer, ResourceCounter, ClassicalSimulator

# Create a main compiler engine
Simulate = ClassicalSimulator()
eng = MainEngine(Simulate)

# Allocate a qubit register (60 qubits in this case)
qubits = eng.allocate_qureg(60)

# Put the second and third qubits in a simple entangled state
X | qubits[1]  
CNOT | (qubits[1], qubits[2])  
CNOT | (qubits[12], qubits[2]) 
CNOT | (qubits[3], qubits[2]) 
CNOT | (qubits[4], qubits[2]) 
CNOT | (qubits[5], qubits[2]) 
CNOT | (qubits[6], qubits[2]) 
Toffoli | (qubits[3], qubits[2], qubits[11])
Toffoli | (qubits[3], qubits[7], qubits[12])
Toffoli | (qubits[3], qubits[9], qubits[10])
Toffoli | (qubits[3], qubits[0], qubits[13])
CNOT | (qubits[2], qubits[3]) 
CNOT | (qubits[3], qubits[2]) 
CNOT | (qubits[4], qubits[2]) 
CNOT | (qubits[36], qubits[2]) 
Toffoli | (qubits[5], qubits[0], qubits[1])
Toffoli | (qubits[54], qubits[0], qubits[1])
CNOT | (qubits[10], qubits[2]) 
CNOT | (qubits[1], qubits[2]) 

# Measure all qubits
for qubit in qubits:
    Measure | qubit

# Execute the quantum circuit
eng.flush()

# Print the measurement results
print("Measured state:", [int(qubit) for qubit in qubits])

Is there is any issuse of simulator usage or any other?
I would greatly appreciate any insights or suggestions on how I might resolve this issue or better understand the underlying cause.

@damiansteiger
Copy link
Contributor

The question in #479 uses the Simulator which is a full-state simulator which stores the 2^n amplitudes in a vector for an n-qubit simulation and allows all operations.

This code snippet here uses the ClassicalSimulator which does only allow classical operations, see doc. This means it does not need to store any superposition state but only n-bits.

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