LocalErgotropy
Documentation for LocalErgotropy.
LocalErgotropy is a package to compute the local ergotropy of a quantum system. The ergotropy is obtained via numerical optimisation (gradient descent over the unitary manifold).
LocalErgotropy.cayley_step!LocalErgotropy.commutatorLocalErgotropy.commutator!LocalErgotropy.conjugateLocalErgotropy.conjugate!LocalErgotropy.ergotropyLocalErgotropy.ergotropyLocalErgotropy.ergotropy_gradient!LocalErgotropy.ergotropy_linesearch!LocalErgotropy.ergotropy_objectiveLocalErgotropy.ergotropy_optimisationLocalErgotropy.extractable_workLocalErgotropy.local_ergotropy_gradient!LocalErgotropy.local_ergotropy_linesearch!LocalErgotropy.local_ergotropy_objectiveLocalErgotropy.local_ergotropy_optimisationLocalErgotropy.local_extractable_workLocalErgotropy.random_density_matrixLocalErgotropy.random_density_matrix_eigenLocalErgotropy.random_hamiltonianLocalErgotropy.random_hamiltonian_spectrum
LocalErgotropy.cayley_step! — Method
cayley_step!(Vnew, V, G, η, M, GV)Compute the gradient descent unitary update via the Cayley transform. The Cayley update is given by:
\[ V_{new} = \left(I + \frac{η}{2} G\right)^{-1} \left(V - \frac{η}{2} G V\right)\]
Arguments
Vnew: preallocated matrix to store the updated unitary in-place.V: previous unitary.G: skew-Hermitian gradient.η: step size (real scalar).M: preallocated workspace for intermediate calculations.GV: preallocated workspace for intermediate calculations.
LocalErgotropy.commutator! — Method
commutator!(C, A, B, α)
commutator!(C, A, B)Compute the commutator
\[ C = α(A B - B A)\]
in-place.
Arguments
C: preallocated matrix to store the commutator.A,B: input matrices.α: scalar multiplier (default 1).
LocalErgotropy.commutator — Method
commutator(A, B, α)
commutator(A, B)Compute the commutator
\[ α(A B - B A)\]
Arguments
A,B: input matrices.α: scalar multiplier (default 1).
LocalErgotropy.conjugate! — Method
conjugate!(Y, X, U, T)Compute the unitary conjugation
\[ Y = U X U'\]
in-place.
Arguments
Y: preallocated matrix to store the result.X: matrix to be conjugated.U: unitary matrix performing the conjugation.T: preallocated workspace for intermediate calculations.
LocalErgotropy.conjugate — Method
conjugate(X, U)Compute the unitary conjugation
\[ U * X * U'\]
Arguments
X: matrix to be conjugated.U: unitary matrix performing the conjugation.
LocalErgotropy.ergotropy — Method
ergotropy(p, pE, E)Compute the ergotropy for a state with eigenvalues p and energy populations pE corresponding to energy levels E, that is
\[ W = \sum_i p_{E_i} E_i - \sum_i p^{\downarrow}_i E_i\]
where p^{\downarrow} is the vector p sorted in descending order.
Arguments
p: vector of eigenvalues of the state.pE: vector of energy populations of the state.E: vector of energy levels.
LocalErgotropy.ergotropy — Method
ergotropy(ρ, H)Compute the ergotropy of a state ρ with respect to Hamiltonian H.
Arguments
ρ: density matrix.H: Hamiltonian.
LocalErgotropy.ergotropy_gradient! — Method
ergotropy_gradient!(G, V, ρ, H, X, T)Compute the gradient of the ergotropy objective function with respect to the unitary V and write it in-place into the preallocated matrix G.
Arguments
G: preallocated matrix to store the gradient in-place.V: unitary matrix.ρ: density matrix.H: Hamiltonian.X,T: preallocated workspaces used for intermediate computations.
LocalErgotropy.ergotropy_linesearch! — Method
ergotropy_linesearch!(Vnext, Vprev, ρ, H, G, X, T; c=1e-4, α=1.0, β=0.7, maxiter=10_000)Backtracking line search for the ergotropy optimisation unitary update using the Armijo stopping condition.
Arguments
Vnext: preallocated matrix to store the updated unitary in-place.Vprev: previous unitary.ρ: density matrix.H: Hamiltonian.G: gradient matrix (must be skew-Hermitian).X,T: preallocated workspaces used for intermediate computations.c: Armijo condition parameter (default 1e-4).α: initial step size parameter (default 1.0).β: step size reduction factor (default 0.7).maxiter: maximum number of line search iterations (default 10,000).
LocalErgotropy.ergotropy_objective — Method
ergotropy_objective(V, ρ, H, X, T)Evaluate the objective function used in ergotropy optimisation, which is given by $math \mathrm{tr}(V ρ V' H)$`
Arguments
V: unitary matrix.ρ: density matrix.H: Hamiltonian.X,T: preallocated workspaces used for intermediate computations.
LocalErgotropy.ergotropy_optimisation — Method
ergotropy_optimisation(ρ, H; rtol=1e-6, atol=0.0, maxiter=100_000, maxiter_linesearch=10_000)
ergotropy_optimisation(ρ, H, Vinit; rtol=1e-6, atol=0.0, maxiter=100_000, maxiter_linesearch=10_000)Run gradient-based optimisation over unitaries to maximise the extractable work for state ρ and Hamiltonian H. Returns a tuple with the optimal ergotropy value W and the optimal unitary Vopt. If provided, Vinit is used as the initial unitary for the gradient descent; otherwise, a random Haar unitary is generated.
Arguments
ρ: density matrix.H: Hamiltonian.Vinit: (optional) initial unitary for the optimisation. If not provided, a Haar-random unitary is used.rtol: relative tolerance for convergence (default 1e-6).atol: absolute tolerance for convergence (default 0.0).grtol: gradient norm relative tolerance for convergence (default 1e-8).gatol: gradient norm absolute tolerance for convergence (default 0.0).maxiter: maximum number of optimisation iterations (default 100,000).maxiter_linesearch: maximum number of line search iterations (default 10,000).
Returns
Wopt: optimal extractable work.Vopt: unitary achieving the optimum.
LocalErgotropy.extractable_work — Method
extractable_work(ρ, H, U)Compute the extractable work from state ρ with Hamiltonian H using unitary U, that is
\[ W = \mathrm{tr}(ρ H) - \mathrm{tr}(U ρ U' H)\]
Arguments
ρ: density matrix (possibly unnormalised).H: Hamiltonian.U: unitary used to extract the work.
LocalErgotropy.local_ergotropy_gradient! — Method
local_ergotropy_gradient!(G, V, ρ0, ρ1, H0, H1, X, T)Compute the gradient of the local ergotropy objective with respect to the unitary V and write it in-place into the preallocated matrix G.
Arguments
G: preallocated matrix to store the gradient.V: unitary matrix.ρ0,ρ1: local density matrices (possibly unnormalised).H0,H1: Hamiltonians for the respective states.X,T: preallocated workspaces used for intermediate computations.
LocalErgotropy.local_ergotropy_linesearch! — Method
local_ergotropy_linesearch!(Vnext, Vprev, ρ0, ρ1, H0, H1, G, X, T; c=1e-4, α=1.0, β=0.7, maxiter=10_000)Backtracking line search for the local ergotropy optimisation unitary update using the Armijo stopping condition.
Arguments
Vnext: preallocated matrix to store the updated unitary in-place.Vprev: previous unitary.ρ0,ρ1: local density matrices (possibly unnormalised).H0,H1: Hamiltonians for the respective states.G: gradient matrix (must be skew-Hermitian).X,T: preallocated workspaces used for intermediate computations.c: Armijo condition parameter (default 1e-4).α: initial step size (default 1.0).β: step size reduction factor (default 0.7).maxiter: maximum number of line search iterations (default 10,000).
LocalErgotropy.local_ergotropy_objective — Method
local_ergotropy_objective(V, ρ0, ρ1, H0, H1, X, T)Evaluate the objective function used in the local ergotropy optimisation, which is given by $math \mathrm{tr}(V ρ_0 V' H_0) + \mathrm{tr}(V ρ_1 V' H_1)$`
Arguments
V: unitary matrix.ρ0,ρ1: local density matrices (possibly unnormalised).H0,H1: Hamiltonians for the respective states.X,T: preallocated workspaces used for intermediate computations.
LocalErgotropy.local_ergotropy_optimisation — Method
local_ergotropy_optimisation(ρ0, ρ1, H0, H1; rtol=1e-6, atol=0.0, maxiter=100_000, maxiter_linesearch=10_000)
local_ergotropy_optimisation(ρ0, ρ1, H0, H1, Vinit; rtol=1e-6, atol=0.0, maxiter=100_000, maxiter_linesearch=10_000)Run gradient-based optimisation over unitaries to maximise the local extractable work for states ρ0, ρ1 and Hamiltonians H0, H1. Returns a tuple with the optimal ergotropy value W and the optimal unitary Vopt. If provided, Vinit is used as the initial unitary for the gradient descent; otherwise, a random Haar unitary is generated.
Arguments
ρ0,ρ1: local density matrices (possibly unnormalised).H0,H1: Hamiltonians for the respective states.Vinit: (optional) initial unitary for the optimisation. If not provided, a Haar-random unitary is used.rtol: relative tolerance for convergence (default 1e-6).atol: absolute tolerance for convergence (default 0.0).grtol: gradient norm relative tolerance for convergence (default 1e-8).gatol: gradient norm absolute tolerance for convergence (default 0.0).maxiter: maximum number of optimisation iterations (default 100,000).maxiter_linesearch: maximum number of line search iterations (default 10,000
Returns
Wopt: optimal local extractable work.Vopt: unitary achieving the optimum (approximate).
LocalErgotropy.local_extractable_work — Method
local_extractable_work(ρ0, ρ1, H0, H1, U)Compute the weighted extractable work for two (possibly unnormalised) states ρ0, ρ1 with corresponding Hamiltonians H0, H1 under the same unitary U, that is
\[ W = p_0 W_0 + p_1 W_1\]
where p_n = \mathrm{tr}(ρ_n) and W_n is the extractable work from state σ_n = ρ_n / p_n with Hamiltonian H_n using unitary U.
Arguments
ρ0,ρ1: local density matrices (possibly unnormalised).H0,H1: Hamiltonians for the respective states.U: unitary used to compute the extractable work.
LocalErgotropy.random_density_matrix — Method
random_density_matrix(d)Return a random density matrix of dimension d×d where the eigenvalues are drawn uniformly from the d-simplex and the eigenvectors are Haar-random.
Arguments
d: dimension of the Hilbert space.
LocalErgotropy.random_density_matrix_eigen — Method
random_density_matrix_eigen(d)Generate a random density matrix with eigen-decomposition ρ = U * Diagonal(p) * U' where p is drawn uniformly from the d-simplex and U is Haar-random.
Arguments
d: dimension of the Hilbert space.
Returns
p: vector of random eigenvalues of the density matrix.U: Random unitary eigenbasis of the density matrix.
LocalErgotropy.random_hamiltonian — Function
random_hamiltonian(d; Emin=0.0, Emax=1.0)Construct a random Hamiltonian with eigenvalues sampled uniformly from [Emin, Emax] and eigenvectors drawn from the Haar measure.
Arguments
d: matrix dimension.Emin,Emax: energy range (defaults 0.0 and 1.0).
LocalErgotropy.random_hamiltonian_spectrum — Function
random_hamiltonian_spectrum(d; Emin=0.0, Emax=1.0)Sample d energy levels uniformly in the interval [Emin, Emax] and return them sorted in ascending order.
Arguments
d: number of energy levels to generate.Emin: minimum energy (default 0.0).Emax: maximum energy (default 1.0).