Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbc.stitch(and_csp) #16

Closed
rog77 opened this issue May 6, 2021 · 2 comments
Closed

dbc.stitch(and_csp) #16

rog77 opened this issue May 6, 2021 · 2 comments

Comments

@rog77
Copy link

rog77 commented May 6, 2021

On colab, I copy over the file dwave-examples/factoring-notebook/blob/master/01-factoring-overview.ipynb from your github, though the open menu.

I insert a code cell at the top with:

!pip install dwave-ocean-sdk
!pip install dwavebinarycsp[maxgap]

(the second line is suggested by an error if the notebook is run without it)

I restart the runtime from the cell on colab, as per instructions from pip.

When I run the rest of the notebook, it hangs on:
and_bqm = dbc.stitch(and_csp)

With the following messages:

VisibleDeprecationWarning Traceback (most recent call last)
in ()
----> 1 and_bqm = dbc.stitch(and_csp)
2 and_bqm.remove_offset()
3
4 print("Linear coefficients:\n\t{}".format(
5 {key: round(val, 2) for key, val in and_bqm.linear.items()}))

10 frames
/usr/local/lib/python3.7/dist-packages/dwavebinarycsp/compilers/stitcher.py in stitch(csp, min_classical_gap, max_graph_size)
180 # try to use the penaltymodel ecosystem
181 try:
--> 182 pmodel = pm.get_penalty_model(spec)
183 except pm.ImpossiblePenaltyModel:
184 # hopefully adding more variables will make it possible

/usr/local/lib/python3.7/dist-packages/penaltymodel/core/interface.py in get_penalty_model(specification)
71 for factory in iter_factories():
72 try:
---> 73 pm = factory(specification)
74 except ImpossiblePenaltyModel as e:
75 # information about impossible models should be propagated

/usr/local/lib/python3.7/dist-packages/penaltymodel/lp/interface.py in get_penalty_model(specification)
57 linear_energy_ranges=specification.ising_linear_ranges,
58 quadratic_energy_ranges=quadratic_ranges,
---> 59 min_classical_gap=specification.min_classical_gap)
60 except ValueError:
61 raise pm.exceptions.FactoryException("Specification is for too large of a model")

/usr/local/lib/python3.7/dist-packages/penaltymodel/lp/generation.py in generate_bqm(graph, table, decision_variables, linear_energy_ranges, quadratic_energy_ranges, min_classical_gap, catch_warnings)
176 try:
177 result = linprog(cost_weights.flatten(), A_eq=noted_matrix, b_eq=noted_bound,
--> 178 A_ub=unnoted_matrix, b_ub=unnoted_bound, bounds=bounds)
179 except (OptimizeWarning, LinAlgWarning) as e:
180 raise ValueError('Penaltymodel-lp has a bad matrix')

/usr/local/lib/python3.7/dist-packages/scipy/optimize/_linprog.py in linprog(c, A_ub, b_ub, A_eq, b_eq, bounds, method, callback, options, x0)
552 x, status, message, iteration = _linprog_ip(
553 c, c0=c0, A=A, b=b, callback=callback,
--> 554 postsolve_args=postsolve_args, **solver_options)
555 elif meth == 'revised simplex':
556 x, status, message, iteration = _linprog_rs(

/usr/local/lib/python3.7/dist-packages/scipy/optimize/_linprog_ip.py in _linprog_ip(c, c0, A, b, callback, postsolve_args, maxiter, tol, disp, alpha0, beta, sparse, lstsq, sym_pos, cholesky, pc, ip, permc_spec, **unknown_options)
1123 lstsq, sym_pos, cholesky,
1124 pc, ip, permc_spec, callback,
-> 1125 postsolve_args)
1126
1127 return x, status, message, iteration

/usr/local/lib/python3.7/dist-packages/scipy/optimize/_linprog_ip.py in _ip_hsd(A, b, c, c0, alpha0, beta, maxiter, disp, tol, sparse, lstsq, sym_pos, cholesky, pc, ip, permc_spec, callback, postsolve_args)
753 d_x, d_y, d_z, d_tau, d_kappa = _get_delta(
754 A, b, c, x, y, z, tau, kappa, gamma, eta,
--> 755 sparse, lstsq, sym_pos, cholesky, pc, ip, permc_spec)
756
757 if ip: # initial point

/usr/local/lib/python3.7/dist-packages/scipy/optimize/_linprog_ip.py in _get_delta(A, b, c, x, y, z, tau, kappa, gamma, eta, sparse, lstsq, sym_pos, cholesky, pc, ip, permc_spec)
319
320 # [4] 8.12 and "Let alpha be the maximal possible step..." before 8.23
--> 321 alpha = _get_step(x, d_x, z, d_z, tau, d_tau, kappa, d_kappa, 1)
322 if ip: # initial point - see [4] 4.4
323 gamma = 10

/usr/local/lib/python3.7/dist-packages/scipy/optimize/_linprog_ip.py in _get_step(x, d_x, z, d_z, tau, d_tau, kappa, d_kappa, alpha0)
372 alpha_z = alpha0 * np.min(z[i_z] / -d_z[i_z]) if np.any(i_z) else 1
373 alpha_kappa = alpha0 * kappa / -d_kappa if d_kappa < 0 else 1
--> 374 alpha = np.min([1, alpha_x, alpha_tau, alpha_z, alpha_kappa])
375 return alpha
376

<array_function internals> in amin(*args, **kwargs)

/usr/local/lib/python3.7/dist-packages/numpy/core/fromnumeric.py in amin(a, axis, out, keepdims, initial, where)
2829 """
2830 return _wrapreduction(a, np.minimum, 'min', axis, None, out,
-> 2831 keepdims=keepdims, initial=initial, where=where)
2832
2833

/usr/local/lib/python3.7/dist-packages/numpy/core/fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
85 return reduction(axis=axis, out=out, **passkwargs)
86
---> 87 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
88
89

VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

** I get identical errors using dwavebinarycsp.stitch on my own PC as well.

Is this a code issue, or human error on my part?

Thanks!

@JoelPasvolsky
Copy link
Collaborator

Hi @rog77,

Can you try replacing your !pip install dwavebinarycsp[maxgap] line with

!pip install scipy==1.5.4
!pip install penaltymodel-maxgap==0.5.4

Also note that you might need to also install bokeh, as can be seen in the https://github.com/dwave-examples/factoring-notebook/blob/master/requirements.txt file.

@rog77
Copy link
Author

rog77 commented May 7, 2021

That sorted it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants