Guest User

Untitled

a guest
Jan 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. from qutip import *
  2. import numpy as np
  3. import scipy
  4. import matplotlib.colors
  5. import scipy
  6.  
  7. #the gate
  8. hadamard = qutip.qip.hadamard_transform()
  9. # the hamilton operator describing the evolution during the hadamard gate
  10. hamilton = Qobj(scipy.linalg.logm(hadamard.data.todense()), dims=hadamard.dims) / np.pi * 1.j
  11.  
  12. #create initial state vector
  13. psi0 = (basis(2, 0)).unit()
  14.  
  15. # describing the gate as time evolution
  16. def gate(t):
  17. return (-2*np.pi*1.j*hamilton*t).expm()
  18.  
  19. # hadamard gate for t = 0.5
  20. # In[1]: gate(0.5)
  21. # Out[3]:
  22. # Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = True
  23. # Qobj data =
  24. # [[ 0.70710678 0.70710678]
  25. # [ 0.70710678 -0.70710678]]
  26.  
  27. # evolve the gate
  28. n = 25
  29. psi = [gate(t)*psi0 for t in np.linspace(0, 1., 2*n)]
  30.  
  31. # plotting the states. State evolution during the first hamadard gate is red. During second hadamard gate is blue
  32. b = Bloch()
  33. b.vector_color = [matplotlib.colors.to_rgba('r', alpha=i) for i in np.arange(n)/float(n)] + [matplotlib.colors.to_rgba('b', alpha=i) for i in np.arange(n)/float(n)] + ['black']
  34. b.add_states(psi)
  35. b.add_states([(basis(2,0) + (basis(2,0) + basis(2,1)).unit()).unit()])
  36.  
  37. b.show()
Add Comment
Please, Sign In to add comment