Search found 18 matches

by Jakob
08 Apr 2025, 10:11
Forum: HowTos and FAQ for TeNPy
Topic: Isotropic spin-spin correlator for 1D J1–J2 model with PBC
Replies: 1
Views: 9658

Re: Isotropic spin-spin correlator for 1D J1–J2 model with PBC

The code you pasted already fails before this line. E.g. Sx = [model.lat.mps_sites().Sx for i in range(L)] fails, as model.lat.mps_sites() is a list. The failure you report is expected behavior as well. An operator, like the entries in your Sx list are Arrays and do not know what site they came from...
by Jakob
07 Apr 2025, 10:46
Forum: HowTos and FAQ for TeNPy
Topic: Changing Bose-Hubbard model
Replies: 9
Views: 50891

Re: Changing Bose-Hubbard model

1) - line before the three: initialize a BosonSite, with its opertors etc. next we modify it by adding the new operator - extract alpha from the model_params, this is just a convenient way to tell the model the value for alpha - N_diag is a helper for defining the operator. It is the diagonal of the...
by Jakob
03 Apr 2025, 16:09
Forum: HowTos and FAQ for TeNPy
Topic: Changing Bose-Hubbard model
Replies: 9
Views: 50891

Re: Changing Bose-Hubbard model

The operator you want is not one of the pre-defined operators of the BosonSite, so you would need to add it explicitly. You probably want to do something like this: class MyExtendedBoseHubbarModel(tenpy.BoseHubbardModel): def init_sites(self, model_params): site = super().init_sites(model_params) al...
by Jakob
03 Apr 2025, 07:19
Forum: HowTos and FAQ for TeNPy
Topic: Changing Bose-Hubbard model
Replies: 9
Views: 50891

Re: Changing Bose-Hubbard model

