hqs_noise_app.BathFitter
- class hqs_noise_app.BathFitter(number_boson_modes: int, spins_per_bosonic_mode: int = 1, broadening_constraint: List[float] | None = None, background_broadening_ratio: float = 0.0, minimum_eigenfrequencies: float | None = None, maximum_eigenfrequencies: float | None = None, fitting_window: Tuple[float, float, int] | None = None, coupling_types: Dict[Tuple[int, int], List[str]] | List[str] | None = None, coupling_indices: List[Tuple[int, int]] | None = None, max_fitting_iterations: int = 5, max_fitting_error: float = 0.05)
Utility for fitting effective open quantum systems to original open quantum systems.
- __init__(number_boson_modes: int, spins_per_bosonic_mode: int = 1, broadening_constraint: List[float] | None = None, background_broadening_ratio: float = 0.0, minimum_eigenfrequencies: float | None = None, maximum_eigenfrequencies: float | None = None, fitting_window: Tuple[float, float, int] | None = None, coupling_types: Dict[Tuple[int, int], List[str]] | List[str] | None = None, coupling_indices: List[Tuple[int, int]] | None = None, max_fitting_iterations: int = 5, max_fitting_error: float = 0.05) None
Initialized Fitting utility.
- Parameters:
number_boson_modes (int) -- Number of bosonic modes used for the fit of bosonic baths.
spins_per_bosonic_mode (int) -- Number of spin modes used to represent one bosonic mode.
broadening_constraint (Optional[List[float]]) -- The optional broadening constraints. When None broadenings of bosonic modes are fitted freely. When given the relative broadening of all modes is fixed and only a prefactor is fitted. The prefactor corresponds to the Trotter timestep in a quantum circuit.
background_broadening_ratio (float) -- Adds a constant background offset to the diagonal spectral functions when fitting. Given in terms of (as a ratio of) the average broadening.
minimum_eigenfrequencies (Optional[float]) -- Minimal value allowed for bath eigenfrequencies.
maximum_eigenfrequencies (Optional[float]) -- Maximum value allowed for bath eigenfrequencies.
fitting_window (Optional[Tuple[float,float, int]]) -- The frequency window used for the fitting (start, end , steps). If no values are provided the functions uses the whole frequency range to determine the fit.
coupling_types (Optional[Union[Dict[Tuple[int, int], List[str]], List[str]]]) -- A list of the couplings to include. If None, all the couplings are used: X, Y, Z.
coupling_indices (Optional[List[Tuple[int, int]]]) -- A list of allowed fermionic hopping operators of the form c^dagger_j c_k that are allowed to couple to bosonic modes. For example [(0,0), (0,1)] only allows coupling operators c^dagger_0 c_0 and c^dagger_0 c_1 If None, all the couplings are allowed. The default is None.
max_fitting_iterations (int) -- The maximum number of iterations a fit is tried before reporting an error not being able to fit the spectrum.
max_fitting_error (float) -- The maximum allowed error in the fit of the spectrum.
Methods
__init__(number_boson_modes[, ...])Initialized Fitting utility.
execution_time_helper(device, algorithm, ...)Helper function to calculate the execution time for a function.
Fits a model Spin-Boson system to an original Spin-Boson system.
Fits a model Spin-Boson system to an original Spin-Fermion system.
Fits a model Spin-Boson system to a Spin spectral function.
Fits a model Fermion-Boson system to an original Fermion-Boson system.
Fits a model Fermion-Boson system to a Fermion spectral function.
Fits a model Fermion-Spin system to an original Fermion-Boson system.
fit_spin_bath_to_boson_bath(original_system, ...)Fits a model Spin-Spin system to an original Spin-Boson system.
fit_spin_bath_to_fermion_bath(...[, ...])Fits a model Spin-Spin system to an original Spin-Fermion system.
fit_spin_bath_to_spectral_function(...[, ...])Fits a model Spin-Spin system to a Spin spectral function.
from_json(json_dict)Initializes the object from a JSON representation.
spin_bath_trotterstep_from_boson_bath(...[, ...])Creates Spin-Spin Hamiltonian and Trotterstep from Spin-Boson system.
to_json()Returns a JSON representation of the object.
Attributes
The broadenings from the last fit of the spectrum.
The maximum allowed fitting error in fitting the spectrum.
The number of retries allowed when fitting the spectrum.
- execution_time_helper(device: Any, algorithm: Any, function_name: str, **kwargs) float
Helper function to calculate the execution time for a function.
- Parameters:
device (Device) -- The device containing the gate times.
algorithm (Any) -- the py_alqorithms algorithm to be used in the circuit creation, for which to calculate the execution time.
function_name (str) -- The name of the function which requires the execution time.
kwargs (Dict[str, Any]) -- The keyword arguments required for the function specified function_name.
- Returns:
Execution time of the function.
- Return type:
(float)
- fit_boson_bath_to_boson_bath(original_system: MixedLindbladOpenSystem, frequencies: ndarray, number_spins: int) Tuple[MixedLindbladOpenSystem, float | None]
Fits a model Spin-Boson system to an original Spin-Boson system.
- Parameters:
original_system (MixedLindbladOpenSystem) -- The spin-boson system bath model the effective model is fitted to
frequencies (ndarray) -- The frequencies for the spectral functions that is calculated from the Bosonic bath
number_spins (int) -- The total number of spins in the original system
- Returns:
- The Spin-Boson system and
for constrained broadenings the fitted prefactor.
- Return type:
(MixedLindbladOpenSystem, Optional[float])
- fit_boson_bath_to_fermion_bath(original_system: MixedHamiltonian, temperature: float, number_frequency_points: int, number_spins: int) Tuple[Tuple[MixedLindbladOpenSystem, float | None], List[float]]
Fits a model Spin-Boson system to an original Spin-Fermion system.
- Parameters:
original_system (MixedHamiltonian) -- The spin-fermion system bath model the effective model is fitted to
temperature (float) -- The fermionic bath temperature assumed to obtain the spectral function
number_frequency_points (int) -- The number of frequency points used to discretize the spectral function obtained from the Fermion bath
number_spins (int) -- The total number of spins in the original system
- Returns:
- The Spin-Boson system,
the fitted prefactor (for constrained broadenings) and the corresponding frequencies.
- Return type:
((MixedLindbladOpenSystem, Optional[float]), List[float])
- fit_boson_bath_to_spectral_function(spin_system: PauliHamiltonian, spectral_function: SpinBRNoiseOperator, number_spins: int) Tuple[MixedLindbladOpenSystem, float | None]
Fits a model Spin-Boson system to a Spin spectral function.
- Parameters:
spin_system (PauliHamiltonian) -- The coherent spin system for which the spectral function determines the noise
spectral_function (SpinBRNoiseOperator) -- The Bloch-Redfield type spectral function that determines the decoherence in the open system the effective system is fitted to.
number_spins (int) -- The total number of spins in the original system
- Returns:
- The Spin-Boson system and
for constrained broadenings the fitted prefactor.
- Return type:
(MixedLindbladOpenSystem, Optional[float])
- fit_fermion_boson_system_to_fermion_boson_system(original_system: MixedLindbladOpenSystem, frequencies: ndarray, number_fermionic_modes: int) Tuple[MixedLindbladOpenSystem, float | None]
Fits a model Fermion-Boson system to an original Fermion-Boson system.
- Parameters:
original_system (MixedLindbladOpenSystem) -- The fermion-boson system bath model the effective model is fitted to
frequencies (ndarray) -- The frequencies for the spectral functions that is calculated from the Bosonic bath
number_fermionic_modes (int) -- The total number of fermionic modes in the system
- Returns:
- The Fermion-Boson system and
for constrained broadenings the fitted prefactor.
- Return type:
(MixedLindbladOpenSystem, Optional[float])
- fit_fermion_boson_system_to_spectral_function(fermionic_system: FermionHamiltonian, spectral_function: FermionBRNoiseOperator, number_fermionic_modes: int) Tuple[MixedLindbladOpenSystem, float | None]
Fits a model Fermion-Boson system to a Fermion spectral function.
- Parameters:
fermionic_system (FermionHamiltonian) -- The coherent fermion system for which the spectral function determines the noise
spectral_function (FermionBRNoiseOperator) -- The Bloch-Redfield type spectral function that determines the decoherence in the open system the effective system is fitted to.
number_fermionic_modes (int) -- The total number of fermionic modes in the system
- Returns:
- The Fermion-Boson system and
for constrained broadenings the fitted prefactor.
- Return type:
(MixedLindbladOpenSystem, Optional[float])
- fit_fermion_spin_system_to_fermion_boson_system(original_system: MixedLindbladOpenSystem, frequencies: ndarray, number_fermionic_modes: int, system_circuit_execution_time: float | None = None) Tuple[MixedHamiltonian, float | None]
Fits a model Fermion-Spin system to an original Fermion-Boson system.
- Parameters:
original_system (MixedLindbladOpenSystem) -- The fermion-boson system bath model the effective model is fitted to
frequencies (ndarray) -- The frequencies for the spectral functions is calculated from the Bosonic bath
number_fermionic_modes (int) -- The total number of fermionic modes in the system
system_circuit_execution_time (Optional[float]) -- The execution time for the circuit that implements the time propagation of the system on the quantum computer. To match the dissipation of bosonic modes in the lab time frame to the time propagation of the system for the virtual time of a trotterstep the time the Trotter circuit needs to run on a quantum computer needs to be known. This needs to be given when the broadening constraints are not None.
- Returns:
- The Fermion-Spin system and
for constrained broadenings the trotter timestep that fixes the correct broadening prefactor.
- Return type:
(MixedHamiltonian, Optional[float])
- fit_spin_bath_to_boson_bath(original_system: MixedLindbladOpenSystem, frequencies: ndarray, number_spins: int, system_circuit_execution_time: float | None = None) Tuple[MixedHamiltonian, float | None]
Fits a model Spin-Spin system to an original Spin-Boson system.
- Parameters:
original_system (MixedLindbladOpenSystem) -- The spin-boson system bath model the effective model is fitted to
frequencies (ndarray) -- The frequencies for the spectral functions is calculated from the Bosonic bath
number_spins (int) -- The total number of spins in the original system
system_circuit_execution_time (Optional[float]) -- The execution time for the circuit that implements the time propagation of the system on the quantum computer. To match the dissipation of bosonic modes in the lab time frame to the time propagation of the system for the virtual time of a trotterstep the time the Trotter circuit needs to run on a quantum computer needs to be known. This needs to be given when the broadening constraints are not None.
- Returns:
- The Spin-Spin system and
for constrained broadenings the trotter timestep that fixes the correct broadening prefactor.
- Return type:
(MixedHamiltonian, Optional[float])
- fit_spin_bath_to_fermion_bath(original_system: MixedHamiltonian, temperature: float, number_frequency_points: int, number_spins: int, system_circuit_execution_time: float | None = None) Tuple[Tuple[MixedHamiltonian, float | None], List[float]]
Fits a model Spin-Spin system to an original Spin-Fermion system.
- Parameters:
original_system (MixedHamiltonian) -- The spin-fermion system bath model the effective model is fitted to
temperature (float) -- The fermionic bath temperature assumed to obtain the spectral function
number_frequency_points (int) -- The number of frequency points used to discretize the spectral function opained from the Fermion bath
number_spins (int) -- The total number of spins in the original system
system_circuit_execution_time (Optional[float]) -- The execution time for the circuit that implements the time propagation of the system on the quantum computer. To match the dissipation of bosonic modes in the lab time frame to the time propagation of the system for the virtual time of a trotterstep the time the Trotter circuit needs to run on a quantum computer needs to be known. This needs to be given when the broadening constraints are not None.
- Returns:
- The Spin-Spin system,
the trotter timestep that fixes the correct broadening prefactor for constrained broadenings, and the corresponding frequencies.
- Return type:
((MixedHamiltonian, Optional[float]), List[float])
- fit_spin_bath_to_spectral_function(spin_system: PauliHamiltonian, spectral_function: SpinBRNoiseOperator, number_spins: int, system_circuit_execution_time: float | None = None) Tuple[MixedHamiltonian, float | None]
Fits a model Spin-Spin system to a Spin spectral function.
- Parameters:
spin_system (PauliHamiltonian) -- The coherent spin system for which the spectral function determines the noise
spectral_function (SpinBRNoiseOperator) -- The Bloch-Redfield type spectral function that determines the decoherence in the open system the effective system is fitted to.
number_spins (int) -- The total number of spins in the original system
system_circuit_execution_time (Optional[float]) -- The execution time for the circuit that implements the time propagation of the system on the quantum computer. To match the dissipation of bosonic modes in the lab time frame to the time propagation of the system for the virtual time of a trotterstep the time the Trotter circuit needs to run on a quantum computer needs to be known. This needs to be given when the broadening constraints are not None. It can be obtained with the HQS quantum libraries qonvert.get_execution_time function.
- Returns:
- The Spin-Spin system and
for constrained broadenings the trotter timestep that fixes the correct broadening prefactor.
- Return type:
(MixedHamiltonian, Optional[float])
- classmethod from_json(json_dict: Dict[str, Any]) BathFitter
Initializes the object from a JSON representation.
- Parameters:
json_dict (Dict[str, Any]) -- JSON representation of the object.
- property last_fitted_broadenings: List[float] | None
The broadenings from the last fit of the spectrum.
- Returns:
The broadenings if a fit has been performed.
- Return type:
Optional[List[float]]
- property max_fitting_error: float
The maximum allowed fitting error in fitting the spectrum.
The bath fitter uses a simple metric for the quality of the fit: Let A be the sum of squares of the difference between the fitter and target and B be the sum of squares of the fitted spectral function. The quality of the fit is defined as the ratio A/B where a small ratio corresponds to a good fit. By default, a deviation of 5% is allowed. If the criterion is not met, the fitting is retried and if the number of retries exceeds the maximum the fit fails. By default, the number of retries is 5. This value can be changed using the max_fitting_iterations setter.
- Returns:
The maximum allowed fitting error as a ratio between spectrum deviation and the spectrum.
- Return type:
(float)
- property max_fitting_iterations: int
The number of retries allowed when fitting the spectrum.
The bath fitter uses a simple metric for the quality of the fit: Let A be the sum of squares of the difference between the fitter and target, and B be the sum of squares of the fitted spectral function. The quality of the fit is defined as the ratio A/B where a small ratio corresponds to a good fit. By default, a deviation of 5% is allowed. This value can be changed using the max_fitting_error setter. If the criterion is not met, the fitting is retried and if the number of retries exceeds the maximum, the fit fails.
- Returns:
The number of retries allowed when fitting the spectrum.
- Return type:
(int)
- spin_bath_trotterstep_from_boson_bath(spin_boson_system: MixedLindbladOpenSystem, prefactor: float | None, system_circuit_execution_time: float | None = None) Tuple[MixedHamiltonian, float | None]
Creates Spin-Spin Hamiltonian and Trotterstep from Spin-Boson system.
Converts a Spin-Boson open system and a fitting prefactor for the Bosonic mode broadening to a Spin-Spin system and a Trotter timestep that can be used to construct a quantum circuit to simulate the Spin part of the Spin-Boson circuit with an effective bath.
- Parameters:
spin_boson_system (MixedLindbladOpenSystem) -- The Spin-Boson open system that is transformed to a Spin-Spin system
prefactor (Optional[float]) -- The fitted prefactor of the bosonic mode broadenings Is used to derive the Trotter timestep
system_circuit_execution_time (Optional[float]) -- The execution time for the circuit that implements the time propagation of the system on the quantum computer. To match the dissipation of bosonic modes in the lab time frame to the time propagation of the system for the virtual time of a trotterstep the time the Trotter circuit needs to run on a quantum computer needs to be known. This needs to be given when the broadening constraints are not None. It can be obtained with the HQS quantum libraries qonvert.get_execution_time function.
- Returns:
- The Spin-Spin system and
for constrained broadenings the trotter timestep that fixes the correct broadening prefactor.
- Return type:
(MixedHamiltonian, Optional[float])
- to_json() Dict[str, Any]
Returns a JSON representation of the object.
- Returns:
JSON representation of the object.
- Return type:
(Dict[str, Any])