From a04ee8f22b967832c51e429af8d97cb371cbaf56 Mon Sep 17 00:00:00 2001 From: Jake Lu Date: Wed, 20 Mar 2024 13:21:26 +0000 Subject: [PATCH] Added functional Quantum RAM prototype. --- src/quojo/quantum.mojo | 39 +--------------------------- src/quojo/quantumComputer.mojo | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 src/quojo/quantumComputer.mojo diff --git a/src/quojo/quantum.mojo b/src/quojo/quantum.mojo index 07f58f5..54643af 100644 --- a/src/quojo/quantum.mojo +++ b/src/quojo/quantum.mojo @@ -349,41 +349,4 @@ struct Qudit: self.qudit = comp.ComplexMatrix(1, self.width) self.qudit[0, index] = comp.ComplexNum(1, 0) - self.print() - -# struct QuantumRAM: -# var top: Int -# var capacity: Int -# var addresses: DynamicVector[Int] -# var data: comp.ComplexArray - -# fn __init__(inout self, capacity: Int) raises: -# self.top = 0 -# self.capacity = capacity -# self.addresses = DynamicVector[Int]() -# self.data = comp.ComplexArray(capacity * 2) - -# fn store(inout self, address: Int, qubit: Qubit) raises: -# self.addresses.push_back(address) -# self.data[self.top] = qubit.qubit[0, 0] -# self.data[self.top + 1] = qubit.qubit[0, 1] -# self.top += 2 - -# fn store(inout self, address: Int, qudit: Qudit) raises: -# self.addresses.push_back(address) -# for i in range(qudit.width): -# self.data[self.top + i] = qudit.qudit[0, i] -# self.top += qudit.width - -# fn dump(inout self) raises: -# self.data.print() - -# fn main() raises: -# var q1 = Qudit("00") -# var q2 = Qudit("10") -# var q3 = Qudit("10") -# var r = QuantumRAM(12) -# r.store(0, q1) -# r.store(1, q2) -# r.store(2, q3) -# r.dump() \ No newline at end of file + self.print() \ No newline at end of file diff --git a/src/quojo/quantumComputer.mojo b/src/quojo/quantumComputer.mojo new file mode 100644 index 0000000..acf2404 --- /dev/null +++ b/src/quojo/quantumComputer.mojo @@ -0,0 +1,47 @@ +import quantum as Q +from quantum import QuantumGates as Gates +import complexNum as comp + +# https://arxiv.org/pdf/2309.14432.pdf +struct QuantumRAM: + var Bus: quantum.Qudit + var top: Int + var capacity: Int + var addresses: DynamicVector[Int] + var data: comp.ComplexArray + + fn __init__(inout self, size: Int) raises: + var state: String = "" + for i in range(size): + state += "0" + + self.Bus = Q.Qudit(state) + self.top = 0 + self.capacity = size + self.addresses = DynamicVector[Int]() + self.data = comp.ComplexArray(2 ** size) + + fn store(inout self, qubit: Q.Qubit) raises: + var size = 2 + if self.top + size > 2 ** self.capacity: + raise "Quantum RAM Does Not have Enough Space" + + for i in range(size): + self.data[self.top + i] = qubit.qubit[0, i] + + self.addresses.push_back(self.top) + self.top += size + + fn store(inout self, qudit: Q.Qudit) raises: + var size = 2 ** qudit.width + if self.top + size > 2 ** self.capacity: + raise "Quantum RAM Does Not have Enough Space" + + for i in range(size): + self.data[self.top + i] = qudit.qudit[0, i] + + self.addresses.push_back(self.top) + self.top += size + + fn dump(inout self) raises: + self.data.print() \ No newline at end of file