Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hilberts["Qubit"] = nk.hilbert.Qubit(graph=nk.graph.Hypercube(length=32, n_dim=1))
hilberts["Qubit n=1"] = nk.hilbert.Qubit()
# Custom Hilbert
hilberts["Custom Hilbert"] = nk.hilbert.CustomHilbert(
local_states=[-1232, 132, 0], graph=nk.graph.Hypercube(length=34, n_dim=1)
)
hilberts["Custom Hilbert n"] = nk.hilbert.CustomHilbert(
local_states=[-1232, 132, 0], n=2
)
# Heisenberg 1d
g = nk.graph.Hypercube(length=20, n_dim=1, pbc=True)
hi = nk.hilbert.Spin(s=0.5, total_sz=0.0, graph=g)
hilberts["Heisenberg 1d"] = hi
# Bose Hubbard
g = nk.graph.Hypercube(length=20, n_dim=1, pbc=True)
hi = nk.hilbert.Boson(n_max=4, n_bosons=20, graph=g)
hilberts["Bose Hubbard"] = hi
#
# Small hilbert space tests
#
# Spin 1/2
hilberts["Spin 1/2 Small"] = nk.hilbert.Spin(
s=0.5, graph=nk.graph.Hypercube(length=10, n_dim=1)
)
def test_no_segfault():
g = nk.graph.Hypercube(8, 1)
hi = nk.hilbert.Spin(g, 0.5)
lo = nk.operator.LocalOperator(hi, [[1, 0], [0, 1]], [0])
lo = lo.transpose()
hi = None
lo = lo * lo
assert True
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import netket as nk
# 1D Lattice
g = nk.graph.Hypercube(length=20, n_dim=1, pbc=True)
# Hilbert space of spins on the graph
hi = nk.hilbert.Spin(s=0.5, graph=g)
# Ising spin hamiltonian
ha = nk.operator.Ising(h=1.0, hilbert=hi)
# RBM Spin Machine
ma = nk.machine.RbmSpin(alpha=1, hilbert=hi)
ma.init_random_parameters(seed=1234, sigma=0.01)
# Metropolis Local Sampling
sa = nk.sampler.MetropolisLocal(machine=ma)
# Optimizer
op = nk.optimizer.Sgd(learning_rate=0.1)
# Stochastic reconfiguration
gs = nk.variational.Vmc(
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import netket as nk
# 1D Lattice
g = nk.graph.Hypercube(length=20, n_dim=1, pbc=True)
# Hilbert space of spins on the graph
# with total Sz equal to 0
hi = nk.hilbert.Spin(s=0.5, graph=g, total_sz=0)
# Heisenberg hamiltonian
ha = nk.operator.Heisenberg(hilbert=hi)
# Symmetric RBM Spin Machine
ma = nk.machine.JastrowSymm(hilbert=hi)
ma.init_random_parameters(seed=1234, sigma=0.01)
# Metropolis Exchange Sampling
# Notice that this sampler exchanges two neighboring sites
# thus preservers the total magnetization
sa = nk.sampler.MetropolisExchange(machine=ma, graph=g)
# Optimizer
op = nk.optimizer.Sgd(learning_rate=0.05)
edge_colors.append([w + L2 * h, w + 1 + L2 * (h - 1), 2])
elif pbc:
edge_colors.append([w + L2 * h, w + 1 + L2 * (L1 - 1), 2])
w = L2 - 1
if pbc:
edge_colors.append([L2 - 1 + L2 * h, L2 * h, 1])
edge_colors.append([w + L2 * h, L2 * ((h + 1) % L1), 2])
edge_colors.append([w + L2 * h, L2 * ((L1 + h - 1) % L1), 2])
if h < L1 - 1:
edge_colors.append([w + L2 * h, w + L2 * (h + 1), 1])
elif pbc:
edge_colors.append([w + L2 * h, w, 1])
g = netket.graph.CustomGraph(edge_colors)
if L1 * L2 % 2 == 0:
hi = netket.hilbert.Spin(s=0.5, total_sz=0.0, graph=g)
else:
hi = netket.hilbert.Spin(s=0.5, graph=g)
sigmaz = [[1, 0], [0, -1]]
sigmax = [[0, 1], [1, 0]]
sigmay = [[0, -1j], [1j, 0]]
interaction = numpy.kron(sigmaz, sigmaz) + numpy.kron(sigmax, sigmax) + numpy.kron(sigmay, sigmay)
bond_operator = [
(J[0] * interaction).tolist(),
(J[1] * interaction).tolist(),
]
bond_color = [1, 2]
return netket.operator.GraphOperator(hi, bondops=bond_operator, bondops_colors=bond_color)
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import netket as nk
# 2D Lattice
g = nk.graph.Hypercube(length=5, n_dim=2, pbc=True)
# Hilbert space of spins on the graph
hi = nk.hilbert.Spin(s=0.5, graph=g)
# Ising spin hamiltonian at the critical point
ha = nk.operator.Ising(h=3.0, hilbert=hi)
# RBM Spin Machine
ma = nk.machine.RbmSpin(alpha=1, hilbert=hi)
ma.init_random_parameters(seed=1234, sigma=0.01)
# Metropolis Local Sampling
sa = nk.sampler.MetropolisLocal(machine=ma)
# Optimizer
op = nk.optimizer.Sgd(learning_rate=0.1)
# Stochastic reconfiguration
gs = nk.variational.Vmc(
def total_spin_netket_operator(hilbert_state_shape):
edge_colors = []
for i in range(numpy.prod(hilbert_state_shape)):
edge_colors.append([i, i, 1])
g = netket.graph.CustomGraph(edge_colors)
hi = netket.hilbert.Spin(s=0.5, graph=g)
sigmaz = [[1, 0], [0, -1]]
sigmax = [[0, 1], [1, 0]]
sigmay = [[0, -1j], [1j, 0]]
interaction = numpy.kron(sigmaz, sigmaz) + numpy.kron(sigmax, sigmax) + numpy.kron(sigmay, sigmay)
bond_operator = [
(interaction).tolist(),
]
bond_color = [1]
return netket.operator.GraphOperator(hi, bondops=bond_operator, bondops_colors=bond_color)