Skip to content

Commit

Permalink
Fixed to newest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftioon authored Mar 29, 2024
1 parent 767b60c commit 2eb53d4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ share/python-wheels/
*.egg
MANIFEST

# VSCode
.vscode/settings.json

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
Empty file removed CHANGELOG.md
Empty file.
2 changes: 1 addition & 1 deletion src/quojo/complexNum.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ struct ComplexMatrix:
fn print(borrowed self) raises -> None:
for i in range(self.rows):
for j in range(self.cols):
print_no_newline(i, j, " ")
print(i, j, end = " ")
self.data[i * self.cols + j].print()
22 changes: 2 additions & 20 deletions src/quojo/quantum.mojo
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
import complexNum as comp
import random
from math import sin, cos
from collections.vector import DynamicVector
from collections.list import List
from collections.dict import Dict, KeyElement

@value
struct StringKey(KeyElement):
var s: String

fn __init__(inout self, owned s: String):
self.s = s ^

fn __init__(inout self, s: StringLiteral):
self.s = String(s)

fn __hash__(self) -> Int:
let ptr = self.s._buffer.data.value
return hash(DTypePointer[DType.int8](ptr), len(self.s))

fn __eq__(self, other: Self) -> Bool:
return self.s == other.s

struct QuantumGates:

var HadamardMatrix: comp.ComplexMatrix
var mX: comp.ComplexMatrix
var mY: comp.ComplexMatrix
Expand All @@ -48,7 +30,7 @@ struct QuantumGates:
self.HadamardMatrix[1, 0] = comp.ComplexNum(1, 0)
self.HadamardMatrix[1, 1] = comp.ComplexNum(-1, 0)

self.HadamardMatrix = self.HadamardMatrix * (1 / (2 ** 0.5))
self.HadamardMatrix = self.HadamardMatrix * (1 / (2.0 ** 0.5))

# Initialise Phase Shift Gate
self.mP = comp.ComplexMatrix(2, 2)
Expand Down
38 changes: 8 additions & 30 deletions src/quojo/quantumComputer.mojo
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import quantum as Q
from quantum import QuantumGates as Gates
import complexNum as comp
from collections.vector import DynamicVector
from collections.list import List


struct QMC: #Quantum Memory Cells
#TODO: Apply Memory Paging of 4 Qubit
struct QuantumPages: #Quantum Memory Cells
var top: Int
var addresses: DynamicVector[Int]
var addresses: List[Int]
var data: comp.ComplexArray

fn __init__(inout self, capacity: Int) raises:
self.top = 1
self.addresses = DynamicVector[Int]()
self.addresses.push_back(1)
self.addresses = List[Int]()
self.addresses.append(1)
self.data = comp.ComplexArray(capacity + 1)

fn dump(inout self) raises:
Expand All @@ -38,34 +38,12 @@ struct QMC: #Quantum Memory Cells
self.data[self.top + i] = contents.qubit[0, i]

self.top += size
self.addresses.push_back(self.top)
self.addresses.append(self.top)

if mode == "o":
var size = 2
var start = self.addresses[address]
self.delete(address)

for i in range(start, start + size):
self.data[i] = contents.qubit[0, i - start]


fn write(inout self, contents: Q.Qudit, mode: String, address: Int = 0) raises:
if mode == "a":
var size = contents.qudit.cols

for i in range(size):
self.data[self.top + i] = contents.qudit[0, i]

self.top += size
self.addresses.push_back(self.top)

if mode == "o":
var addrSize = self.addresses[address + 1] - self.addresses[address]
var size = contents.qudit.cols
if size > addrSize:
raise("Given contents too big, cannot overwrite")
var start = self.addresses[address]
self.delete(address)

for i in range(start, start + size):
self.data[i] = contents.qudit[0, i - start]
self.data[i] = contents.qubit[0, i - start]

0 comments on commit 2eb53d4

Please sign in to comment.