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

dancing links: find all solutions in parallel #25125

Closed
seblabbe opened this issue Apr 9, 2018 · 58 comments
Closed

dancing links: find all solutions in parallel #25125

seblabbe opened this issue Apr 9, 2018 · 58 comments

Comments

@seblabbe
Copy link
Contributor

seblabbe commented Apr 9, 2018

Add all_solutions method so that one can do:

sage: S = Subsets(range(4))
sage: rows = map(list, S)
sage: dlx = dlx_solver(rows)
sage: dlx
Dancing links solver for 4 columns and 16 rows
sage: dlx.number_of_solutions()
15
sage: sorted([sorted(s) for s in dlx.all_solutions(ncpus=8)])
[[1, 2, 3, 4],
 [1, 2, 10],
 [1, 3, 9],
 [1, 4, 8],
 [1, 14],
 [2, 3, 7],
 [2, 4, 6],
 [2, 13],
 [3, 4, 5],
 [3, 12],
 [4, 11],
 [5, 10],
 [6, 9],
 [7, 8],
 [15]]

Component: combinatorics

Keywords: thursdaysbdx

Author: Sébastien Labbé

Branch/Commit: c985179

Reviewer: Julian Rüth, Vincent Delecroix, Vincent Klein

Issue created by migration from https://trac.sagemath.org/ticket/25125

@seblabbe seblabbe added this to the sage-8.2 milestone Apr 9, 2018
@seblabbe
Copy link
Contributor Author

seblabbe commented Apr 9, 2018

Commit: c4aa595

@seblabbe
Copy link
Contributor Author

seblabbe commented Apr 9, 2018

Branch: u/slabbe/25125

@seblabbe
Copy link
Contributor Author

seblabbe commented Apr 9, 2018

New commits:

c4aa59525125: add all_solutions method to dancing links

@mantepse
Copy link
Contributor

mantepse commented Apr 9, 2018

comment:3

spliting -> splitting

add a test / example for parallel?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 9, 2018

Branch pushed to git repo; I updated commit sha1. New commits:

71b868325125: fix doc

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 9, 2018

Changed commit from c4aa595 to 71b8683

@seblabbe
Copy link
Contributor Author

seblabbe commented Apr 9, 2018

comment:5

Since tests are often run in parallel, I know Volker does not like when doctests use more than one cpus. Instead I added a sentence explaining how to use ncpus argument.

re-needs_review.

@saraedum
Copy link
Member

comment:6

I think you forgot to set the "Author" on this ticket.

@saraedum
Copy link
Member

Reviewer: Julian Rüth

@saraedum
Copy link
Member

comment:7

I think it's a bit weird that the ncpus example does not actually set ncpus>1. It's understandable from your comment on the ticket why you did that but it's not understandable from looking at the code. I think it would be nice to add a comment to the docstring.

Why do you set ncpus=1 as a default? Shouldn't the default just be None? During doctests that is going to be "2" which seems to be Ok for doctesting, see ncpus.py.

@seblabbe
Copy link
Contributor Author

Author: Sébastien Labbé

@seblabbe
Copy link
Contributor Author

comment:9

Replying to @seblabbe:

I know Volker does not like when doctests use more than one cpus

For reference, here is the previous discussion on this aspect:
#24424 comment:3

At #24424, in the end, I wrote ncpus=2 in the doctests.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 12, 2018

Branch pushed to git repo; I updated commit sha1. New commits:

307381125125: setting ncpus=None as default

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 12, 2018

Changed commit from 71b8683 to 3073811

@saraedum
Copy link
Member

comment:12

If parallelity is what people usually want in #24424 as well, then None should be the default there as well I think.

@saraedum
Copy link
Member

comment:13

The docstrings do not really work anymore now. It's not explained what None means. Also the example about parallel computation is not really different from the "non-parallel" one that is parallel as well.

@seblabbe
Copy link
Contributor Author

comment:14

Ok, thanks for your comment. I will rework on this in a few days. I need to prepare for a travel.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 22, 2018

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

9448bfd25125: add all_solutions method to dancing links
f6257b825125: fix doc
876bfd325125: setting ncpus=None as default
606c15625125: improved sentences before some doctests
0a86ab2rewriting number_of_solutions method like one_solution and all_solutions

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 22, 2018

Changed commit from 3073811 to 0a86ab2

@seblabbe
Copy link
Contributor Author

comment:33

And are you able to reproduce the problem mentionned by Volker with commit a5c4667 ?

@vinklein
Copy link
Mannequin

vinklein mannequin commented May 22, 2018

comment:34

Yes ! I should have mentioned that.

@vinklein
Copy link
Mannequin

vinklein mannequin commented May 22, 2018

comment:35

​d13e0ec fix the problem.

@seblabbe
Copy link
Contributor Author

comment:36

Thanks for your help testing on OSX.

Sébastien

@vbraun
Copy link
Member

vbraun commented May 23, 2018

comment:37
sage -t --long src/sage/combinat/matrices/dancing_links.pyx
**********************************************************************
File "src/sage/combinat/matrices/dancing_links.pyx", line 683, in sage.combinat.matrices.dancing_links.dancing_linksWrapper.all_solutions
Failed example:
    [sorted(s) for s in S]
Expected:
    [[0, 1], [2, 3], [4, 5]]
