Code Monkey home page Code Monkey logo

Comments (11)

jotterbach avatar jotterbach commented on June 14, 2024

Thanks for reporting this @riyasett . Would it be possible for you to share the code-snippet that produced this error so I can try to reproduce this on my end?

from grove.

riyasett avatar riyasett commented on June 14, 2024

from grove.

jotterbach avatar jotterbach commented on June 14, 2024

@riyasett I can't seem to find the notebook. Maybe github email filtered it out?

from grove.

riyasett avatar riyasett commented on June 14, 2024

Oh, I am extremely sorry. I sent you the notebook through email. I am attaching it here again.
image

I cannot attach the notebook (.ipynb) here...

from grove.

jotterbach avatar jotterbach commented on June 14, 2024

hmm .. I unfortunately still can't see the full code to reproduce the error. Can you turn the notebook into a small script that I can run? You can also copy-and-paste the code you are running into a comment here.

from grove.

riyasett avatar riyasett commented on June 14, 2024

import numpy as np
import pyquil.api as api
from pyquil.paulis import PauliTerm, PauliSum
import networkx as nx
from scipy.optimize import minimize
from grove.pyqaoa.qaoa import QAOA
CXN = api.SyncConnection()

def print_fun(x):
print(x)

def maxcut_qaoa(graph, steps=1, rand_seed=None, connection=None, samples=None,
initial_beta=None, initial_gamma=None, minimizer_kwargs=None,
vqe_option=None):

if not isinstance(graph, nx.Graph) and isinstance(graph, list):
    maxcut_graph = nx.Graph()
    for edge in graph:
        maxcut_graph.add_edge(*edge)
    graph = maxcut_graph.copy()

cost_operators = []
driver_operators = []
for i, j in graph.edges():
    cost_operators.append(PauliTerm("Z", i, 0.5)*PauliTerm("Z", j) + PauliTerm("I", 0, -0.5))
for i in graph.nodes():
    driver_operators.append(PauliSum([PauliTerm("X", i, -1.0)]))

if connection is None:
    connection = CXN

if minimizer_kwargs is None:
    minimizer_kwargs = {'method': 'Nelder-Mead',
                        'options': {'ftol': 1.0e-2, 'xtol': 1.0e-2,
                                    'disp': False}}
if vqe_option is None:
    vqe_option = {'disp': print_fun, 'return_all': True,
                  'samples': samples}

qaoa_inst = QAOA(connection, len(graph.nodes()), steps=steps, cost_ham=cost_operators,
                 ref_hamiltonian=driver_operators, store_basis=True,
                 rand_seed=rand_seed,
                 init_betas=initial_beta,
                 init_gammas=initial_gamma,
                 minimizer=minimize,
                 minimizer_kwargs=minimizer_kwargs,
                 vqe_options=vqe_option)

return qaoa_inst

Sample Run:

Cutting 0 - 1 - 2 graph!

inst = maxcut_qaoa([(0, 1), (1, 2)], steps=2, rand_seed=42, samples=None)
betas, gammas = inst.get_angles()
probs = inst.probabilities(np.hstack((betas, gammas)))
for state, prob in zip(inst.states, probs):
print(state, prob)

print("Most frequent bitstring from sampling")
most_freq_string, sampling_results = inst.get_string(
betas, gammas)
print(most_freq_string)

from grove.

jotterbach avatar jotterbach commented on June 14, 2024

Thanks @riyasett, this will help me in reproducing your error!

from grove.

riyasett avatar riyasett commented on June 14, 2024

from grove.

jotterbach avatar jotterbach commented on June 14, 2024

@riyasett we just pushed a fix to master for your problem #109. Thanks @jonathanward for this. We will have a release of Grove coming up soon that will contain this fix.

from grove.

riyasett avatar riyasett commented on June 14, 2024

from grove.

jotterbach avatar jotterbach commented on June 14, 2024

@riyasett You're welcome! We just pushed a new release of grove. v1.4.0 I hope your problem is fixed there. I'll close this ticket, but feel free to reopen if you encounter the issue again!

from grove.

Related Issues (20)

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.