QuantumToolbox Settings
In this section, we introduce the default global settings used throughout the package and show how to modify them.
All settings are stored in QuantumToolbox.settings.
Differences from QuTiP
Due to the differences in programming languages, solving algorithms, and many other reasons, these global settings (including their default values and usage) may be very different from those in Python QuTiP.
List of settings
Here, we list out each setting along with the specific functions that will use it.
tidyup_tol::Float64 = 1.0e-14: tolerance fortidyup,tidyup!andto_sparse.auto_tidyup::Bool = true: Automatically tidyup during the following situations:Solving for eigenstates, including
eigenstates,eigsolve,eigsolve_alCreating
bloch_redfield_tensororbrterm, and solvingbrmesolve.
progressmeter_kwargs::NamedTuple = (showspeed = true, printed = true): Default keyword arguments for progress bar inProgressMeter.jl. This allows the customization of progress bar.default_eltype::Type = ComplexF64: Element type of the quantum objects created without specifying it, such asdestroy(N)orfock(N, j). It must be a concrete floating point or complex type, such asComplexF32orFloat64. A real type can be used for real-valued systems: functions that need complex numbers, such assigmayorrand_ket, then use its complex version.show_eltype_warning::Bool = true: Warn (once) when a quantum object is created with an element type more general thandefault_eltype, e.g.,0.5 * destroy(N)withdefault_eltype = ComplexF32, or a complex state with a realdefault_eltype.
Change default settings
First, we can check the current QuantumToolbox.settings:
using QuantumToolbox
QuantumToolbox.settingsQuantumToolbox.jl Settings
--------------------------
tidyup_tol = 1.0e-14
auto_tidyup = true
progressmeter_kwargs = (showspeed = true, printed = true)
default_eltype = ComplexF64
show_eltype_warning = trueNext, one can overwrite the default settings by
QuantumToolbox.settings.tidyup_tol = 1e-10
QuantumToolbox.settings.auto_tidyup = false
QuantumToolbox.settingsQuantumToolbox.jl Settings
--------------------------
tidyup_tol = 1.0e-10
auto_tidyup = false
progressmeter_kwargs = (showspeed = true, printed = true)
default_eltype = ComplexF64
show_eltype_warning = trueChange the default element type
By default, quantum objects are created with element type ComplexF64. To use a lower precision, for example to run faster or to save memory, one can change default_eltype:
QuantumToolbox.settings.default_eltype = ComplexF32
a = destroy(5)
eltype(a)ComplexF32 (alias for Complex{Float32})Note that a Float64 number promotes the element type back to ComplexF64, following the usual promotion rules of Julia. A warning is shown (once per session) when this happens:
eltype(0.5 * a)ComplexF64 (alias for Complex{Float64})To keep the lower precision, use Float32 numbers instead, such as 0.5f0:
eltype(0.5f0 * a)ComplexF32 (alias for Complex{Float32})An element type given explicitly is still used. The warning above cannot tell it apart from a promotion, so set QuantumToolbox.settings.show_eltype_warning = false if a more general type is intended:
eltype(destroy(ComplexF64, 5))ComplexF64 (alias for Complex{Float64})Change progressmeter_kwargs and default_eltype with a separate statement
Changing progressmeter_kwargs or default_eltype redefines a method, so code that is already running keeps seeing the previous value: reading default_eltype there throws an error, and the progress bar keeps the previous progressmeter_kwargs. Change them with a separate statement, for example at the beginning of your script, and not inside a function or a block (such as begin, let, try or for) that also uses them. For the same reason, they cannot be changed by a package while it is being precompiled: packages should pass the element type explicitly instead, e.g., destroy(T, N).