Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # Process tomography of a Hadamard gate
  2. q = QuantumRegister(1)
  3. circ = QuantumCircuit(q)
  4. circ.h(q[0])
  5.  
  6. # Run circuit on unitary simulator to find ideal unitary
  7. job = qiskit.execute(circ, Aer.get_backend('unitary_simulator'))
  8. ideal_unitary = job.result().get_unitary(circ)
  9. # convert to Choi-matrix in column-major convention
  10. choi_ideal = outer(ideal_unitary.ravel(order='F'))
  11.  
  12. # Generate process tomography circuits and run on qasm simulator
  13. qpt_circs = process_tomography_circuits(circ, q)
  14. job = qiskit.execute(qpt_circs, Aer.get_backend('qasm_simulator'), shots=4000)
  15.  
  16. # Extract tomography data so that counts are indexed by measurement configuration
  17. qpt_tomo = ProcessTomographyFitter(job.result(), qpt_circs)
  18. qpt_tomo.data
  19.  
  20. choi_lstsq = qpt_tomo.fit(method='lstsq')
  21.  
  22. print('fit fidelity (state):', state_fidelity(choi_ideal / 2, choi_lstsq.data / 2))
  23. print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_lstsq.data, require_cptp=False)))
  24.  
  25. fit fidelity (state): 0.9976767994222256
  26. fit fidelity (process): 0.995358994837865
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement