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

Implement the fusion methods for Fibonacci model #70

Merged
merged 5 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/anyon_braiding_simulator/Braiding.py
Original file line number Diff line number Diff line change
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(self.model.model_type)):
for qubit_index, fusion_pair in enumerate(self.fusion.qubit_enc()):
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(self.model.model_type)
qubit_encoding = self.fusion.qubit_enc()
if qubit_encoding is None:
raise ValueError("Fusion qubit encoding returned None")

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

for i in range(num_qubits):
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_braiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from Braiding import Braid
from Model import Model
from anyon_braiding_simulator import Anyon, AnyonModel, IsingTopoCharge, TopoCharge, State, FusionPair
from anyon_braiding_simulator import Anyon, AnyonModel, IsingTopoCharge, FibonacciTopoCharge, TopoCharge, State, FusionPair


@pytest.fixture
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_qubit_enc(setup_state):
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(braid.model.model_type))) == set(map(str, correct))
assert set(map(str, braid.fusion.qubit_enc())) == set(map(str, correct))

def test_swap_to_qubit(setup_state):
braid = setup_state
Expand Down
139 changes: 99 additions & 40 deletions python/tests/test_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,144 @@
Fusion,
FusionPair,
IsingTopoCharge,
FibonacciTopoCharge,
State,
TopoCharge,
)


@pytest.fixture
def state() -> State:
def ising_state() -> State:
state = State()
for i in range(6):
state.add_anyon(Anyon(f'{i}', TopoCharge.from_ising(IsingTopoCharge.Sigma), (0, 0)))
return state

@pytest.fixture
def fibo_state() -> State:
state = State()
state.set_anyon_model(AnyonModel.Fibonacci)
for i in range(6):
state.add_anyon(Anyon(f'{i}', TopoCharge.from_fibonacci(FibonacciTopoCharge.Tau), (0,0)))
return state

@pytest.mark.fusion
def test_str_1(state):
state.add_operation(1, FusionPair(0, 1))
state.add_operation(1, FusionPair(2, 3))
state.add_operation(1, FusionPair(4, 5))
state.add_operation(2, FusionPair(2, 4))
state.add_operation(3, FusionPair(0, 2))

fusion = Fusion(state)
def test_str_1(ising_state):
ising_state.add_operation(1, FusionPair(0, 1))
ising_state.add_operation(1, FusionPair(2, 3))
ising_state.add_operation(1, FusionPair(4, 5))
ising_state.add_operation(2, FusionPair(2, 4))
ising_state.add_operation(3, FusionPair(0, 2))

fusion = Fusion(ising_state)
expected = '0 1 2 3 4 5 \n| | | | | | \n|─| |─| |─| \n| |───| \n|───| \n| '

assert str(fusion) == expected


@pytest.mark.fusion
def test_apply_ising_fusion(state):
fusion = Fusion(state)
def test_apply_ising_fusion(ising_state):
fusion = Fusion(ising_state)

psi = [1, 0, 0]
vacuum = [0, 1, 0]
sigma = [0, 0, 1]

assert fusion.apply_fusion(psi, psi, AnyonModel.Ising) == vacuum
assert fusion.apply_fusion(vacuum, vacuum, AnyonModel.Ising) == vacuum
assert fusion.apply_fusion(sigma, sigma, AnyonModel.Ising) == [psi[i] + vacuum[i] for i in range(3)]
assert fusion.apply_fusion(psi, psi) == vacuum
assert fusion.apply_fusion(vacuum, vacuum) == vacuum
assert fusion.apply_fusion(sigma, sigma) == [psi[i] + vacuum[i] for i in range(3)]

psi_sigma = [1, 0, 1]
assert fusion.apply_fusion(psi_sigma, psi_sigma, AnyonModel.Ising) == [1, 2, 2]
assert not fusion.apply_fusion(psi_sigma, psi_sigma, AnyonModel.Ising) == [2, 1, 2] # get owned rishi

assert fusion.apply_fusion(psi_sigma, psi_sigma) == [1, 2, 2]
assert not fusion.apply_fusion(psi_sigma, psi_sigma) == [2, 1, 2] # get owned rishi

@pytest.mark.fusion
def test_qubit_enc(state):
state.add_operation(1, FusionPair(0, 1))
state.add_operation(1, FusionPair(2, 3))
state.add_operation(1, FusionPair(4, 5))
state.add_operation(2, FusionPair(2, 4))
state.add_operation(3, FusionPair(0, 2))
def test_apply_fibo_fusion(fibo_state):
fusion = Fusion(fibo_state)

