"""
Test routines for the functions in 'surface_code.py'

created on: 20/07/17

@author: eduardo
"""
import unittest
import numpy as np
import numpy.testing as nptest
import surface_code

# initialize the surface code object
distance = 6
surface = "toric"
sc = surface_code.SurfaceCode(distance, surface)

sc.select_measurement_protocol(0, 0, "single_rounds")

print("-------------------Testing random noise------------------------")
sc.apply_qubit_error(0.5, 0.5)
print(sc.qubits)

print("-------------------Testing stabilizer measurements-------------")
sc.reset()
sc.apply_qubit_error(.3, .3)
sc.measure_stabilizer_type("star")
sc.measure_stabilizer_type("plaq")
print(sc.tags)
print(sc.qubits)
pg = 0.008
eta = 0.0
a0 = 0.0
a1 = 0.0
protocol = "LOCAL"
theta = .0
PERFECT_LAST_ROUND = False

p = 0.029
q = 0.029
iterations = 1
cycles = 1

# Initialize objects
fail_rate = 0
sc = surface_code.SurfaceCode(distance, topology)
lc = layers.Layers(sc)
# sc.init_error_obj(topology, ps, pm, pg, eta, a0, a1, theta, protocol)

# Choose a measurement protocol
# sc.select_measurement_protocol(0, 0, "single", 0.0)

# Perform measurements
for i in range(iterations):

    # Errors and measurements
    # Random errors
    if q != 0:
        for t in range(cycles):
            sc.apply_qubit_error(p, 0)
            sc.measure_all_stabilizers()