Skip to content

Commit

Permalink
Merge pull request #400 from tenpy/fix_examples
Browse files Browse the repository at this point in the history
Fix examples
  • Loading branch information
Jakob-Unfried committed May 2, 2024
2 parents e18ea2e + 06ef10b commit 4e96fd7
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 32 deletions.
8 changes: 4 additions & 4 deletions examples/advanced/central_charge_ising.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Example to extract the central charge from the entranglement scaling.
"""Example to extract the central charge from the entanglement scaling.
This example code evaluate the central charge of the transverse field Ising model using IDMRG.
This example code evaluate the central charge of the transverse field Ising model using iDMRG.
The expected value for the central charge c = 1/2. The code always recycle the environment from
the previous simulation, which can be seen at the "age".
Expand Down Expand Up @@ -43,10 +43,10 @@ def example_DMRG_tf_ising_infinite_S_xi_scaling(g):

t0 = time.time()
eng.reset_stats(
) # necessary if you for example have a fixed numer of sweeps, if you don't set this you option your simulation stops after initial number of sweeps!
) # necessary if you for example have a fixed number of sweeps, if you don't set this you option your simulation stops after initial number of sweeps!
eng.trunc_params['chi_max'] = chi
## DMRG Calculation ##
print("Start IDMRG CALCULATION")
print("Start iDMRG CALCULATION")
eng.run()
eng.options['mixer'] = None
psi.canonical_form()
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/xxz_corr_length.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Calculate the correleation legnth of the transferse field Ising model for various h_z.
"""Calculate the correlation length of the transverse field Ising model for various h_z.
This example uses DMRG to find the ground state of the transverse field Ising model when tuning
through the phase transition by changing the field `hz`. It uses
Expand Down
15 changes: 7 additions & 8 deletions examples/chern_insulators/chiral_pi_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ def init_terms(self, model_params):

for u1, u2, dx in self.lat.NN:
t1_phi = self.coupling_strength_add_ext_flux(t1, dx, [0, phi_ext])
self.add_coupling(t1_phi, u1, 'Cd', u2, 'C', dx, 'JW', True,
category='t1 Cd_i C_j', add_hc=True) # yapf: disable
self.add_coupling(t1_phi, u1, 'Cd', u2, 'C', dx, 'JW',
category='t1 Cd_i C_j', plus_hc=True) # yapf: disable
self.add_coupling(V, u1, 'N', u2, 'N', dx, category='V N_i N_j')

for u1, u2, dx in self.lat.nNNdashed:
t2_phi = self.coupling_strength_add_ext_flux(t2, dx, [0, phi_ext])
self.add_coupling(t2_phi, u1, 'Cd', u2, 'C', dx, 'JW', True,
category='t2 Cd_i C_j', add_hc=True) # yapf: disable
self.add_coupling(t2_phi, u1, 'Cd', u2, 'C', dx, 'JW',
category='t2 Cd_i C_j', plus_hc=True) # yapf: disable

for u1, u2, dx in self.lat.nNNdotted:
t2_phi = self.coupling_strength_add_ext_flux(t2, dx, [0, phi_ext])
self.add_coupling(-t2_phi, u1, 'Cd', u2, 'C', dx, 'JW', True,
category='-t2 Cd_i C_j', add_hc=True) # yapf: disable
self.add_coupling(-t2_phi, u1, 'Cd', u2, 'C', dx, 'JW',
category='-t2 Cd_i C_j', plus_hc=True) # yapf: disable


def plot_lattice():
Expand All @@ -99,7 +99,7 @@ def run(phi_ext=np.linspace(0, 1.0, 7)):

data = dict(phi_ext=phi_ext, QL=[], ent_spectrum=[])

model_params = dict(conserve='N', t=-1, V=0, mu=0, Lx=1, Ly=3, verbose=1)
model_params = dict(conserve='N', t=-1, V=0, mu=0, Lx=1, Ly=3)

dmrg_params = {
'mixer': True, # setting this to True helps to escape local minima
Expand All @@ -123,7 +123,6 @@ def run(phi_ext=np.linspace(0, 1.0, 7)):
'max_E_err': 1.e-10,
'max_S_err': 1.e-6,
'max_sweeps': 150,
'verbose': 1.,
}

prod_state = ['empty', 'full'] * (model_params['Lx'] * model_params['Ly'] * 2)
Expand Down
4 changes: 1 addition & 3 deletions examples/chern_insulators/haldane.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def run(model_params, phi_ext=np.linspace(0, 1.0, 7)):
'max_E_err': 1.e-10,
'max_S_err': 1.e-6,
'max_sweeps': 150,
'verbose': 1.,
}

prod_state = ['empty', 'full'] * (model_params['Lx'] * model_params['Ly'])
Expand Down Expand Up @@ -139,8 +138,7 @@ def plot_results(data):
order='default',
Lx=1,
Ly=3,
bc_y='cylinder',
verbose=0)
bc_y='cylinder')

# plot_model(model_params)
data = run(model_params)
Expand Down
19 changes: 9 additions & 10 deletions examples/chern_insulators/haldane_C3.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ def init_terms(self, model_params):

