Modules¶
MPI¶
Warning
This module will only operate correctly if called within an MPI instance.
-
class
qsw_mpi.MPI.GKSL(H, Ls, MPI_communicator, taus=None)¶ Bases:
qsw_mpi.MPI.walkGKSLprovides for the simulation of systems obeying the GKSL master equation in its diagonalised form (see Equation (10)).Parameters: - H (\(N \times N\) complex SciPy CSR) – Hamiltonian, \(H\).
- Ls (\(N \times N\) complex SciPy CSR matrix) – Generalised Lindblad operators \(L_k\).
- taus (float array, optional) – Coefficients \(\tau_k\) of the Lindblad operators \(L_k\) (see Equation (11)). If None, \(\tau_k = 1\).
- MPI_communicator – MPI communicator object provided by mpi4py.
Returns: A
walkobject with \(\tilde{\mathcal{L}}\) distributed over an MPI communicator.-
initial_state(state)¶ Sets the initial state \(\rho(t_0)\) and generates \(\tilde{\rho}(t_0)\).
Parameters: state – One of the following:
- \(\rho(t_0)\) as a complex NumPy array.
- \(p(t_0)\). An array describing the diagonal of \(\rho(t_0)\) which is then assumed to have no initial inter-vertex coherences.
- ’mixed’ - Equally distribute \(\rho(t_0)\) over all sites, including specified sources and sinks.
-
set_omega(omega)¶ Re-defines \(\omega\) in the QSW master equation. This requires that \(\tilde{\mathcal{L}}\) be re-built, its communication pattern re-optimised and its one-norm series re-calculated.
Parameters: omega (float) – Interpolation parameter, \(\omega\)
-
class
qsw_mpi.MPI.GQSW(omega, H, Ls, MPI_communicator, H_loc=None, vsets=None)¶ Bases:
qsw_mpi.MPI.walkGQSWprovides for the simulation of G-QSWs and NM-G-QSWs (see Equations (18) or (22)).Parameters: - omega (float) – Interpolation parameter, \(\omega\).
- H (\(\tilde{N} \times \tilde{N}\) SciPy CSR) – Hamiltonian, \(H\).
- Ls (\(\tilde{N} \times \tilde{N}\) SciPy CSR matrix) – Generalised Lindblad operators \(L_k\).
- MPI_communicator – MPI communicator object provided by mpi4py.
- H_loc (\(\tilde{N} \times \tilde{N}\) SciPy CSR, optional) – NM-G-QSW only. Hamiltonian acting in the subspaces of \(V^D\), produced by
nm_H_loc()(see Equation (22)). - vsets (integer lists, optional) – NM-G-QSW only. Set of vertex subspaces \(V^D\) created by
nm_vsets(), see (Equation (22)).
Returns: A
walkobject with a \(\tilde{\mathcal{L}}\) distributed over an MPI communicator.-
gather_populations(root=0)¶ Return \(p(t)\) or \((p(t_0),...,p(t_q))\) following a call to
step()orseries(). In the case of a G-QSW, \(p(t)\) corresponds to the originating graph \(G\) (see Equation (22)).Parameters: root (integer, optional.) – MPI process rank at which to gather \(p(t)\) or \((p(t_0),...,p(t_q))\). Returns: \(p(t)\) or \((p(t_0),...,p(t_q))\). Return type: \(N\), or \((q + 1) \times N\), complex NumPy array.
-
initial_state(state)¶ Sets the initial state \(\rho(t_0)\) and generates \(\tilde{\rho}(t_0)\).
Parameters: state – One of the following:
- \(\rho(t_0)\) as a complex NumPy array.
- \(p(t_0)\). An array describing the diagonal of \(\rho(t_0)\) which is then assumed to have no initial inter-vertex coherences.
- ’mixed’ - Equally distribute \(\rho(t_0)\) over all sites, including specified sources and sinks.
-
save_vsets(filename, vsetsname, action='a')¶ Save \(V^D\) (see Equation (22)) created by
nm_vsets()to a HDF5 file.Parameters: - filename (string) – File basename.
- vsetname (string) – Group/dataset name under which to save \(V^D\).
- action (string) – File access type, append (‘a’), overwrite (‘w’).
-
class
qsw_mpi.MPI.LQSW(omega, H, L, MPI_communicator, sources=(None, None), sinks=(None, None))¶ Bases:
qsw_mpi.MPI.walkDefines an L-QSW, a QSW with locally interacting Lindblad operators, with or without appended sources and sinks (see Equation (13) or (17)).
Parameters: - omega (float) – Interpolation parameter, \(\omega\)
- H (\(N \times N\) SciPy CSR) – Hamiltonian, \(H\)
- L (\(N \times N\) SciPy CSR) – \(M_L = \sum_k L_k\) where the Lindblad operators are defined as in Equation (12).
- MPI_communicator – MPI communicator object provided by mpi4py.
- sources (tuple ([integers],[floats]), optional) – Contains a list of absorption sites and the corresponding absorption rates.
- sinks (tuple ([integers],[floats]), optional) – Contains a list of the emission sites and the corresponding absorption rates.
Returns: A
walkobject with a \(\tilde{\mathcal{L}}\) distributed over an MPI communicator.-
initial_state(state)¶ Sets the initial state, \(\rho(t_0)\). For an
LQSW, this method accepts an additional keyword argument.Parameters: state – One of the following:
- \(\rho(t_0)\) as a complex NumPy array.
- \(p(t_0)\). An array describing the diagonal of \(\rho(t_0)\) which is then assumed to have no initial inter-vertex coherences.
- ’sources’ - Equally distribute \(\rho(t_0)\) over all specified sources.
- ’mixed’ - Equally distribute \(\rho(t_0)\) over all sites, including specified sources and sinks.
-
class
qsw_mpi.MPI.walk¶ Bases:
objectThe
walkclass provides a framework for Lindbladian quantum walk simulation. This proceeds by creating awalksub-class containing a private method with the signature,def _construct_superoperator(self):
which is responsible for defining:
self.SO_nnz (integer): The number of non-zeros in \(\tilde{\mathcal{L}}\)
self.SO_rows (integer): The global number of rows in \(\tilde{\mathcal{L}}\)
self.partition_table (integer array): A 1-based array describing the number of \(\tilde{\mathcal{L}}\) rows per MPI rank.
Example: An evenly distributed \(\tilde{\mathcal{L}}\) with an MPI communicator of size of 4 and self.SO_nnz = 16 would have,self.partition_table = [1,5,9,13,17]where the number of rows at MPI rank i (self.SO_local_rows) is equal to self.partition_table[i + 1] - self.partition_table[i]self.SO_local_rows (integer) the number of \(\tilde{\mathcal{L}}\) stored locally, \(N_\text{local}\).
self.SO_n_row_starts (\(N_\text{local} + 1\) integer NumPy array): Local partition of the 1-based row index pointer array for \(\tilde{\mathcal{L}}\), part of the CSR matrix format.
self.SO_col_indexes (\(N_\text{local}\) integer NumPy array): Local partition of the 1-based column index array for \(\tilde{\mathcal{L}}\), part of the CSR matrix format.
self.SO_values (\(N_\text{local}\) complex NumPy array): Local partition of non-zero values corresponding to self.SO_col_indexes (in 1-based indexing) for \(\tilde{\mathcal{L}}\), part of the CSR matrix format.
self.size (integer tuple): Dimensions of \(\rho(t), H\), Lindblad and other non-vectorised operators.
self.MPI_communicator: MPI communicator object as defined by mpi4py.
self.rank (integer): MPI process rank
_construct_superoperator()must be called in the ‘__init__’ function of thewalksubclass, followed by a call to the __init__ method of the parent class:super().__init__()
The following
walksub-classes are defined in QSW_MPI:LQSW: QSWs with locally interacting Lindbad operators.GQSW: QSWs with globally interacting Lindblad operators (including non-moralising QSWs).GKSL: Quantum walks defined using the diagonal form of the GKSL equation.
-
gather_populations(root=0)¶ Gathers \(p(t)\) or \(((p(t_0),...,p(t_q))\) following execution of
qsw_mpi.MPI.walk.step()orqsw_mpi.MPI.walk.series()at a specified MPI rank. None` is returned elsewhere.Parameters: root (integer) – MPI process rank at which to gather \(p(t)\) or \((p(t_1),...,p(t_q))\). Returns: \(p(t)\) or \((p(t_0),...,p(t_q))\). Return type: \(N\), or \((q + 1) \times N\), complex NumPy array.
-
gather_result(root=0)¶ Gathers \(\rho(t)\) or \((\rho(t_1),...,\rho(t_q))\) following execution of
qsw_mpi.MPI.walk.step()orqsw_mpi.MPI.walk.series()at a specified MPI rank. None is returned elsewhere.Parameters: root (integer) – MPI process rank at which to gather \(\rho(t)\) or \((\rho(t_1),...,\rho(t_q))\). Returns: \(\tilde{N} \times \tilde{N}\) complex NumPy array at root, otherwise None.
-
gather_superoperator(root=0)¶ Gathers \(\tilde{\mathcal{L}}\) to the root MPI process as a SciPy CSR matrix.
Parameters: root (integer) – MPI process rank at which to gather \(\tilde{\mathcal{L}}\). Returns: \(\tilde{\mathcal{L}}\) Return type: \(\tilde{N}^2 \times \tilde{N}^2\) SciPY CSR matrix
-
initial_state(state)¶ Sets the initial state \(\rho(t_0)\) and generates \(\tilde{\rho}(t_0)\).
Parameters: state – One of the following:
- \(\rho(t_0)\) as a complex NumPy array.
- \(p(t_0)\). An array describing the diagonal of \(\rho(t_0)\) which is then assumed to have no initial inter-vertex coherences.
- ’mixed’ - Equally distribute \(\rho(t_0)\) over all sites, including specified sources and sinks.
-
save_populations(filename, popname, action='a')¶ Saves \(p(t)\) or \((p(t_1),...,p(t_q))\) to a HDF5 file.
Parameters: - filename (string) – File basename.
- walkname (string) – Group/dataset name for \(p(t)\) or \((p(t),...,p(t_q))\).
- action – File access type, append (‘a’), overwrite (‘w’).
- action – string
-
save_result(filename, walkname, action='a')¶ Saves \(\rho(t)\) or \(\vec{\rho}(t)\) to a HDF5 file.
Parameters: - filename (string) – File basename.
- walkname (string) – Group/dataset name for \(\rho(t)\) or \(\vec{\rho}(t)\)
- action – File access type, append (‘a’), overwrite (‘w’).
- action – string
-
save_superoperator(filename, operatorname, action='a')¶ Save \(\tilde{\mathcal{L}}\) to a HDF5 file as a CSR matrix.
Parameters: - filename (string) – File basename
- operatorname (string) – Group/dataset name for \(\tilde{\mathcal{L}}\).
- action (string) – File access type, append (‘a’), overwrite (‘w’).
-
series(t1, tq, steps, precision='dp')¶ Calculate \(\rho(t)\) over \([t_1, t_q]\) (where \(t_q > t_1\)) at \(q\) evenly spaced steps with \(\Delta t = \frac{t_q - t_1}{q}\). This is done via an implementation of Algorithm 5.2 (without optional balancing or minimisation of the Frobenius norm) as detailed in:
- Al-Mohy and N. Higham, SIAM Journal on Scientific Computing 33, 488 (2011).
Parameters: - t1 (float) – Starting time, \(t_1\).
- tq (float) – Ending time, \(t_q\).
- steps (integer) – \(q\).
- precision (string, optional) – Target precision, accepts “sp” for single precision and “dp” for double precision. Defaults to “dp”.
Note
To gather or save \((\rho(t_0),...,\rho(t_q))\) or \((p(t_0),...,p(t_0))\):
-
set_omega(omega)¶ Re-defines \(\omega\) in the QSW master equation. This requires that \(\tilde{\mathcal{L}}\) be re-built, its communication pattern re-optimised and its one-norm series re-calculated.
Parameters: omega (float) – Interpolation parameter, \(\omega\)
-
step(t, precision='dp')¶ Calculate \(\rho(t)\). This is done via an implementation of Algorithm 3.2 (without optional balancing or minimisation of the Frobenius norm) as detailed in:
- Al-Mohy and N. Higham, SIAM Journal on Scientific Computing 33, 488 (2011).
Parameters: - t (float) – time, \(t\).
- precision (string, optional) – Target precision, accepts “sp” for single precision and “dp” for double precision.
Note
To gather or save \(\rho(t)\) or \(p(t)\):
operators¶
-
qsw_mpi.operators.check_indices(G)¶ Ensure that as SciPY CSR matrix has column ordered indices and data arrays.
Parameters: G – SciPy CSR matrix
-
qsw_mpi.operators.import_superoperator(File, operatorname)¶ Import a \(\tilde{\mathcal{L}}\) from a HDF5 file.
Note
This method does not distrubted \(\tilde{\mathcal{L}}\).
Parameters: - File – H5Py
Fileobject. - operatorname (string) – Group containing the \(\tilde{\mathcal{L}}\) CSR arrays.
Returns: Superoperator, \(\tilde{\mathcal{L}}\).
Return type: \(\tilde{N}^2 \times \tilde{N}^2\) SciPy CSR matrix
- File – H5Py
-
qsw_mpi.operators.import_vsets(File, vsetsname)¶ Import \(V^D\) (see Step 1 of the demoralisation procedure) from a HDF5 file.
Parameters: File – H5Py Fileobject.Returns: Vertex subspaces, \(V^D\). Return type: integer arrays
-
qsw_mpi.operators.local_lindblads(G)¶ Generate a Lindblad operator matrix from a graph transition matrix or adjacency matrix for use with the
LQSWclass (see Equation (15)).Parameters: G (\(N \times N\) SciPy CSR matrix) – Adjacency matrix \(G\). Return L: \(M_L\). Return type: \(N \times N\) SciPy CSR matrix
-
qsw_mpi.operators.markov_chain(G)¶ Generate the cannonical Markov chain transition matrix (see Equation (14)) of a CSR adjacency matrix for use with the
LQSWclass (see Equation (15)).Parameters: G (\(N \times N\) SciPy CSR matrix.) – Adjacency matrix, \(G\). Returns: The cannonical Markov chain transition matrix of \(G\), \(C\). Return type: \(N \times N\) SciPy CSR matrix
-
qsw_mpi.operators.nm_G(G, vsets)¶ Returns the demoralised graph \(G^D\), as per step 2 of the graph demoralisation procedure.
Parameters: - G (\(N \times N\) SciPy CSR matrix) – Adjacency matrix, \(G\).
- vsets (integer arrays) – Vertex subspaces, \(V^D\), generated via
nm_vsets().
Returns: The demoralised graph, \(G^D\).
Return type: \(\tilde{N} \times \tilde{N}\) SciPy CSR matrix
-
qsw_mpi.operators.nm_H_loc(vsets)¶ Returns the locally rotating Hamiltonian, \(H_\text{loc}\), as per step 4 of the graph demoralised procedure.
Parameters: vsets (integer arrays) – Vertex subspaces, \(V^D\), generated via nm_vsets().Returns: The locally rotating Hamiltonian, \(H_\text{loc}\). Return type: \(\tilde{N} \times \tilde{N}\) SciPy CSR matrix
-
qsw_mpi.operators.nm_L(G, vsets, perm_i=0)¶ Returns a global Lindblad operator, \(L^D\), capable of generating a non-moralising QSW, as per step 3 of the demoralisation procedure.
Parameters: - G (\(N \times N\) SciPy CSR matrix) – Adjacency matrix, \(G\).
- vsets (integer arrays) – Vertex subspaces, \(V^D\), generated via
nm_vsets(). - perm_i (integer, optional) – Use the \(i^\text{th}\) permutation of the Fourier matrices to orthogonalise the vertex subspaces of \(L^D\).
Returns: A demoralised global Lindblad operator, \(L^D\).
Return type: \(\tilde{N} \times \tilde{N}\) SciPy CSR matrix
-
qsw_mpi.operators.nm_measure(rho, vsets)¶ Maps the vertex populations of \(\rho^D(t)\) or \((\rho^D(t_0),...,\rho^D(t_q))\) to \(p(t)\) or \((p(t_0),...,p(t_q))\) (see Equation (23)).
Parameters: - rho – \(\rho^D(t)\) or \((\rho^D(t_0),...,\rho^D(t_q))\).
- vsets (integer arrays) – Vertex subspaces, \(V^D\), generated via
nm_vsets().
Returns: \(p(t)\) or \((p(t_0),...,p(t_q))\).
Return type: \(N \times N\) or \(q \times N \times N\) NumPy complex array.
-
qsw_mpi.operators.nm_pop_inv_map(populations, vsets)¶ Maps the vertex populations of \(\rho^D(t)\) to \(\rho(t)\) (see Equation (23)) given \(p^D(t)\) or \((p^D(t_0),...,p^D(t_q))\).
Parameters: - rho – Vertex populations, \(p^D(t)\) or \((p^D(t_0),...,p^D(t_q))\).
- vsets (integer arrays) – Vertex subspaces, \(V^D\), generated via
nm_vsets().
Returns: \(p(t)\) or \((p(t_0),...,p(t_q))\).
Return type: \(N \times N\) or \(q \times N \times N\) NumPy complex array.
-
qsw_mpi.operators.nm_rho_map(probs, vsets)¶ Maps the vertex populations, \(p(t_0)\), of a QSW on graph \(G\), to the corresponding vertex subspaces of the demoralised graph, \(G^D\) (see Equation (23)).
Parameters: - probs (\(1 \times N\) float array) – Vertex populations of \(\rho(t_0)\).
- vsets (integer arrays) – Vertex subspaces, \(V^D\), generated via
nm_vsets().
Returns: Density operator, \(\rho^D(t_0)\)
Return type: \(\tilde{N} \times \tilde{N}\) SciPy CSR matrix
-
qsw_mpi.operators.nm_vsets(G)¶ Creates vertex subspaces, \(V^D\), as per Step 1 of the graph demoralisation procedure.
Parameters: G (\(N \times N\) SciPy CSR matrix) – Adjacency matrix, \(G\). Returns: Vertex subspaces, \(V^D\). Return type: integer arrays
-
qsw_mpi.operators.symmetrise(G)¶ Symmetrise a CSR matrix with a symmetric structure.
G is altered so as to satisfy \(G_{ij} = max(G_{ij}, G_{ji})\).
Parameters: G (SciPy real CSR matrix.) – CSR matrix to symmetrise. Warning
The matrix must be structurally symmetric in terms of its non-zero entires.
-
qsw_mpi.operators.transition(gamma, G)¶ Generate the graph transition matrix (see Equation (5)) from a CSR adjacency matrix.
Parameters: - gamma (float) – Transition rate, \(\gamma\).
- G (\(N \times N\) SciPy CSR matrix) – Adjacency matrix, \(G\).
Returns: The transition matrix of \(G\), \(M\)
Return type: \(N \times N\) SciPy CSR matrix