I'm trying to build an MPO for a spin-boson system, coupling a single spin-half to a chain of bosonic sites. To make it simple, I thought I'd try to set up an MPO for a single spin-half and a single site that can host a few bosons.
Code: Select all
import tenpy.networks as tpn
import tenpy.linalg.np_conserved as npc
spin_site = tpn.site.SpinHalfSite(conserve=None)
boson_site = tpn.site.BosonSite(Nmax=4, conserve='N')
tpn.site.set_common_charges([spin_site, boson_site])
""" This works """
spin_zx = tpn.mpo.grid_insert_ops(spin_site, [[spin_site.Sz, spin_site.Sx]])
bos_n = tpn.mpo.grid_insert_ops(boson_site, [[boson_site.N], [boson_site.NN]])
mpo = tpn.mpo.MPO.from_grids([spin_site, boson_site], [spin_zx, bos_n])
""" This does not work """
spin_zx = tpn.mpo.grid_insert_ops(spin_site, [[spin_site.Sz, None]])
bos_n = tpn.mpo.grid_insert_ops(boson_site, [[boson_site.N], [boson_site.NN]])
mpo = tpn.mpo.MPO.from_grids([spin_site, boson_site], [spin_zx, bos_n])
""" This however does work """
spin_zx = tpn.mpo.grid_insert_ops(spin_site, [[spin_site.Sz, spin_site.Sx]])
bos_middle = tpn.mpo.grid_insert_ops(boson_site, [[boson_site.N, None], [boson_site.NN, boson_site.NN]])
bos_n = tpn.mpo.grid_insert_ops(boson_site, [[boson_site.N], [boson_site.NN]])
mpo = tpn.mpo.MPO.from_grids([spin_site, boson_site, boson_site], [spin_zx, bos_middle, bos_n])
I then wondered whether the function does not like it when the last (or first) Superoperator in an MPO has 'None' values, and I do not have a conclusive answer to this. I only get an error if the spin_zx operator has a 'None' value. The MPO manages to get built if the bos_n operator has a 'None' value.
I get the following error in detect_grid_outer_legcharge
ValueError: can't derive flat charge for all indices:[array([0]), None]
I guess there would be a possibility to manually construct the MPO via the grid_outer function as is written in the example there https://tenpy.readthedocs.io/en/v0.8.2/ ... outer.html, but I tried to avoid that since I thought I'd rather have the charge-conservation and everything being taken care of by the functions instead of me manually plugging things in via LegCharge.
Would it be a viable hack to substitute 'None' with 0*spin_site.Id?
If not, why not?