Open Systems Module
Overview
In this section, we outline the main functionality of the open_systems
module.
First, we will provide some conceptual explanations that provide the user with a necessary background to understand the code. Then we provide some illustrative examples that demonstrate how the code can be used. Finally, we provide the source code as an API reference to the source code.
Concepts
In this section, we can add some theoretical background/explanation of relevant concepts.
Examples
In this section, we can add some illustrative examples.
Source Code
qflux.open_systems
DynamicsOS
Class for open-system dynamics (Lindblad equation).
This class provides methods to simulate open-system dynamics described by the Lindblad equation.
Attributes:
Name | Type | Description |
---|---|---|
Nsys |
int
|
System Hilbert Space Dimension. |
Hsys |
ndarray
|
Hamiltonian of the system (shape (N, N)). |
rho0 |
ndarray
|
Initial density matrix (shape (N, N)). |
c_ops |
List[ndarray]
|
List of collapse operators (each of shape (N, N)). |
Source code in src/qflux/open_systems/numerical_methods.py
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
Gt_matrix_expo(time_arr, Is_show_step=False)
Compute the propagator of the Lindblad equation using the matrix exponential.
The propagator is computed by exponentiating the Liouvillian operator defined by the system Hamiltonian and collapse operators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_arr
|
List[float]
|
Array of time values for the simulation. |
required |
Is_show_step
|
bool
|
If True, prints the current simulation step. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
List[ndarray]
|
List[np.ndarray]: List of propagators corresponding to each time in |
Source code in src/qflux/open_systems/numerical_methods.py
__init__(Nsys, Hsys, rho0, c_ops=None)
Initialize the DynamicsOS instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Nsys
|
int
|
System Hilbert Space Dimension. |
required |
Hsys
|
ndarray
|
Hamiltonian of the system. |
required |
rho0
|
ndarray
|
Initial density matrix. |
required |
c_ops
|
Optional[List[ndarray]]
|
List of collapse operators. Defaults to an empty list. |
None
|
Source code in src/qflux/open_systems/numerical_methods.py
propagate_matrix_exp(time_arr, observable, Is_store_state=False, Is_show_step=False, Is_Gt=False)
Solve the Lindblad equation using matrix exponential.
This method computes the propagator, evolves the initial density matrix, and calculates the expectation value of the observable over time. Optionally, it stores the evolved density matrices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_arr
|
List[float]
|
Time array for dynamic simulation. |
required |
observable
|
ndarray
|
Observable matrix for which the expectation value is computed. |
required |
Is_store_state
|
bool
|
If True, stores the density matrices at each time step. Defaults to False. |
False
|
Is_show_step
|
bool
|
If True, prints the current simulation step. Defaults to False. |
False
|
Is_Gt
|
bool
|
If True, includes the propagators in the result. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Result |
Any
|
An object with the following attributes:
- expect (List[float]): List of expectation values over time.
- density_matrix (List[np.ndarray], optional): List of density matrices (if |
Source code in src/qflux/open_systems/numerical_methods.py
propagate_qt(time_arr, observable, **kwargs)
Propagate the system using QuTiP's mesolve
function.
This method solves the Lindblad master equation using QuTiP's mesolve
to compute the expectation
values of the observable over time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_arr
|
List[float]
|
Time array for dynamic simulation. |
required |
observable
|
Any
|
Observable operator(s) for which the expectation value is computed. Can be a single operator or a list of operators. |
required |
**kwargs
|
Any
|
Additional keyword arguments to pass to |
{}
|
Returns:
Type | Description |
---|---|
List[float]
|
List[float]: List of expectation values of the observable over time. |
Source code in src/qflux/open_systems/numerical_methods.py
QubitDynamicsOS
Bases: DynamicsOS
Class for simulating quantum dynamics using either vectorized density matrix or Kraus operator representations.
This class provides methods to initialize state vectors, construct quantum circuits, and perform quantum simulations using Qiskit backends.
Source code in src/qflux/open_systems/quantum_simulation.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
__init__(rep='Density', **kwargs)
Initialize a QubitDynamicsOS instance.
Depending on the representation, either "Density" or "Kraus", the number of qubits is computed. Additional keyword arguments are passed to the base DynamicsOS class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rep
|
str
|
Representation type, either 'Density' or 'Kraus'. Defaults to 'Density'. |
'Density'
|
**kwargs
|
Any
|
Additional keyword arguments for the DynamicsOS initializer. |
{}
|
Source code in src/qflux/open_systems/quantum_simulation.py
_create_circuit(array, statevec, Isscale=True)
Construct and return the quantum circuit.
This method wraps the call to the dilation circuit construction function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array
|
ndarray
|
Array used for circuit construction (e.g., propagator or Kraus operator). |
required |
statevec
|
Union[ndarray, List[ndarray]]
|
State vector(s) to be used in the circuit. |
required |
Isscale
|
bool
|
Flag indicating whether scaling should be applied. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
QuantumCircuit |
QuantumCircuit
|
The constructed quantum circuit. |
Source code in src/qflux/open_systems/quantum_simulation.py
_get_qiskit_observable(Isdilate=False, tol=0.005)
Prepare and return the Qiskit observable operator.
Converts the observable matrix to its Pauli representation and returns a SparsePauliOp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Isdilate
|
bool
|
Flag indicating whether to use the dilated observable. Defaults to False. |
False
|
tol
|
float
|
Tolerance for the Pauli decomposition. Defaults to 5e-3. |
0.005
|
Returns:
Name | Type | Description |
---|---|---|
SparsePauliOp |
SparsePauliOp
|
The Qiskit representation of the observable. |
Source code in src/qflux/open_systems/quantum_simulation.py
init_statevec_Kraus(tol=1e-06)
Initialize state vectors from the initial density operator using the Kraus operator representation.
The density matrix is decomposed using eigenvalue decomposition, and eigenstates with eigenvalues below the specified tolerance are ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tol
|
float
|
Tolerance for ignoring eigenstates with small eigenvalues. Defaults to 1e-6. |
1e-06
|
Returns:
Type | Description |
---|---|
List[ndarray]
|
Tuple[List[np.ndarray], List[float]]: A tuple containing a list of state vectors and a list of |
List[float]
|
corresponding probabilities. |
Source code in src/qflux/open_systems/quantum_simulation.py
init_statevec_vecdens()
Initialize the state vector from the initial density operator using vectorized representation.
The initial density matrix is reshaped into a vector and normalized.
Returns:
Type | Description |
---|---|
ndarray
|
Tuple[np.ndarray, float]: A tuple containing the normalized state vector and the norm |
float
|
of the original vectorized density matrix. |
Source code in src/qflux/open_systems/quantum_simulation.py
qc_simulation_kraus(time_arr, shots=1024, Kraus=None, Gprop=None, tolk=1e-05, tolo=1e-05, **kwargs)
Perform quantum simulation using the Kraus operator representation.
This method simulates the quantum system dynamics over a series of time steps using a Kraus operator-based approach. It constructs quantum circuits for each Kraus operator and initial state, runs the simulation using Qiskit's Estimator, and accumulates the measurement results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_arr
|
List[float]
|
List of time steps for simulation. |
required |
shots
|
int
|
Number of shots for each measurement. Defaults to 1024. |
1024
|
Kraus
|
Optional[Dict[int, List[ndarray]]]
|
Dictionary mapping time step index to a list of Kraus operators. If None, Kraus operators are generated from the propagator. Defaults to None. |
None
|
Gprop
|
Optional[List[ndarray]]
|
Propagator matrix (or list of matrices) for simulation. If None, it will be calculated. Defaults to None. |
None
|
tolk
|
float
|
Tolerance for generating Kraus operators. Defaults to 1e-5. |
1e-05
|
tolo
|
float
|
Tolerance for observable decomposition. Defaults to 1e-5. |
1e-05
|
**kwargs
|
Any
|
Additional keyword arguments for propagator calculation. |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array containing the quantum simulation results. |
Source code in src/qflux/open_systems/quantum_simulation.py
qc_simulation_vecdens(time_arr, shots=1024, backend=AerSimulator(), Gprop=None, **kwargs)
Perform quantum simulation using the vectorized density matrix representation.
This method simulates the quantum system dynamics over a series of time steps by constructing circuits based on the vectorized density matrix representation, performing measurements, and processing the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_arr
|
List[float]
|
List of time steps for simulation. |
required |
shots
|
int
|
Number of measurement shots. Defaults to 1024. |
1024
|
backend
|
Any
|
Quantum simulation backend. Defaults to AerSimulator(). |
AerSimulator()
|
Gprop
|
Optional[List[ndarray]]
|
Propagator matrix (or list of matrices) for simulation. If None, it will be calculated. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments for propagator calculation. |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array containing the quantum simulation results. |
Source code in src/qflux/open_systems/quantum_simulation.py
set_count_str(count_str)
Set the counting bit string for measurement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count_str
|
List[str]
|
The counting bit string. |
required |
set_dilation_method(method)
Set the dilation method for quantum simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
The dilation method, e.g., 'Sz-Nagy', 'SVD', or 'SVD-Walsh'. |
required |
Source code in src/qflux/open_systems/quantum_simulation.py
set_observable(observable)
Set the observable for the quantum simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observable
|
ndarray
|
The observable matrix. |
required |
DVR_grid
Class for Discrete Variable Representation (DVR) grid methods.
This class handles grid-based representations for systems where the potential is expressed on grid points.
Attributes:
Name | Type | Description |
---|---|---|
Ngrid |
int
|
Number of grid points. |
xmin |
float
|
Minimum value of the grid. |
xmax |
float
|
Maximum value of the grid. |
mass |
float
|
Mass of the particle. |
xgrid |
ndarray
|
Array of grid points in position space. |
dx |
float
|
Spacing between grid points. |
dk |
float
|
Spacing in momentum space. |
kgrid |
ndarray
|
Array of grid points in momentum space. |
ak2 |
ndarray
|
Kinetic energy array in momentum space. |
hamk |
ndarray
|
Kinetic Hamiltonian matrix in position space. |
potential |
Optional[ndarray]
|
Potential energy array on the grid. |
Source code in src/qflux/open_systems/numerical_methods.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
__init__(xmin, xmax, Ngrid, mass)
Initialize the DVR_grid instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xmin
|
float
|
Minimum x-value. |
required |
xmax
|
float
|
Maximum x-value. |
required |
Ngrid
|
int
|
Number of grid points. |
required |
mass
|
float
|
Mass of the particle. |
required |
Source code in src/qflux/open_systems/numerical_methods.py
_set_kinet_ham()
Set up the kinetic Hamiltonian matrix in position space.
This method computes the momentum grid and the corresponding kinetic energy values, and constructs the kinetic Hamiltonian matrix in position space using a Fourier transform.
Source code in src/qflux/open_systems/numerical_methods.py
_set_xgrid()
Set up the position space grid.
Initializes the xgrid
attribute using a linear space between xmin
and xmax
.
get_eig_state(Nstate)
Get the eigenstates for the potential in x-space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Nstate
|
int
|
Number of eigenstates to output. |
required |
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: A tuple containing:
- Eigenvalues (np.ndarray) for the first |
Source code in src/qflux/open_systems/numerical_methods.py
k2x_wave(psik)
Transform the wavefunction from momentum space to position space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psik
|
ndarray
|
Wavefunction in momentum space. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Wavefunction in position space. |
Source code in src/qflux/open_systems/numerical_methods.py
set_potential(func_pot)
Set up the potential energy array on the grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func_pot
|
Callable[[float], float]
|
Function that returns the potential value at a given x. |
required |
Source code in src/qflux/open_systems/numerical_methods.py
x2k_wave(psi)
Transform the wavefunction from position space to momentum space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psi
|
ndarray
|
Wavefunction in position space. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Wavefunction in momentum space. |