System Module
The system module contains classes for representing quantum systems and their states.
Density Matrix
- class qepsilon.system.DensityMatrix(num_states: int, batchsize: int = 1)[source]
Bases:
ModuleBase class for density matrices.
- __init__(num_states: int, batchsize: int = 1)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- set_rho(rho: Tensor)[source]
This function sets the density matrix. :param rho: a complex tensor. Shape: (self.nb, self.ns, self.ns).
- property trace
- class qepsilon.system.QubitDensityMatrix(n_qubits: int = 1, batchsize: int = 1)[source]
Bases:
DensityMatrixThis class deals with density matrices of an ensemble of n-qubit systems. Basic quantum operations on the ensemble of density matrices are implemented. Quantum operations are not necessarily unitary. A quantum operation is also called a quantum channel.
- __init__(n_qubits: int = 1, batchsize: int = 1)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- set_rho_by_config(config: Tensor)[source]
This function sets the density matrix as \(| \text{config} \rangle \langle \text{config} |\). :param config: a 0 or 1 tensor that specifies the spin configuration. Shape: (#qubits). Example for 2-qubit system: [0, 1] means \(| 01 \rangle\).
- partial_trace(rho: Tensor, config: Tensor)[source]
This function traces out the qubits specified in config. :param rho: the (\(2^n imes 2^n\)) density matrix to be traced out. :param config: a boolean tensor that specifies the qubits to be kept. config[i]==False means the i-th qubit will be traced out. Shape: (#qubits).
- apply_unitary_rotation(rho: Tensor, u: Tensor, theta: float, config=None)[source]
This function applies the unitary rotation operator about the direction u by angle theta to the density matrix. The rotation is simultaneous performed on selected qubits. :param rho: the density matrix to be rotated. :param direction: the direction of the rotation. Shape: (3) :param angle: the angle of the rotation. :param config: a boolean tensor that specifies the qubits to be rotated. config[i]==True means the i-th qubit is included in the rotation. Shape: (#qubits). If not specified, all qubits are included in the rotation.
- apply_kraus_operation(rho: Tensor, kraus_operators: list[Tensor], config=None)[source]
This function applies the Kraus operation to the density matrix. The operation is simultaneous performed on selected qubits. :param rho: the density matrix to be acted on. :param kraus_operators: a list of Kraus operators. :param config: a boolean tensor that specifies the qubits to be acted on. config[i]==True means the i-th qubit is included in the operation. Shape: (#qubits). If not specified, all qubits are included in the operation.
- get_diagonal_by_config(rho: Tensor, config: Tensor)[source]
This function gets the diagonal elements of the density matrix specified by config. :param rho: the density matrix. :param config: a 0 or 1 tensor that specifies the spin configuration. Shape: (#qubits). Example for 2-qubit system: [0, 1] means \(| 01 \rangle\).
- observe_prob_by_config(rho: Tensor, config: Tensor)[source]
This function observes the probability of the spin configuration specified by config. :param rho: the density matrix. :param config: a 0 or 1 tensor that specifies the spin configuration. Shape: (#qubits). Example for 2-qubit system: [0, 1] means \(| 01 \rangle\).
- Returns:
the probability of the spin configuration. Shape: (batchsize).
- Return type:
prob
Pure Ensemble
- class qepsilon.system.PureStatesEnsemble(num_states: int, batchsize: int = 1)[source]
Bases:
ModuleBase class for ensembles of pure states.
- __init__(num_states: int, batchsize: int = 1)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- set_pse(pse: Tensor)[source]
This function sets the pure states. :param pse: a complex tensor. Shape: (self.nb, self.ns).
- property norm
- class qepsilon.system.TightBindingPureStatesEnsemble(n_sites: int, batchsize: int)[source]
Bases:
PureStatesEnsembleThis class deals with pure states of an ensemble of tight binding systems.
- __init__(n_sites: int, batchsize: int)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- set_pse_by_config(config: Tensor)[source]
This function sets the pure states by a configuration. :param config: a 0 or 1 tensor that specifies the configuration. Shape: (nsites). Should contain exactly one 1.
- observe_occupation(pse: Tensor)[source]
This function observes the occupation of the sites. :param pse: the pure states. Shape: (batchsize, nsites).
- Returns:
the occupation of the sites. Shape: (batchsize, nsites).
- Return type:
occupation
- class qepsilon.system.QubitPureStatesEnsemble(n_qubits: int = 1, batchsize: int = 1)[source]
Bases:
PureStatesEnsembleThis class deals with pure states of an ensemble of n-qubit systems. Basic quantum operations on the ensemble of pure states are implemented.
- __init__(n_qubits: int = 1, batchsize: int = 1)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- set_pse_by_config(config: Tensor)[source]
This function sets all pure states as \(| \text{config} \rangle\). :param config: a 0 or 1 tensor that specifies the spin configuration. Shape: (#qubits). Example for 2-qubit system: [0, 1] means \(| 01 \rangle\).
- partial_trace(pse: Tensor, config: Tensor)[source]
This function traces out the qubits specified in config. :param pse: the (ns) pure states to be traced out. :param config: a boolean tensor that specifies the qubits to be kept. config[i]==False means the i-th qubit will be traced out. Shape: (#qubits).
- apply_unitary_rotation(pse: Tensor, u: Tensor, theta: float, config=None)[source]
This function applies the unitary rotation operator about the direction u by angle theta to the pure states. The rotation is simultaneous performed on selected qubits. :param pse: the pure states to be rotated. :param direction: the direction of the rotation. Shape: (3) :param angle: the angle of the rotation. :param config: a boolean tensor that specifies the qubits to be rotated. config[i]==True means the i-th qubit is included in the rotation. Shape: (#qubits). If not specified, all qubits are included in the rotation.
- observe_one_qubit(pse: Tensor, observable: Tensor, idx: int)[source]
This function observes the one-qubit observable on the idx-th qubit. :param pse: the pure states to be observed. :param observable: the one-qubit observable. :param idx: the index of the qubit to be observed.
- observe_prob_by_config(pse: Tensor, config: Tensor)[source]
This function observes the probability of the spin configuration specified by config. :param pse: the pure states. Shape: (batchsize, ns). :param config: a 0 or 1 tensor that specifies the spin configuration. Shape: (#qubits). Example for 2-qubit system: [0, 1] means \(| 01 \rangle\).
- Returns:
the probability of the spin configuration. Shape: (batchsize).
- Return type:
prob
Particles
- class qepsilon.system.Particles(n_particles: int, batchsize: int = 1, ndim: int = 3, mass: float = 1.0, dt: float = 0.1, tau: float = None, unit: str = 'pm_ps')[source]
Bases:
ModuleThis class represents particles in the QEpsilon project.
- __init__(n_particles: int, batchsize: int = 1, ndim: int = 3, mass: float = 1.0, dt: float = 0.1, tau: float = None, unit: str = 'pm_ps')[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- modify_forces_by_harmonic_trap(omega: float, x0: Tensor = None)[source]
Modify the forces on the particles by a harmonic trap. :param omega: float or th.Tensor, the frequency of the harmonic trap. Shape: (self.ndim) or (self.nq,self.ndim) :param x0: th.Tensor, the position of the harmonic trap. Shape: (self.ndim) or (self.nq,self.ndim)
- class qepsilon.system.ParticlesInTweezers(n_particles: int, batchsize: int = 1, mass: float = 1.0, radial_temp: float = 1.0, axial_temp: float = 1.0, dt: float = 0.1, tau: float = None, unit: str = 'um_us')[source]
Bases:
ParticlesThis class represents particles in the QEpsilon project.
- __init__(n_particles: int, batchsize: int = 1, mass: float = 1.0, radial_temp: float = 1.0, axial_temp: float = 1.0, dt: float = 0.1, tau: float = None, unit: str = 'um_us')[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- init_tweezers(id, min_waist, wavelength, max_depth, center, axis, on=True)[source]
Initialize a tweezer. :param id: int, the id of the tweezer :param min_waist: float, the minimum waist of the tweezer :param wavelength: float, the wavelength of the tweezer :param max_depth: float, the maximum depth of the tweezer :param center: th.Tensor, shape (3), the center of the tweezer :param axis: th.Tensor, shape (3), the axis of the tweezer