Giter VIP home page Giter VIP logo

netket_fidelity's Introduction

logo

NetKet

Release Anaconda-Server Badge Paper (v3) codecov Slack

NetKet is an open-source project delivering cutting-edge methods for the study of many-body quantum systems with artificial neural networks and machine learning techniques. It is a Python library built on JAX.

Installation and Usage

NetKet runs on MacOS and Linux. We recommend to install NetKet using pip, but it can also be installed with conda. It is often necessary to first update pip to a recent release (>=20.3) in order for upper compatibility bounds to be considered and avoid a broken installation. For instructions on how to install the latest stable/beta release of NetKet see the Get Started page of our website or run the following command (Apple M1 users, follow that link for more instructions):

pip install --upgrade pip
pip install --upgrade netket

If you wish to install the current development version of NetKet, which is the master branch of this GitHub repository, together with the additional dependencies, you can run the following command:

pip install --upgrade pip
pip install 'git+https://github.com/netket/netket.git#egg=netket[all]'

To speed-up NetKet-computations, even on a single machine, you can install the MPI-related dependencies by using [mpi] between square brackets.

pip install --upgrade pip
pip install --upgrade "netket[mpi]"

We recommend to install NetKet with all it's extra dependencies, which are documented below. However, if you do not have a working MPI compiler in your PATH this installation will most likely fail because it will attempt to install mpi4py, which enables MPI support in netket.

The latest release of NetKet is always available on PyPi and can be installed with pip. NetKet is also available on conda-forge, however the version available through conda install can be slightly out of date compared to PyPi. To check what is the latest version released on both distributions you can inspect the badges at the top of this readme.

Extra dependencies

When installing netket with pip, you can pass the following extra variants as square brakets. You can install several of them by separating them with a comma.

  • "[dev]": installs development-related dependencies such as black, pytest and testing dependencies
  • "[mpi]": Installs mpi4py to enable multi-process parallelism. Requires a working MPI compiler in your path
  • "[extra]": Installs tensorboardx to enable logging to tensorboard, and openfermion to convert the QubitOperators.
  • "[all]": Installs all extra dependencies

MPI Support

To enable MPI support you must install mpi4jax. Please note that we advise to install mpi4jax with the same tool (conda or pip) with which you install it's dependency mpi4py.

To check whether MPI support is enabled, check the flags

>>> import netket
>>> netket.utils.mpi.available
True

Getting Started

To get started with NetKet, we recommend you give a look at our tutorials page, by running them on your computer or on Google Colaboratory. There are also many example scripts that you can download, run and edit that showcase some use-cases of NetKet, although they are not commented.

If you want to get in touch with us, feel free to open an issue or a discussion here on GitHub, or to join the MLQuantum slack group where several people involved with NetKet hang out. To join the slack channel just accept this invitation

License

Apache License 2.0

netket_fidelity's People

Contributors

allesini99 avatar mboky avatar philipvinc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

netket_fidelity's Issues

Operators (Rx, Ry, Rz, Hadamard) do not support non-Spin Hilbert spaces.

Following the example code in the readme file, but changing the Hilbert space to Qubit instead of Spin results in only NaNs being calculated for the fidelity at every iteration. Changing the data type for higher precision did not make any difference.

import netket as nk
import netket_fidelity as nkf

# Create the Hilbert space and the variational states |ψ⟩ and |ϕ⟩
hi = nk.hilbert.Qubit(4)
sampler = nk.sampler.MetropolisLocal(hilbert=hi, n_chains_per_rank=16)
model = nk.models.RBM(alpha=1, param_dtype=complex)
phi = nk.vqs.MCState(sampler=sampler, model=model, n_samples=100)
psi = nk.vqs.MCState(sampler=sampler, model=model, n_samples=100)

# Transformation U
U = nkf.operator.Hadamard(hi, 0)

# Instantiate the operator to optimize the infidelity with U|ϕ⟩ by sampling from |ψ⟩ and |ϕ⟩
I_op = nkf.infidelity.InfidelityOperator(phi, U=U, U_dagger=U, is_unitary=True, cv_coeff=-1/2)

# Create the driver
optimizer = nk.optimizer.Sgd(learning_rate=0.01)
te =  nkf.driver.infidelity_optimizer.InfidelityOptimizer(phi, optimizer, U=U, U_dagger=U, variational_state=psi, is_unitary=True, cv_coeff=-0.5)

# Run the driver
te.run(n_iter=100)

Dispatch problem

I can't run netket fidelity with the latest version of netket. The problem seems to be related to dispatching:

    fid_opt.run(n_iter=n_iter, show_progress=show_inner_progress, out=inner_logger, callback=inner_callback())
  File "xxx/netket_fidelity/driver/infidelity_optimizer.py", line 187, in run
    super().run(n_iter, out, *args, callback=callbacks, **kwargs)
  File "xxx/netket/driver/abstract_variational_driver.py", line 255, in run
    for step in self.iter(n_iter, step_size):
  File "xxx/netket/driver/abstract_variational_driver.py", line 167, in iter
    dp = self._forward_and_backward()
  File "xxx/netket_fidelity/driver/infidelity_optimizer.py", line 145, in _forward_and_backward
    self._loss_stats, self._loss_grad = self.state.expect_and_grad(self._I_op)
  File "xxx/netket/vqs/mc/mc_state/state.py", line 604, in expect_and_grad
    return expect_and_grad(
  File "xxx/netket/utils/plum/function.py", line 366, in __call__
    return _convert(method(*args, **kw_args), return_type)
  File "xxx/netket/vqs/mc/mc_state/expect_grad.py", line 58, in expect_and_grad_default_formula
    Ō, Ō_grad = expect_and_forces(vstate, Ô, chunk_size, *args, mutable=mutable)

  File "xxx/netket/utils/plum/function.py", line 366, in __call__

    return _convert(method(*args, **kw_args), return_type)

  File "xxx/netket/vqs/mc/mc_state/expect_forces.py", line 48, in expect_and_forces
    σ, args = get_local_kernel_arguments(vstate, Ô)

  File "xxx/netket/utils/plum/function.py", line 365, in __call__
    method, return_type = self._resolve_method_with_cache(args=args)
  File "xxx/netket/utils/plum/function.py", line 396, in _resolve_method_with_cache
    method, return_type = self.resolve_method(args)
  File "xxx/netket/utils/plum/function.py", line 316, in resolve_method
    impl, return_type = self._handle_not_found_lookup_error(e)
  File "xxx/netket/utils/plum/function.py", line 325, in _handle_not_found_lookup_error
    raise ex from None
  File "xxx/netket/utils/plum/function.py", line 298, in resolve_method
    method = self._resolver.resolve(target)
  File "xxx/netket/utils/plum/resolver.py", line 293, in resolve
    raise NotFoundLookupError(self.function_name, target, self.methods)

it can't find the expect_and_grad of the type:

netket.utils.plum.resolver.NotFoundLookupError: 
get_local_kernel_arguments(MCState, op) could not be 
resolved.

where op is an existing netket operator.
This does work if I go back to the netket version before:
netket/netket@34bd4ad

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.