Quick StartΒΆ

A basic template of a distributed CNOT gate between two different computing hosts is shown in the file examples/template.py, where the control qubit in first computing host is set in |1> state and the target qubit in the second computing host is set in |0> state.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
 def create_circuit(q_map):
     layers = []
     computing_host_ids = list(q_map.keys())

     # Prepare the qubits on both computing hosts
     ops = []
     for host_id in computing_host_ids:
         op = Operation(
             name=Constants.PREPARE_QUBITS,
             qids=q_map[host_id],
             computing_host_ids=[host_id])
         ops.append(op)
     layers.append(Layer(ops))

     # Circuit input should be added below
     # Put qubit "q_0_0" in |1> state
     op = Operation(
         name=Constants.SINGLE,
         qids=[q_map[computing_host_ids[0]][0]],
         gate=Operation.X,
         computing_host_ids=[computing_host_ids[0]])
     ops.append(op)
     layers.append(Layer(ops))

     # Apply cnot gate from "q_0_0" to "q_1_0"
     control_qubit_id = q_map[computing_host_ids[0]][0]
     target_qubit_id = q_map[computing_host_ids[1]][0]

     op = Operation(
         name=Constants.TWO_QUBIT,
         qids=[control_qubit_id, target_qubit_id],
         gate=Operation.CNOT,
         computing_host_ids=computing_host_ids)
     layers.append(Layer([op]))

     # Measure the qubits
     ops = []
     for host_id in computing_host_ids:
         op = Operation(
             name=Constants.MEASURE,
             qids=[q_map[host_id][0]],
             cids=[q_map[host_id][0]],
             computing_host_ids=[host_id])
         ops.append(op)
     layers.append(Layer(ops))

     circuit = Circuit(q_map, layers)
     return circuit

 def controller_host_protocol(host, q_map):
     """
     Protocol for the controller host
     """
     circuit = create_circuit(q_map)
     host.generate_and_send_schedules(circuit)
     host.receive_results()

     results = host.results
     computing_host_ids = host.computing_host_ids

     print('Final results: \n')
     for computing_host_id in computing_host_ids:
         bits = results[computing_host_id]['bits']
         for bit_id, bit in bits.items():
             print("{0}: {1}".format(bit_id, bit))

 def computing_host_protocol(host):
     """
     Protocol for the computing hosts
     """
     host.receive_schedule()
     host.send_results()

 def main():
     # initialize network
     network = Network.get_instance()
     network.start()

     clock = Clock()
     controller_host = ControllerHost(host_id="host_1", clock=clock)

     # Here the number of computing hosts and number of qubits per computing hosts
     # can be customised
     computing_hosts, q_map = controller_host.create_distributed_network(
         num_computing_hosts=2,
         num_qubits_per_host=2)
     controller_host.start()

     network.add_host(controller_host)
     for host in computing_hosts:
         network.add_host(host)

     print('starting...')
     t = controller_host.run_protocol(controller_host_protocol, (q_map,))
     threads = [t]
     for host in computing_hosts:
         t = host.run_protocol(computing_host_protocol)
         threads.append(t)

     for thread in threads:
         thread.join()
     network.stop(True)
     exit()

 if __name__ == '__main__':
     main()