Giter VIP home page Giter VIP logo

aisim's Introduction

PyPI Conda Test Status Test Coverage Documentation Status Code style: black

AISim ‒ Simulations for light-pulse atom interferometry

AISim is a Python package for simulating light-pulse atom interferometers.

It uses dedicated objects to model the laser beams, the atomic ensemble and the detection system and store experimental parameters in a neat way. After you define these objects you can use built-in propagators to simulate internal and external degrees of freedom of cold atoms.

Installation

The latest tagged release can installed via pip with

pip install aisim

or via conda with

conda install -c conda-forge aisim 

Alternatively, if you plan to make changes to the code, use

git clone https://github.com/bleykauf/aisim.git
cd aisim
python setup.py develop

Usage

For basic usage and code reference, see the documentation.

Examples

Some examples are provided in the form of Jupyter notebooks:

Contributing

Contributions are very welcome. If you want to help, check out our contributions guide.

Authors

License

AISim ‒ Simulations for light-pulse atom interferometry

Copyright © 2023 B. Leykauf, S. Vowe

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

aisim's People

Contributors

bleykauf avatar dependabot[bot] avatar github-actions[bot] avatar pre-commit-ci[bot] avatar savowe avatar synapticarbors avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

aisim's Issues

propagator in transition method is not unitary if delta is not zero

the propagator matrix U is not generally time-reversable, meaning
U(tau)*U(-tau) \neq 1
It is right now only 1, if the two-photon detuning delta is zero. This means that it proably has something to do with it.
Maybe the formula is wrong?
Example:

import numpy as np
import matplotlib.pyplot as plt
import aisim as ais

pos_params = {
     'mean_x': 0.0,
     'std_x' : 3.0e-3, # cloud radius in m
     'mean_y': 0.0,
     'std_y' : 3.0e-3, # cloud radius in m
     'mean_z': 0.0,
     'std_z' : 0,        # ignore z dimension, its not relevant here
}
vel_params = {
     'mean_vx': 0.0,
     'std_vx' : ais.convert.vel_from_temp(3.0e-6), # cloud velocity spread in m/s at tempearture of 3 uK
     'mean_vy': 0.0,
     'std_vy' : ais.convert.vel_from_temp(3.0e-6), # cloud velocity spread in m/s at tempearture of 3 uK
     'mean_vz': 0.0,
     'std_vz' : ais.convert.vel_from_temp(0*.2e-6),       
}

print(ais.__version__)

atoms = ais.create_random_ensemble_from_gaussian_distribution(pos_params, vel_params, int(1e4))

center_Rabi_freq = 2*np.pi*12.5e3
r_beam = 29.5e-3 / 2 # 1/e^2 beam radius in m
intensity_profile = ais.IntensityProfile(r_beam, center_Rabi_freq)
wave_vectors = ais.Wavevectors( k1 = 8.052945514e6, k2 = -8.052802263e6)

Omega_eff = intensity_profile.get_rabi_freq(atoms.position)

phase = 0

delta = wave_vectors.doppler_shift(atoms)

# calculate Rabi frequency
Omega_R = np.sqrt(Omega_eff**2 + delta**2)
# beginning of pulse t0
t0 = atoms.time

tau = 20e-6
# calculate matrix elements
sin_theta = Omega_eff/Omega_R
cos_theta = -delta/Omega_R

U_ee = np.cos(Omega_R * tau / 2) - 1j * \
    cos_theta * np.sin(Omega_R * tau / 2)
U_ee *= np.exp(-1j * delta * tau/2)

U_eg = np.exp(-1j * (delta*t0 + phase)) * -1j * \
    sin_theta * np.sin(Omega_R * tau / 2)
U_eg *= np.exp(-1j * delta * tau/2)

U_ge = np.exp(+1j * (delta*t0 + phase)) * -1j * \
    sin_theta * np.sin(Omega_R * tau / 2)
U_ge *= np.exp(1j * delta * tau/2)

U_gg = np.cos(Omega_R * tau / 2) + 1j * \
    cos_theta * np.sin(Omega_R * tau / 2)
U_gg *= np.exp(1j * delta * tau/2)

propagator = np.array([[U_ee, U_eg], [U_ge, U_gg]], dtype='complex')
propagator = np.transpose(propagator, (2, 0, 1))
prop1 = propagator

tau = -tau
# calculate matrix elements
sin_theta = Omega_eff/Omega_R
cos_theta = -delta/Omega_R

U_ee = np.cos(Omega_R * tau / 2) - 1j * \
    cos_theta * np.sin(Omega_R * tau / 2)
U_ee *= np.exp(-1j * delta * tau/2)

U_eg = np.exp(-1j * (delta*t0 + phase)) * -1j * \
    sin_theta * np.sin(Omega_R * tau / 2)
U_eg *= np.exp(-1j * delta * tau/2)

U_ge = np.exp(+1j * (delta*t0 + phase)) * -1j * \
    sin_theta * np.sin(Omega_R * tau / 2)
U_ge *= np.exp(1j * delta * tau/2)

U_gg = np.cos(Omega_R * tau / 2) + 1j * \
    cos_theta * np.sin(Omega_R * tau / 2)
U_gg *= np.exp(1j * delta * tau/2)

propagator = np.array([[U_ee, U_eg], [U_ge, U_gg]], dtype='complex')
propagator = np.transpose(propagator, (2, 0, 1))
prop2 = propagator

print(np.matmul(prop1,prop2))

Cannot select a single atom from AtomicEnsemble with __getitem__

This fails:

