Skip to content

Commit

Permalink
Added functional Quantum RAM prototype.
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftioon authored Mar 20, 2024
1 parent 4f2722f commit a04ee8f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
39 changes: 1 addition & 38 deletions src/quojo/quantum.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -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()
self.print()
47 changes: 47 additions & 0 deletions src/quojo/quantumComputer.mojo
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a04ee8f

Please sign in to comment.