-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work on Open Quantum System State Vector started
- Loading branch information
Showing
4 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
||
|
||
|
||
|