Skip to content

Commit

Permalink
fixed topocharge
Browse files Browse the repository at this point in the history
  • Loading branch information
juli6nne committed Jun 22, 2024
1 parent 6417d27 commit 35878dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions python/anyon_braiding_simulator/Braiding.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import numpy as np
from anyon_braiding_simulator import State, Fusion, AnyonModel, Model
from anyon_braiding_simulator import State, Fusion, Model, AnyonModel

class Braid:
def __init__(self, state: State, model: Model):
"""
Parameters:
- state (State): The state of the system containing anyons and fusion operations
- model_type (AnyonModel): Model to use for the braid simulation
- model (Model): Model to use for the braid simulation
"""
self.state = state
self.anyons = state.anyons
Expand Down Expand Up @@ -74,7 +74,7 @@ def swap_to_qubit(self, time: int, swap_index: int) -> int:
index_A, index_B = swap[swap_index]

# Iterate through the qubit encoding to find the matching qubit
for qubit_index, fusion_pair in enumerate(self.fusion.qubit_enc()):
for qubit_index, fusion_pair in enumerate(self.fusion.qubit_enc(self.model.model_type)):
if {index_A, index_B} == {fusion_pair.anyon_1, fusion_pair.anyon_2}:
return qubit_index

Expand Down Expand Up @@ -112,11 +112,11 @@ def generate_swap_matrix(self, time: int, swap_index: int) -> np.ndarray:
return swap_matrix

def generate_overall_unitary(self, time: int, swap_index: int) -> np.ndarray:
qubit_encoding = self.fusion.qubit_enc()
qubit_encoding = self.fusion.qubit_enc(self.model.model_type)
if qubit_encoding is None:
raise ValueError("Fusion qubit encoding returned None")

num_qubits = len(self.fusion.qubit_enc())
num_qubits = len(self.fusion.qubit_enc(self.model.model_type))
unitary = np.eye(2**num_qubits) # Start with identity matrix of appropriate size

for i in range(num_qubits):
Expand Down
6 changes: 3 additions & 3 deletions python/tests/test_braiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ def setup_state():
state.add_operation(3, FusionPair(0, 2))

# Initialize the braid with the given state and model type
braid = Braid(state, AnyonModel.Ising)
braid = Braid(state, Model(AnyonModel.Ising))

return braid

def test_qubit_enc(setup_state):
braid = setup_state

correct = [FusionPair(0, 1), FusionPair(2, 3), FusionPair(2, 4)]
correct = [FusionPair(0, 1), FusionPair(2, 4), FusionPair(2, 3)]

# Confirm qubit_enc is working as expected
assert set(map(str, braid.fusion.qubit_enc())) == set(map(str, correct))
assert set(map(str, braid.fusion.qubit_enc(braid.model.model_type))) == set(map(str, correct))

def test_swap_to_qubit(setup_state):
braid = setup_state
Expand Down

0 comments on commit 35878dc

Please sign in to comment.