for u1, u2, dx in self.lat.NN:
t1_phi = self.coupling_strength_add_ext_flux(t1, dx, [0, phi_ext])
self.add_coupling(t1_phi, u1, 'CdA', u2, 'CB', dx, 'JW', True)
self.add_coupling(np.conj(t1_phi), u2, 'CdB', u1, 'CA', -dx, 'JW', True)
self.add_coupling(t1_phi, u1, 'CdA', u2, 'CB', dx, 'JW')
self.add_coupling(np.conj(t1_phi), u2, 'CdB', u1, 'CA', -dx, 'JW')
self.add_coupling(V, u1, 'Ntot', u2, 'Ntot', dx)

for u1, u2, dx in self.lat.nNNA:
t2_phi = self.coupling_strength_add_ext_flux(t2, dx, [0, phi_ext])
self.add_coupling(t2_phi, u1, 'CdA', u2, 'CA', dx, 'JW', True)
self.add_coupling(np.conj(t2_phi), u2, 'CdA', u1, 'CA', -dx, 'JW', True)
self.add_coupling(t2_phi, u1, 'CdA', u2, 'CA', dx, 'JW')
self.add_coupling(np.conj(t2_phi), u2, 'CdA', u1, 'CA', -dx, 'JW')

for u1, u2, dx in self.lat.nNNB:
t2_phi = self.coupling_strength_add_ext_flux(t2, dx, [0, phi_ext])
self.add_coupling(t2_phi, u1, 'CdB', u2, 'CB', dx, 'JW', True)
self.add_coupling(np.conj(t2_phi), u2, 'CdB', u1, 'CB', -dx, 'JW', True)
self.add_coupling(t2_phi, u1, 'CdB', u2, 'CB', dx, 'JW')
self.add_coupling(np.conj(t2_phi), u2, 'CdB', u1, 'CB', -dx, 'JW')

for u1, u2, dx in self.lat.nnNN:
t3_phi = self.coupling_strength_add_ext_flux(t3, dx, [0, phi_ext])
self.add_coupling(t3_phi, u1, 'CdA', u2, 'CB', dx, 'JW', True)
self.add_coupling(np.conj(t3_phi), u2, 'CdB', u1, 'CA', -dx, 'JW', True)
self.add_coupling(t3_phi, u1, 'CdA', u2, 'CB', dx, 'JW')
self.add_coupling(np.conj(t3_phi), u2, 'CdB', u1, 'CA', -dx, 'JW')


def plot_lattice():
Expand All @@ -117,7 +117,7 @@ def run(phi_ext=np.linspace(0, 1.0, 7)):

data = dict(phi_ext=phi_ext, QL=[], ent_spectrum=[])

model_params = dict(conserve='N', t=-1, V=0, Lx=1, Ly=3, verbose=1)
model_params = dict(conserve='N', t=-1, V=0, Lx=1, Ly=3)

dmrg_params = {
'mixer': True, # setting this to True helps to escape local minima
Expand All @@ -141,7 +141,6 @@ def run(phi_ext=np.linspace(0, 1.0, 7)):
'max_E_err': 1.e-10,
'max_S_err': 1.e-6,
'max_sweeps': 150,
'verbose': 1.,
}

prod_state = ['full_A empty_B', 'empty_A full_B', 'full_A empty_B'
Expand Down
4 changes: 1 addition & 3 deletions examples/chern_insulators/haldane_FCI.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def run(model_params, phi_ext=np.linspace(0, 2.0, 7)):
'max_E_err': 1.e-10,
'max_S_err': 1.e-6,
'max_sweeps': 150,
'verbose': 1.,
}

prod_state = [1]
Expand Down Expand Up @@ -152,8 +151,7 @@ def plot_results(data):
order='default',
Lx=1,
Ly=4,
bc_y='cylinder',
verbose=0)
bc_y='cylinder')

# plot_model(model_params)
data = run(model_params)
Expand Down
2 changes: 1 addition & 1 deletion examples/yaml/minimal_ExpMPOEvolution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final_time : 1.
# additional measurements during the evolution
connect_measurements:
- - tenpy.simulations.measurement
- onsite_expectation_value
- m_onsite_expectation_value
- opname: Sz
- - psi_method
- wrap correlation_function
Expand Down
2 changes: 1 addition & 1 deletion examples/yaml/minimal_TDVP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final_time : 1.
# additional measurements during the evolution
connect_measurements:
- - tenpy.simulations.measurement
- onsite_expectation_value
- m_onsite_expectation_value
- opname: Sz
- - psi_method
- wrap correlation_function
Expand Down
2 changes: 1 addition & 1 deletion examples/yaml/minimal_TEBD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final_time : 1.
# additional measurements during the evolution
connect_measurements:
- - tenpy.simulations.measurement
- onsite_expectation_value
- m_onsite_expectation_value
- opname: Sz
- - psi_method
- wrap correlation_function
Expand Down

0 comments on commit 4e96fd7

Please sign in to comment.