fusion = Fusion(state)
tau = [1,0]
vac = [0,1]

assert fusion.apply_fusion(tau, tau) == [1,1]
assert fusion.apply_fusion(vac,vac) == vac
assert fusion.apply_fusion(tau, vac) == tau

tau_vac = [1,1]

assert fusion.apply_fusion(tau_vac, tau_vac) == [3,2]

@pytest.mark.fusion
def test_ising_qubit_enc(ising_state):
ising_state.add_operation(1, FusionPair(0, 1))
ising_state.add_operation(1, FusionPair(2, 3))
ising_state.add_operation(1, FusionPair(4, 5))
ising_state.add_operation(2, FusionPair(2, 4))
ising_state.add_operation(3, FusionPair(0, 2))

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

assert set(map(str, fusion.qubit_enc(AnyonModel.Ising))) == set(map(str, correct))
assert set(map(str, fusion.qubit_enc())) == set(map(str, correct))

@pytest.mark.fusion
def test_fibo_qubit_enc(fibo_state):
fibo_state.add_operation(1, FusionPair(0, 1))
fibo_state.add_operation(1, FusionPair(2, 3))
fibo_state.add_operation(1, FusionPair(4, 5))
fibo_state.add_operation(2, FusionPair(2, 4))
fibo_state.add_operation(3, FusionPair(0, 2))

fusion = Fusion(fibo_state)

print(fusion.qubit_enc())
pass



@pytest.mark.fusion
def test_verify_fusion_result(state):
fusion = Fusion(state)
assert not fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Sigma), AnyonModel.Ising)
assert fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Vacuum), AnyonModel.Ising)
assert fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Psi), AnyonModel.Ising)
def test_ising_verify_fusion_result(ising_state):
fusion = Fusion(ising_state)
assert not fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Sigma))
assert fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Vacuum))
assert fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Psi))

ising_state.add_anyon(Anyon('7', TopoCharge.from_ising(IsingTopoCharge.Sigma), (0, 0)))
fusion = Fusion(ising_state)
assert not fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Vacuum))
assert not fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Psi))
assert fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Sigma))

@pytest.mark.fusion
def test_fibo_verify_fusion_result(fibo_state):
fusion = Fusion(fibo_state)

state.add_anyon(Anyon('7', TopoCharge.from_ising(IsingTopoCharge.Sigma), (0, 0)))
assert fusion.verify_fusion_result(TopoCharge.from_fibonacci(FibonacciTopoCharge.Tau))
assert fusion.verify_fusion_result(TopoCharge.from_fibonacci(FibonacciTopoCharge.Vacuum))

state = State()
state.set_anyon_model(AnyonModel.Fibonacci)
for i in range(6):
state.add_anyon(Anyon(f'{i}', TopoCharge.from_fibonacci(FibonacciTopoCharge.Vacuum), (0,0)))
fusion = Fusion(state)
assert not fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Vacuum), AnyonModel.Ising)
assert not fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Psi), AnyonModel.Ising)
assert fusion.verify_fusion_result(TopoCharge.from_ising(IsingTopoCharge.Sigma), AnyonModel.Ising)

assert not fusion.verify_fusion_result(TopoCharge.from_fibonacci(FibonacciTopoCharge.Tau))
assert fusion.verify_fusion_result(TopoCharge.from_fibonacci(FibonacciTopoCharge.Vacuum))




@pytest.mark.fusion
def test_minimum_possible_anyons(state):
def test_ising_minimum_possible_anyons(ising_state):

fusion = Fusion(state)
fusion = Fusion(ising_state)

assert (fusion.minimum_possible_anyons(10, AnyonModel.Ising) == [21,22])
assert (fusion.minimum_possible_anyons(5, AnyonModel.Ising) == [11,12])
assert (fusion.minimum_possible_anyons(10) == [21,22])
assert (fusion.minimum_possible_anyons(5) == [11,12])

@pytest.mark.fusion
def test_fibo_minimum_possible_anyons(ising_state):
ising_state.set_anyon_model(AnyonModel.Fibonacci)
fusion = Fusion(ising_state)

assert(fusion.minimum_possible_anyons(10, AnyonModel.Fibonacci) == [17,18]);
assert(fusion.minimum_possible_anyons(0, AnyonModel.Fibonacci) == [0,1,2,3]);
assert(fusion.minimum_possible_anyons(10) == [17,18])
assert(fusion.minimum_possible_anyons(0) == [0,1,2,3])
Loading