[go: up one dir, main page]

Skip to content

A semi-agnostic ansatz with variable structure for quantum machine learning - an implementation.

Notifications You must be signed in to change notification settings

matibilkis/qvans

Repository files navigation


VANs

A semi-agnostic ansatz with variable structure for quantum machine learning

This repository contains an implementation of A semi-agnostic ansatz with variable structure for quantum machine learning.

Table of Contents
  1. Overview
  2. Getting Started
  3. Usage
  4. Contributing

Overview

How would you walk through the architecture hyperspace to find your favorite quantum circuit? How to do so when both intuition and gradients vanish? Just go for our Variable Ansatz (VAns) algorithm!

* QML trains a parametrized quantum circuit to solve a given problem, encoded in some cost function. Depending on the circuit, this approach can potentially run into trouble, since trainability issues and quantum hardware noise essentially forbid the cost function to be minimized.
  • For this, we very much motivate the idea of optimizing both circuit parameters 𝗮𝗻𝗱 circuit structure in a semi-agnostic fashion 🤖 🤖.

  • This consists on randomly placing blocks of gates in the circuit, and accept or reject those modifications if the cost function is actually lowered or not. Crucially, we prevent the circuit from over-growing by applying some circuit-compression rules in a problem-informed way.

Logo

  • In turn, this mechanism gets the most out of the available quantum resources. For example, in VQE, we find that cost value (energy) is lower than that of the circuits usually employed, if using the same resources.

Logo

Built With

This implementation of |VANs> has been written in Python 3, using

Getting Started

How to use VANs on a local machine?

Prerequisites

Have Python 3 installed.

Installation

  1. Clone the repo
    git clone https://github.com/matibilkis/qvans.git
  2. Optional, but highly recommended. Create a virtual environment to avoid conflict with other dependencies
python3 -m virtualenv {NameOfVirtualEnv}

And activate the virtual environment

source {NameOfVirtualEnv}/bin/activate.sh
  1. Install libraries
    (NameOfVirtualEnv) pip3 install -r requirements.txt
  2. Now you are ready to use VANs!
(NameOfVirtualEnv) python3 meta_main.py
  1. You might also want to run the tutorials from the virtual environment and thus need to configure the jupyter notebook (that's why jupyter is included in the requirements.txt). To configure it, simple run
(NameOfVirtualEnv) ipython kernel --user --name NameOfVirtualEnv

Usage

The code we present comes with a series of pre-defined Hamiltonians and cost functions. It is up to the user to define new hamiltonians, which are Transverse Field Ising Model (TFIM), XXZ model, chemical hamiltonians (H2, H4, LiH) and the autoencoder.

Note that each of the pre-defined Hamiltonians has one (or more) free paramters, such as magnetic field strengths or bond lengths. This setting can be specified by parsing arguments to main.py file. For example, if willing to work with the TFIM, given by for a configuration of TFIM,

for n=4, J=0.5, g=1, we get

python3 main.py --problem TFIM --J 0.6 --g 1 --n_qubits 4

Importantly, the hyperparameters of the algorithm can be modified as well, feel free to peer at main.py file for all parsing arguments.

Finally, it is ussually of great utility to sweep over a certain parameter(s). To that end, we use the meta_main.py (where, at the cost of elegancy, some templates can be found under commented format). For instance, if willing to sweep over J values (say, from 0.5 to 1.5), one would modify meta_main.py by setting

```
insts=[]
js = np.arange(0.5,1.6,0.1)
for J in js:
    problem_config = dict_to_json({"problem" : "TFIM", "g":1.0, "J": bond})
    instruction = "python3 main.py --n_qubits 4 --problem_config {}".format(problem_config)
    insts.append(instruction)
```

and consequently run it:

python3 meta_main.py

Moreover, a series of tutorials have been written in order to demonstrate how to use VANs.

Contributing

Don't hesitate in getting in touch to contribute with this project :)

About

A semi-agnostic ansatz with variable structure for quantum machine learning - an implementation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published