Skip to content

Commit

Permalink
Work on Open Quantum System State Vector started
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancal74 committed Jan 10, 2024
1 parent afb4362 commit bff053b
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 1 deletion.
6 changes: 5 additions & 1 deletion quantarhei/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,13 @@


#
# Operators
# State vectors
#
from .qm import StateVector
from .qm import OQSStateVector
#
# Operators
#
from .qm import DensityMatrix
from .qm import ReducedDensityMatrix
from .qm import BasisReferenceOperator
Expand Down
1 change: 1 addition & 0 deletions quantarhei/qm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# HILBERT SPACE STATES
#
from .hilbertspace.statevector import StateVector
from .hilbertspace.oqsstatevector import OQSStateVector

#
# LIOUVILLE SPACE STATES
Expand Down
81 changes: 81 additions & 0 deletions quantarhei/qm/hilbertspace/oqsstatevector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
"""
State vector of the open quantum system
"""
import numpy

from ... import REAL, COMPLEX

class OQSStateVector():
"""Represents a quantum mechanical state of an open system
In this representation we keep state vector coefficients separate
from the state of the bath representation.
Parameters
----------
Examples
--------
>>> psi = OQSStateVector(2)
>>> print(psi.dim)
2
>>> vec = numpy.zeros((1,3), dtype=REAL)
>>> psi = OQSStateVector(data=vec)
Traceback (most recent call last):
...
Exception: Data has to be a vector
"""


def __init__(self, dim=None, data=None):

self._initialited = False

if data is not None:

ddat = numpy.array(data)

if len(ddat.shape) > 1:
raise Exception("Data has to be a vector")

if dim != ddat.shape[0]:
print("Dimension specification differes from data: ignored.")

self.data = ddat
self.dim = ddat.shape[0]
self._initialited = True

elif dim is not None:

self.dim = dim
self.data = numpy.zeros(self.dim, dtype=REAL)
self._initialited = True


def norm(self):
"""Norm of the state vector
"""

return numpy.dot(self.data,self.data)


def puredot(self, psi):
"""Dot product concerning only the system part
"""

return numpy.dot(self.data, psi.data)


68 changes: 68 additions & 0 deletions tests/unit/qm/hilbertspace/oqsstatevector_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
import unittest


"""
*******************************************************************************
Tests of the quantarhei.qm.hilbertspace.oqsstatevector package
*******************************************************************************
"""

from quantarhei import OQSStateVector
from quantarhei import REAL

class TestOQSStateVector(unittest.TestCase):
"""Tests for the statevector package
"""

def test_of_state_vector_creation(self):
"""Testing StateVector creation """

psi = OQSStateVector(3)

self.assertEqual(psi.dim,3)

psi = OQSStateVector()

self.assertFalse(psi._initialized)



def test_of_sv_creation_from_data(self):
"""Testing StateVector creation with data"""

import numpy

vec = numpy.zeros((1,3), dtype=REAL)

with self.assertRaises(Exception):
psi = OQSStateVector(data=vec)

vec = numpy.zeros(3, dtype=REAL)
psi = OQSStateVector(data=vec)

self.assertEqual(psi.dim,3)


def test_creation_from_list(self):
"""Tests creation from non numpy array """
import numpy

vec = [0.1, 2.0, 0.0]

psi = OQSStateVector(data = vec)

self.assertAlmostEqual(psi.norm(), numpy.sqrt(0.1**2 + 4.0))
self.assertAlmostEqual(psi.puredot(psi), psi.norm()**2)






0 comments on commit bff053b

Please sign in to comment.