Examples

Examples of implementation of the Bath Mapper's functionality can be found below.

from struqture_py import mixed_systems, spins, bosons  # type: ignore
from bath_mapper import (  # type: ignore
    coupling_to_spectral_function,
    SpinBRNoiseOperator,
    spectral_function_to_coupling,
)
import numpy as np

# Use three boson baths
bath_energies = [0, 1, 2]

# Use three boson baths
bath_broadenings = [0.1, 0.2, 0.3]

# Couplings to spin 0
couplings_0 = [0.3, 0.1, 0.3]
# Couplings to spin 1
couplings_1 = [0.2, 0.4, 0.2]

# Create a new mixed system with one spin and one boson subsystem
Hnew = mixed_systems.MixedLindbladOpenSystem(
    [None],
    [None],
    [],
)

# Set bath energies
for bath_index, be in enumerate(bath_energies):
    index = mixed_systems.HermitianMixedProduct(
        # Identity spin operator
        [spins.PauliProduct()],
        # Create a Boson occupation operator
        [bosons.BosonProduct([bath_index], [bath_index])],
        [],
    )
    Hnew.system_set(index, be)

# Set bath energies
for bath_index, bb in enumerate(bath_broadenings):
    # create the index for the Lindblad terms.
    # We have pure damping
    index = mixed_systems.MixedDecoherenceProduct(
        # Identity spin operator
        [spins.DecoherenceProduct()],
        # Create a Boson occupation operator
        [bosons.BosonProduct([], [bath_index])],
        [],
    )
    Hnew.noise_set((index, index), bb)


# Set couplings, use pure ZZ coupling
for bath_index, c in enumerate(couplings_0):
    index = mixed_systems.HermitianMixedProduct(
        # Identity spin operator
        [spins.PauliProduct().z(0)],
        # Create a Boson coupling  operator (always a + a^dagger)
        [bosons.BosonProduct([], [bath_index])],
        [],
    )
    Hnew.system_set(index, c)


# Set couplings, use pure ZZ coupling
for bath_index, c in enumerate(couplings_1):
    index = mixed_systems.HermitianMixedProduct(
        # Identity spin operator
        [spins.PauliProduct().z(1)],
        # Create a Boson coupling  operator (always a + a^dagger)
        [bosons.BosonProduct([], [bath_index])],
        [],
    )
    Hnew.system_set(index, c)

print("Newly created system")
print(Hnew.__repr__())

# Create a spectral function from Spin-Bath-System
frequencies = np.linspace(-0.5, 4, 100)
spectral_function = coupling_to_spectral_function(Hnew, frequencies)

print("Spectrum frequencies")
print(spectral_function.frequencies())

print("Spectrum for 0, 0 spin indices with Z-Z coupling")
print(spectral_function.get(("0Z", "0Z")))

print("Spectrum for 0, 1 spin indices with Z-Z coupling")
print(spectral_function.get(("0Z", "1Z")))

# Creating an empty spectral function
spectra = SpinBRNoiseOperator(frequencies)
calculated_coupling = spectral_function_to_coupling(spectra, 2)

print("Coupling obtained from spin function")
print(calculated_coupling)

For further examples, please see our Quantum Libraries Examples.