Advertisement
Guest User

arrayintg_toy.py

a guest
Nov 5th, 2010
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ##
  4. # arrayintg_toy.py: Toy program to illustrate problems integrating an array with SciPy.
  5. ##
  6. # © 2010 Christopher E. Granade (cgranade@gmail.com).
  7. # Licensed under the GPL version 2.
  8. ##
  9. # This library is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU Lesser General Public
  11. # License as published by the Free Software Foundation; either
  12. # version 2.1 of the License, or (at your option) any later version.
  13. #
  14. # This library is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. # Lesser General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Lesser General Public
  20. # License along with this library; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  22. ##
  23.  
  24. ## IMPORTS #####################################################################
  25.  
  26. import math as m
  27. import numpy as np
  28. import scipy.linalg.matfuncs as mf
  29.  
  30. import scipy.integrate
  31.  
  32. ## CONSTANTS ###################################################################
  33.  
  34. ## OTHER ##
  35. I = 1j
  36.  
  37. ## COMMON MATRICES ##
  38. Id = np.array([[1,0],[0,1]])
  39. sX = np.array([[0,1],[1,0]])
  40. sY = np.array([[0,-I],[I,0]])
  41. sZ = np.array([[1,0],[0,-1]])
  42.  
  43. Ep = np.array([[1,0],[0,0]])
  44. Em = np.array([[0,0],[0,1]])
  45. sp = np.array([[0,1],[0,0]])
  46. sm = np.array([[0,0],[1,0]])
  47.  
  48. ## FUNCTIONS ###################################################################
  49.  
  50. def propagator(H, t):
  51.     return mf.expm(-I * t * H)
  52.    
  53. def interaction_frame(H0, Hint, t):    
  54.     return reduce(np.dot,[
  55.         propagator(Hint, t),
  56.         H0,
  57.         propagator(Hint, -t)
  58.     ])
  59.  
  60. def H0(omega):
  61.     return omega * np.kron(sZ, sZ)
  62.  
  63. ## MAIN ########################################################################
  64.  
  65. if __name__ == "__main__":
  66.    
  67.     wz =  100.0
  68.     wt = 1000.0
  69.    
  70.     H_cycle = (m.pi / wt) * scipy.integrate.romberg(
  71.        lambda t: interaction_frame(
  72.             H0(wz),
  73.             wt * (np.kron(sX, Id) + np.kron(Id, sX)),
  74.             t
  75.         ),
  76.         0, m.pi / wt
  77.     )
  78.  
  79.     print H_cycle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement