-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.py
39 lines (35 loc) · 1.4 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Functions for accessing and manipulating adjoint eigenvectors
"""
import numpy as np
def set_state_adjoint(self, index, subsystem):
"""
Set state vector to the specified eigenmode.
Parameters
----------
index : int
Index of desired eigenmode.
subsystem : Subsystem object or int
Subsystem that will be set to the corresponding eigenmode.
If an integer, the corresponding subsystem of the last specified
eigenvalue_subproblem will be used.
"""
# TODO: allow setting left modified eigenvectors?
subproblem = self.eigenvalue_subproblem
if isinstance(subsystem, int):
subsystem = subproblem.subsystems[subsystem]
# Check selection
if subsystem not in subproblem.subsystems:
raise ValueError("subsystem must be in eigenvalue_subproblem")
# Set coefficients
for var in self.state:
var['c'] = 0
subsystem.scatter(self.modified_left_eigenvectors[:, index], self.state)
def _build_modified_left_eigenvectors(self):
sp = self.eigenvalue_subproblem
return (sp.M_min @ sp.pre_right_pinv)[email protected][email protected]_eigenvectors
def _normalize_left_eigenvectors(self):
modified_left_eigenvectors = _build_modified_left_eigenvectors(self)
norms = np.diag(modified_left_eigenvectors.T.conj() @ self.eigenvectors)
self.left_eigenvectors /= np.conj(norms)
self.modified_left_eigenvectors /= np.conj(norms)