pos_params = {
    'mean_x': 0.0,
    'std_x': 3.0e-3,  # cloud radius in m
    'mean_y': 0.0,
    'std_y': 3.0e-3,  # cloud radius in m
    'mean_z': 0.0,
    'std_z': 0,        # ignore z dimension, its not relevant here
}
vel_params = {
    'mean_vx': 0.0,
    # cloud velocity spread in m/s at tempearture of 3 uK
    'std_vx': ais.convert.vel_from_temp(3.0e-6),
    'mean_vy': 0.0,
    # cloud velocity spread in m/s at tempearture of 3 uK
    'std_vy': ais.convert.vel_from_temp(3.0e-6),
    'mean_vz': 0.0,
    'std_vz': ais.convert.vel_from_temp(0),
}

atoms = ais.create_random_ensemble_from_gaussian_distribution(
    pos_params, vel_params, int(1e4), state_kets=[1, 0, 0, 0])

atoms[0]

with

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-16-72aa0f35cda1> in <module>
----> 1 atoms[0]

c:\users\bastian\documents\programming\aisim\aisim\atoms.py in __getitem__(self, key)
     80             phase_space_vectors=self.phase_space_vectors[key][:],
     81             state_kets=self.state_kets[key][:],
---> 82             weights=self.weights[key])
     83         return new_instance
     84 

c:\users\bastian\documents\programming\aisim\aisim\atoms.py in __init__(self, phase_space_vectors, state_kets, time, weights)
     49     def __init__(self, phase_space_vectors, state_kets=[1, 0], time=0,
     50                  weights=None):
---> 51         assert phase_space_vectors.shape[1] == 6
     52         self.phase_space_vectors = phase_space_vectors
     53         self.state_kets = state_kets

IndexError: tuple index out of range

but

atoms[0:1]

works.

Building RTD documentation fails

RTD fails with

 python /home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/bin/sphinx-build -T -b readthedocs -d _build/doctrees-readthedocs -D language=en . _build/html
Running Sphinx v1.8.5
loading translations [en]... done

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/sphinx/cmd/build.py", line 303, in build_main
    args.tags, args.verbosity, args.jobs, args.keep_going)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/sphinx/application.py", line 228, in __init__
    self.setup_extension(extension)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/sphinx/application.py", line 449, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/sphinx/registry.py", line 472, in load_extension
    mod = __import__(extname, None, None, ['setup'])
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/nbsphinx.py", line 41, in <module>
    import nbconvert
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/nbconvert/__init__.py", line 4, in <module>
    from .exporters import *
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/nbconvert/exporters/__init__.py", line 4, in <module>
    from .slides import SlidesExporter
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/nbconvert/exporters/slides.py", line 12, in <module>
    from ..preprocessors.base import Preprocessor
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/nbconvert/preprocessors/__init__.py", line 7, in <module>
    from .csshtmlheader import CSSHTMLHeaderPreprocessor
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/nbconvert/preprocessors/csshtmlheader.py", line 14, in <module>
    from jupyterlab_pygments import JupyterStyle
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/jupyterlab_pygments/__init__.py", line 4, in <module>
    from .style import JupyterStyle
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/jupyterlab_pygments/style.py", line 10, in <module>
    class JupyterStyle(Style):
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/pygments/style.py", line 101, in __new__
    ndef[0] = colorformat(styledef)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/pygments/style.py", line 58, in colorformat
    assert False, "wrong color format %r" % text
AssertionError: wrong color format 'var(--jp-mirror-editor-variable-color)'

Exception occurred:
  File "/home/docs/checkouts/readthedocs.org/user_builds/aisim/envs/fix_docs/lib/python3.7/site-packages/pygments/style.py", line 58, in colorformat
    assert False, "wrong color format %r" % text
AssertionError: wrong color format 'var(--jp-mirror-editor-variable-color)'
The full traceback has been saved in /tmp/sphinx-err-_xoeql76.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks! 

Use fixtures in tests

At the moment a lot of tests generate objects like AtomicEnsemble, Wavefront etc.

Readability could be improved by using fixtures.

propagate method in prop class not time symmetric

def propagate(self, atoms):

The propagate method is not time symmetric and therefore not unitary if internal and free propagators are combined.
We should change the propagate method from
freeprop(Delta t) -> internalprop(Delta t)
to
freeprop(Delta t/2) -> internalprop(Delta t) -> ifreeprop(Delta t/2)

More tests

We should make tests for testing the internal structure of the modules.
My first two cents for tests of the AtomicEnsemble class:

N_atom = 1000
N_ints = [2, 3, 5, 10, 20, 100]
for N_int in N_ints:
    print(N_int)
    # Generate random states
    random_phase_space_vectors = np.random.rand(N_atom, 6)
    random_kets = np.random.rand(N_atom, N_int)
    # normalize random ket
    norm = np.einsum('ij,ij->i', random_kets, random_kets)
    norm_random_kets = np.einsum('ij,i->ij', random_kets, 1/norm**(1/2))
    # apply random phase shifts
    random_phases = 2*np.pi*np.random.rand(N_atom, N_int)
    norm_random_kets = np.exp(1j*random_phases) * norm_random_kets
    norm_random_kets = np.reshape(norm_random_kets, (N_atom, N_int, 1))
    random_atoms = ais.AtomicEnsemble(
        random_phase_space_vectors, norm_random_kets)
    # Testing AtomicEnsemble properties
    # Test duality of Kets and Bras
    np.testing.assert_array_almost_equal(random_atoms.state_kets, np.conjugate(
        np.transpose(random_atoms.state_bras, (0, 2, 1))))
    # Test whether the trace of every density matrix is equal to one
    np.testing.assert_almost_equal(
        np.trace(random_atoms.density_matrices, axis1=1, axis2=2), 1)
    # Test whether every single atoms density matrix satisfies rho^2 = rho (condition for pure states)
    np.testing.assert_array_almost_equal(np.matmul(
        random_atoms.density_matrices, random_atoms.density_matrices), random_atoms.density_matrices)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.