naive_nb.py 837 B

1234567891011121314151617181920
  1. import numpy as np
  2. def naive_network_benchmarking(network, path_list, bounces, sample_times):
  3. '''Perform vanilla network benchmarking for each path in the `path_list`.
  4. Return a tuple: (a list of fidelities, the total number of bounces).
  5. '''
  6. fidelity = {}
  7. cost = 0
  8. for path in path_list:
  9. p, bounces_num = network.benchmark_path(path, bounces, sample_times)
  10. # fidelity.append(result)
  11. fidelity[path] = p + (1 - p) / 2 # Convert the estimated depolarizing parameter `p` into fidelity
  12. cost += bounces_num
  13. # print("Estimated fidelity:", fidelity)
  14. # best_path = np.argmax(fidelity) + 1
  15. best_path = max(fidelity, key=fidelity.get)
  16. correctness = best_path == network.best_path
  17. best_path_fidelity = fidelity[best_path]
  18. return correctness, cost, best_path_fidelity