Ejemplo n.º 1
0
def main():

    input_data = sys.argv[1:]

    # Set node numbers
    min_tel = int(input_data[0])
    max_tel = int(input_data[1])
    number = int(input_data[2])

    # Initialize the connection
    Bob = CQCConnection("Bob")

    for n in range(min_tel, max_tel + 1):

        for _ in range(number):

            # Start teleporting back and fourth

            for _ in range(n):

                # Make an EPR pair with other node
                q = Bob.recvEPR()

                # Receive info about corrections
                data = Bob.recvClassical(timout=3600)
                Bob.closeClassicalServer()
                message = list(data)
                a = message[0]
                b = message[1]

                # Apply corrections
                if b == 1:
                    q.X()
                if a == 1:
                    q.Z()

                    # Make an EPR pair with next node
                qEPR = Bob.recvEPR()

                # Apply the local teleportation operations
                q.cnot(qEPR)
                q.H()

                # Measure the qubits
                a = q.measure()
                b = qEPR.measure()
                to_print = "App {}: Measurement outcomes are: a={}, b={}".format(
                    Bob.name, a, b)
                print("|" + "-" * (len(to_print) + 2) + "|")
                print("| " + to_print + " |")
                print("|" + "-" * (len(to_print) + 2) + "|")

                # Send corrections to other node
                Bob.sendClassical("Alice", [a, b])
                Bob.closeClassicalChannel("Alice")

                # Stop the connection
    Bob.close()
Ejemplo n.º 2
0
def main():

    input_data = sys.argv[1:]

    # Set node numbers
    min_tel = int(input_data[0])
    max_tel = int(input_data[1])
    number = int(input_data[2])

    # Clear file
    with open("times{}_{}_{}.txt".format(min_tel, max_tel, number), "w") as f:
        pass

        # Initialize the connection
    Alice = CQCConnection("Alice")

    times = []

    for n in range(min_tel, max_tel + 1):

        print("========")
        print(n)
        print("========")

        for _ in range(number):

            # start timer
            t1 = timer()

            # Create a qubit to teleport
            q = qubit(Alice)

            # Prepare the qubit to teleport in |+>
            q.H()

            # Start teleporting back and fourth

            for _ in range(n):
                # Make an EPR pair with next node
                qEPR = Alice.createEPR("Bob")

                # Apply the local teleportation operations
                q.cnot(qEPR)
                q.H()

                # Measure the qubits
                a = q.measure()
                b = qEPR.measure()
                to_print = "App {}: Measurement outcomes are: a={}, b={}".format(
                    Alice.name, a, b)
                print("|" + "-" * (len(to_print) + 2) + "|")
                print("| " + to_print + " |")
                print("|" + "-" * (len(to_print) + 2) + "|")

                # Send corrections to other node
                Alice.sendClassical("Bob", [a, b])
                Alice.closeClassicalChannel("Bob")

                # Make an EPR pair with other node
                q = Alice.createEPR("Bob")

                # Receive info about corrections
                data = Alice.recvClassical(timout=3600)
                Alice.closeClassicalServer()
                message = list(data)
                a = message[0]
                b = message[1]

                # Apply corrections
                if b == 1:
                    q.X()
                if a == 1:
                    q.Z()

                    # measure the qubit, print the outcome and record the time it took
            m = q.measure()
            t2 = timer()
            to_print = "App {}: Measurement outcome is: m={}".format(
                Alice.name, m)
            print("|" + "-" * (len(to_print) + 2) + "|")
            print("| " + to_print + " |")
            print("|" + "-" * (len(to_print) + 2) + "|")
            to_print = "App {}: Time elapsed: t={}".format(Alice.name, t2 - t1)
            print("|" + "-" * (len(to_print) + 2) + "|")
            print("| " + to_print + " |")
            print("|" + "-" * (len(to_print) + 2) + "|")

            times.append((n, t2 - t1))

    with open("times{}_{}_{}.txt".format(min_tel, max_tel, number), "a") as f:
        for (n, t) in times:
            f.write("{}, {}\n".format(n, t))

            # Stop the connection
    Alice.close()