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: Module

Base class for density matrices.

__init__(num_states: int, batchsize: int = 1)[source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

get_rho()[source]
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
normalize(rho: Tensor)[source]

This function normalizes the density matrix. :param rho: the density matrix to be normalized.

class qepsilon.system.QubitDensityMatrix(n_qubits: int = 1, batchsize: int = 1)[source]

Bases: DensityMatrix

This 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.

observe_paulix_one_qubit(rho: Tensor, idx: int)[source]
observe_pauliy_one_qubit(rho: Tensor, idx: int)[source]
observe_pauliz_one_qubit(rho: Tensor, idx: int)[source]
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

observe_one_qubit(rho: Tensor, observable: Tensor, idx: int)[source]

This function observes the one-qubit observable on the idx-th qubit. :param rho: the density matrix to be observed. :param observable: the one-qubit observable. :param idx: the index of the qubit to be observed.

Pure Ensemble

class qepsilon.system.PureStatesEnsemble(num_states: int, batchsize: int = 1)[source]

Bases: Module

Base 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.

get_pse()[source]
set_pse(pse: Tensor)[source]

This function sets the pure states. :param pse: a complex tensor. Shape: (self.nb, self.ns).

property norm
normalize(pse: Tensor)[source]

This function normalizes the pure states. :param pse: the pure states to be normalized. Shape: (batchsize, ns).

get_expectation(operator: Tensor)[source]

This function computes the expectation of an operator on the pure state ensemble. :param operator: the operator to get the expectation. Shape: (ns, ns).

Returns:

the expectation of the operator. Shape: (batchsize).

Return type:

expectation

class qepsilon.system.TightBindingPureStatesEnsemble(n_sites: int, batchsize: int)[source]

Bases: PureStatesEnsemble

This 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

observe_r(pse: Tensor)[source]

This function observes <psi|r|psi>. :param pse: the pure states. Shape: (batchsize, nsites).

Returns:

Shape: (batchsize).

Return type:

r

observe_r2(pse: Tensor)[source]

This function observes <psi|r^2|psi>. :param pse: the pure states. Shape: (batchsize, nsites).

Returns:

Shape: (batchsize).

Return type:

r2

class qepsilon.system.QubitPureStatesEnsemble(n_qubits: int = 1, batchsize: int = 1)[source]

Bases: PureStatesEnsemble

This 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_paulix_one_qubit(pse: Tensor, idx: int)[source]
observe_pauliy_one_qubit(pse: Tensor, idx: int)[source]
observe_pauliz_one_qubit(pse: Tensor, idx: int)[source]
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: Module

This 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.

get_positions()[source]
get_velocities()[source]
get_temperature()[source]
get_forces()[source]
get_trajectory()[source]
set_positions(positions: Tensor)[source]
set_gaussian_velocities(temp: float = None)[source]
set_velocities(velocities: Tensor)[source]
zero_forces()[source]
modify_forces(df: Tensor)[source]

Modify the forces on the particles.

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)

reset(temp: float = None)[source]

Reset the particles to a thermal equilibrium state.

get_noise(temp=None)[source]
step_langevin(record_traj=False, temp=None)[source]

Isothermal Langevin dynamics. Update the positions and velocities by one time step with mid-point Langevin method.

step_adiabatic(record_traj=False)[source]

Adiabatic dynamics. Update the positions and velocities by one time step with leapfrog method.

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: Particles

This 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

get_tweezer_by_id(id)[source]
remove_tweezer(id)[source]
turn_on_tweezer(id)[source]
turn_off_tweezer(id)[source]
get_trapping_info()[source]
set_positions_at_tweezer_center()[source]
set_gaussian_velocities(radial_temp: float = None, axial_temp: float = None)[source]
get_trapping_forces()[source]

Get the trapping forces on the particles.

reset()[source]

Reset the particles to a thermal equilibrium state.

get_noise(temp=None)[source]
equilibrate(nsteps: int, tau: float = 1)[source]

Equilibrate the particles with Langevin dynamics.