Got:
    [[0, 1], [4, 5], [2, 3]]
**********************************************************************
1 item had failures:
   1 of  16 in sage.combinat.matrices.dancing_links.dancing_linksWrapper.all_solutions
    [215 tests, 1 failure, 7.16 s]

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 24, 2018

Changed commit from d13e0ec to 25da49e

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 24, 2018

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

9a158e625125: add all_solutions method to dancing links
89b590125125: fix doc
c54a64d25125: setting ncpus=None as default
cf7b43525125: improved sentences before some doctests
004126arewriting number_of_solutions method like one_solution and all_solutions
d18e09025125: allow reinitialization of dlx solver
c05e73b25125: reinitialize the dlx solver when needed
10f885d25125: Calling constructor dancing_links() only in reinitialize not in __init__
25da49e25125: sorted lists in doctests

@seblabbe
Copy link
Contributor Author

comment:40

Sorry Volker. I was sure that I put sorted everywhere needed, but I forgot one.

Rebased on 8.3.beta2.

I added a commit which added the sorted where the doctest problem occurs. I also added two other sorted elsewhere.

Needs review.

@vinklein
Copy link
Mannequin

vinklein mannequin commented May 29, 2018

comment:41

sage -t -a works on ubuntu and OSX ( except for ext_rep.py and external.py killed due to abort signal, which is not related to this ticket).

@vinklein
Copy link
Mannequin

vinklein mannequin commented May 29, 2018

comment:42

Random errors on dancing_links.pyx on OSX.

sage admin$ for i in `seq 0 50` ; do ./sage -t --long src/sage/combinat/matrices/dancing_links.pyx ; done
...
sage -t --long --warn-long 46.8 src/sage/combinat/matrices/dancing_links.pyx
    [215 tests, 5.41 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 5.5 seconds
    cpu time: 4.8 seconds
    cumulative wall time: 5.4 seconds
macbookpro-sierra-02:sage admin$ for i in `seq 0 50` ; do ./sage -t --long src/sage/combinat/matrices/dancing_links.pyx ; done
Running doctests with ID 2018-05-29-11-30-55-9317aab4.
Git branch: t/25125/25125
Using --optional=gfortran,gmpy2,mpir,python2,sage
Doctesting 1 file.
sage -t --long --warn-long 46.8 src/sage/combinat/matrices/dancing_links.pyx
**********************************************************************
File "src/sage/combinat/matrices/dancing_links.pyx", line 603, in sage.combinat.matrices.dancing_links.dancing_linksWrapper.one_solution
Failed example:
    sorted(d.one_solution())
Expected:
    [0, 1]
Got:
    [2, 3]
**********************************************************************
1 item had failures:
   1 of  17 in sage.combinat.matrices.dancing_links.dancing_linksWrapper.one_solution
    [215 tests, 1 failure, 5.46 s]
----------------------------------------------------------------------
sage -t --long --warn-long 46.8 src/sage/combinat/matrices/dancing_links.pyx  # 1 doctest failed
----------------------------------------------------------------------
Total time for all tests: 5.6 seconds
    cpu time: 4.9 seconds
    cumulative wall time: 5.5 seconds
Running doctests with ID 2018-05-29-11-31-04-c04446f2.
Git branch: t/25125/25125
Using --optional=gfortran,gmpy2,mpir,python2,sage
Doctesting 1 file.
sage -t --long --warn-long 46.8 src/sage/combinat/matrices/dancing_links.pyx
**********************************************************************
File "src/sage/combinat/matrices/dancing_links.pyx", line 634, in sage.combinat.matrices.dancing_links.dancing_linksWrapper.one_solution
Failed example:
    sorted(dlx.one_solution())
Expected:
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Got:
    [2, 3, 4, 5, 6, 7, 9, 10, 11, 18]
**********************************************************************
1 item had failures:
   1 of  17 in sage.combinat.matrices.dancing_links.dancing_linksWrapper.one_solution
    [215 tests, 1 failure, 5.42 s]
----------------------------------------------------------------------
sage -t --long --warn-long 46.8 src/sage/combinat/matrices/dancing_links.pyx  # 1 doctest failed

@vinklein vinklein mannequin added s: needs work and removed s: needs review labels May 29, 2018
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Changed commit from 25da49e to c985179

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Branch pushed to git repo; I updated commit sha1. New commits:

c98517925125: sorting every list even those of size one in doctests

@seblabbe
Copy link
Contributor Author

comment:45

Thanks for your carefull review Vincent K. We avoided a nuisance to Volker.

The failures you found come from the fact that we change the ncpus=1 to ncpus=None in the one_solution method which made deterministic doctests become not deterministic. If the doctest is run with more than one cpu, than the first solution found depend on the speed of the computation made on each cpus.

I made the doctests for one_solution independent of the first solution found.

I also added a bunch of sorted (even for list of size one!) to prevents other similar problem.

Hopefully, these were the last non deterministic doctests to be fixed.

Needs review.

@vinklein
Copy link
Mannequin

vinklein mannequin commented Jun 1, 2018

comment:46

All tests passed (with several iteration of sage -t ...dancing_links.pyx) both on unbuntu and osx.

@vbraun
Copy link
Member

vbraun commented Jun 2, 2018

Changed branch from u/slabbe/25125 to c985179

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

No branches or pull requests

5 participants