Ah I see. In that case you can replace the hopping for u1, u2, dx in self.lat.pairs['nearest_neighbors']: self.add_coupling(-t, u1, 'Bd', u2, 'B', dx, plus_hc=True) that generates \sum_{<i,j>} (b^\dagger_i b_j + hc) with for u1, u2, dx in self.lat.pairs['nearest_neighbors']: self.add_coupling(-t, u1...
by Jakob
02 Apr 2025, 14:35
Forum: HowTos and FAQ for TeNPy
Topic: Changing Bose-Hubbard model
Replies: 9
Views: 50891

Re: Changing Bose-Hubbard model

If you want to extend the BH model without rewriting everything, you can do sth like class MyExtendedBHModel(tenpy.BoseHubbardModel): def init_terms(self, model_params): super().init_terms(model_params) gamma = model_params.get('gamma', 0, 'real_or_array') for u in range(len(self.lat.unit_cell)): se...
by Jakob
02 Apr 2025, 14:33
Forum: HowTos and FAQ for TeNPy
Topic: Changing Bose-Hubbard model
Replies: 9
Views: 50891

Re: Changing Bose-Hubbard model

The term you want is called parity or 'P' in the BosonSite, with definition P = 1 - 2 (n \text{ mod } 2) = (-1)^n = \mathrm{exp}(\mathrm{i} \pi n) . So for H = \sum_i \gamma_i * \mathrm{exp}(\mathrm{i} \pi n_i) + H_\text{other} you could do something like def init_terms(self, model_params): ... # ot...
by Jakob
20 Mar 2025, 15:08
Forum: HowTos and FAQ for TeNPy
Topic: Converting to state vector gives wrong energy
Replies: 2
Views: 20503

Re: Converting to state vector gives wrong energy

See https://github.com/tenpy/tenpy/pull/495 for functions that export tenpy objects (MPS or Hamitlonians from a model) to full matrix representations.
by Jakob
19 Mar 2025, 10:05
Forum: HowTos and FAQ for TeNPy
Topic: Obtainin expectation value of number operator in BH model
Replies: 3
Views: 12613

Re: Obtainin expectation value of number operator in BH model

I assume you mean the Bose Hubbard model?
In what state do you want to take the expectation value?
If you want it in the groundstate, you can take an MPS psi resulting from DMRG and use
psi.expectation_value('N'), which gives you the particle number on every single site.
by Jakob
19 Mar 2025, 09:56
Forum: HowTos and FAQ for TeNPy
Topic: Converting to state vector gives wrong energy
Replies: 2
Views: 20503

Re: Converting to state vector gives wrong energy

tenpy, with charge conservation has a basis order that might be surprising. See e.g. the warning in Site So I assume that you are writing down H_sp in an incompatible basis (probably you use {|up>, |down>}, and if you use charge conservation, tenpy will use {|down>, |up>}). Have a look at model.lat....
by Jakob
14 Feb 2025, 16:27
Forum: HowTos and FAQ for TeNPy
Topic: DMRG on a IrregularLattice Transverse Field Ising Model
Replies: 3
Views: 43496

Re: DMRG on a IrregularLattice Transverse Field Ising Model

Confirmed that the workaround above works for my quick test.
For the fix see https://github.com/tenpy/tenpy/pull/481
by Jakob
14 Feb 2025, 16:05
Forum: HowTos and FAQ for TeNPy
Topic: DMRG on a IrregularLattice Transverse Field Ising Model
Replies: 3
Views: 43496

Re: DMRG on a IrregularLattice Transverse Field Ising Model

Hi, Looks like this is bug in the consistency_check ecosystem, specifically for IrregularLattices. TeNPy tries to warn users if the lattice has too large N_sites_per_ring. This check causes an error, because N_sites_per_ring is None for the IrregularLattice. I will push a fix soon. In the meantime y...
by Jakob
30 Jan 2025, 16:00
Forum: HowTos and FAQ for TeNPy
Topic: Ordering of exact diagonalization basis
Replies: 5
Views: 79452

Re: Ordering of exact diagonalization basis

Hi bart, just FYI that this will be resolved in the next version of tenpy, developed at https://github.com/tenpy/cyten. There, we consider this permutation in ``Tensor.to_numpy()`` such that it behaves as expected, i.e. such that ``.combine_legs(...).to_numpy()`` is equivalent to ``.to_numpy().resha...
by Jakob
16 Oct 2024, 13:00
Forum: HowTos and FAQ for TeNPy
Topic: How to convert between npc.Array and one dimension np.array efficiently?
Replies: 3
Views: 45174

Re: How to convert between npc.Array and one dimension np.array efficiently?

At first glance, I do not see why this code should raise such an error.
Please make sure you are using an up to date version of tenpy.
If the problem persists, please open an issue on github with a minimal code example that reproduces the bug, and include the full error message.
by Jakob
09 Oct 2024, 10:22
Forum: HowTos and FAQ for TeNPy
Topic: How to convert between npc.Array and one dimension np.array efficiently?
Replies: 3
Views: 45174

Re: How to convert between npc.Array and one dimension np.array efficiently?

For Array_to_ndarray, the low hanging fruits are to operate on numpy arrays instead of python lists. I probably would initialize a final_array of correct length (sum of the ``block.size`` for all blocks) and dtype, then in the loop set elements of the final_array to the block (keep somecounter varia...
by Jakob
18 Apr 2024, 05:49
Forum: HowTos and FAQ for TeNPy
Topic: Applying different time evolution to different subsystems with TEBD
Replies: 2
Views: 35478

Re: Applying different time evolution to different subsystems with TEBD

Hi, This can not be done out of the box. TEBD will also be difficult, since your gates are not nearest neighbour (even if H_i are NN on their subsystem, they are NNN on the full system). You could force TEBD by grouping sites to a nearest neighbour model. I would go for MPO time evolution though. Yo...
by Jakob
10 Apr 2024, 12:45
Forum: HowTos and FAQ for TeNPy
Topic: Matrix representation of dN operator
Replies: 1
Views: 10246

Re: Matrix representation of dN operator

Yes, you can have a look at the operator in the site In [3]: import tenpy as tp In [4]: site = tp.FermionSite(filling=0.5) In [5]: site.dN Out[5]: <npc.Array shape=(2, 2) labels=['p', 'p*']> In [6]: site.dN.to_ndarray() Out[6]: array([[-0.5, 0. ], [ 0. , 0.5]]) In[7]: # The basis is { |empty> , |ful...
by Jakob
31 Mar 2024, 20:58
Forum: HowTos and FAQ for TeNPy
Topic: Issue in running chiral_pi_flux.py
Replies: 4
Views: 34016

Re: Issue in running chiral_pi_flux.py

Hi,
Yes it turns out those examples are not yet updated for v1.0.
They should run with v0.99.
Working on a fix in https://github.com/tenpy/tenpy/pull/400.
Thanks for posting!