Skip to content

Some usability improvements for operators

Vicentini Filippo requested to merge github/fork/femtobit/pr into master

Created by: femtobit

This PR contains some usability improvements:

  1. Add __repr__ for operators (cf. #472):
>>> nk.operator.spin.sigmap(hi, 0) @ nk.operator.spin.sigmam(hi, 1)
LocalOperator(dim=16, local_dim=2, acting_on=[[0, 1]])
>>> nk.operator.Ising(hi, nk.graph.Chain(16), h=1.0)
Ising(J=1.0, h=1.0; dim=16)
>>> nk.operator.Heisenberg(hi, nk.graph.Chain(16))
Heisenberg(J=1, sign_rule=True; dim=16)
  1. Add copy for local operator (can be useful if you construct some combination of local operators using +=/*= etc. and want to reuse some intermediate operator):
>>> op = sigmaz(hi, 0)
>>> op2 = op.copy()
>>> op *= sigmaz(hi, 1)
>>> op, op2
(LocalOperator(dim=16, local_dim=2, acting_on=[[0, 1]]),
 LocalOperator(dim=16, local_dim=1, acting_on=[[0]]))
  1. Adds a better error message if Vmc.estimate is called before the first step (which fails since there are no pre-computed MC samples).

Merge request reports