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

SubHypergraphSearch #17309

Closed
nathanncohen mannequin opened this issue Nov 8, 2014 · 43 comments
Closed

SubHypergraphSearch #17309

nathanncohen mannequin opened this issue Nov 8, 2014 · 43 comments

Comments

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Nov 8, 2014

At long long long long last.

I have been wanting to write this for ages but never really needed it. And one should never implement something unless one needs it.

Here it is. It does what SubgraphSearch already does for graphs, but it does it for hypergraphs. The code is just a simple eunmeration of all possibilities, with a couple of cuts. The implementation tries to make this as cheap as possible.

We now have a IncidenceStructure.isomorphic_substructures_iterator whose name is similar to the new Poset.has_isomorphic_subposet.

Oh, and it does not work if the pattern you try to find had >64 points. It is already very large considering how hard it is to run this code anyway, plus making it work for >64 implied a +50% cost even for small instances on my use case. So I thought it was not worth it.

Right now it handles induced and non-induced hypergraph. Later, in another patch, it can be improved to deal with another definition of "substructure" and compute things like the VC-dimension, in case somebody cares.

CC: @jm58660 @dimpase @videlec @sagetrac-Stefan

Component: combinatorial designs

Author: Nathann Cohen

Branch/Commit: 5d7a241

Reviewer: Dima Pasechnik

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

@nathanncohen nathanncohen mannequin added this to the sage-6.4 milestone Nov 8, 2014
@nathanncohen nathanncohen mannequin added p: major / 3 labels Nov 8, 2014
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Nov 8, 2014

Branch: u/ncohen/17309

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Nov 8, 2014

Author: Nathann Cohen

@nathanncohen nathanncohen mannequin added the s: needs review label Nov 8, 2014
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 8, 2014

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

4c163fctrac #17309: SubHypergraphSearch

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 8, 2014

Commit: 4c163fc

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 8, 2014

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

9d3d155trac #17309: SubHypergraphSearch

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 8, 2014

Changed commit from 4c163fc to 9d3d155

@nathanncohen

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 16, 2014

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

3688bdbtrac #17309: SubHypergraphSearch
6b4ecebtrac #17309: Caching the traces and induced subgraphs of h2

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 16, 2014

Changed commit from 9d3d155 to 6b4eceb

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 26, 2014

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

ae1f014trac #17309: SubHypergraphSearch
8e8bde1trac #17309: Caching the traces and induced subgraphs of h2
6f2f204trac #17309: Bugfix

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 26, 2014

Changed commit from 6b4eceb to 6f2f204

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 25, 2014

Changed commit from 6f2f204 to 82b928a

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 25, 2014

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

82b928atrac #17309: SubHypergraphSearch

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Dec 25, 2014

comment:9

(it was conflicting with the latest beta)

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 24, 2015

comment:10

Guys ?... This feature is really cool, I swear. Plus you probably will not find it anywhere else..

@dimpase
Copy link
Member

dimpase commented Feb 25, 2015

comment:11

Do you iterate over embeddings of H in G, factoring out the automorphisms of H?
(i.e. if f is an automorphism of H, and g an embedding of H, do distinguish g(H) and g(H^f) ?)

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 25, 2015

comment:12

No, this code does not. It enumerates all labelled copies, and the number of copies of H that you will find in H is |aut(H)|.

@dimpase
Copy link
Member

dimpase commented Feb 25, 2015

comment:13

Replying to @nathanncohen:

No, this code does not. It enumerates all labelled copies, and the number of copies of H that you will find in H is |aut(H)|.

it should say distinct copies, or even distinct (unlabelled) copies.

@dimpase
Copy link
Member

dimpase commented Feb 25, 2015

comment:14

The stuff should be tested on a 32-bit system, just to make sure there is no arch-specific bugs...

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 25, 2015

comment:15

The stuff should be tested on a 32-bit system, just to make sure there is no arch-specific bugs...

Well, you can if you have one but I tried to be careful with respect to that and explicitly wrote uint64_t when I needed a 64-bits integer. Usually the 'int' variables that I use represent the vertex of a hypergraph, so I do not think that it will overflow anytime soon :-P

@dimpase
Copy link
Member

dimpase commented Feb 25, 2015

comment:16

Trying out the patch, I get

Error building the documentation.
Traceback (most recent call last):
  File "/home/dima/software/sage/src/doc/common/builder.py", line 1623, in <module>
    getattr(get_builder(name), type)()
  File "/home/dima/software/sage/src/doc/common/builder.py", line 296, in _wrapper
    getattr(get_builder(document), name)(*args, **kwds)
  File "/home/dima/software/sage/src/doc/common/builder.py", line 503, in _wrapper
    x.get(99999)
  File "/home/dima/software/sage/local/lib/python/multiprocessing/pool.py", line 558, in get
    raise self._value
OSError: [combinat ] /home/dima/software/sage/local/lib/python2.7/site-packages/sage/combinat/designs/__init__.py:docstring of sage.combinat.designs.__init__:32: WARNING: undefined label: sage.combinat.designs.subhypergraph_search (if the link has no caption the label must precede a section header)

make: *** [doc-html] Error 1

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 25, 2015

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

dad6191trac #17309: SubHypergraphSearch
c0d1d1ftrac #17309: Broken doc and typo

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 25, 2015

Changed commit from 82b928a to c0d1d1f

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 25, 2015

comment:18

That's because the documentation of the combinat/ folder now work in a different way from the rest of Sage's doc. It is meant to be distributed with no central index of files, and I had forgotten to add my new file to the new index of files it creates.

I also changed 'disjoint' into 'distinct unlabelled', and rebased everything on the latest beta.

Nathann

@dimpase
Copy link
Member

dimpase commented Feb 25, 2015

comment:19
+ As the automorphism group of `C_5` has size 10, the number of distinct
+ labelled copies is 12. 

it should say unlabelled

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 25, 2015

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

d83413atrac #17309: Broken doc and typo

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 25, 2015

Changed commit from c0d1d1f to d83413a

@dimpase
Copy link
Member

dimpase commented Feb 25, 2015

Reviewer: Dima Pasechnik

@dimpase
Copy link
Member

dimpase commented Feb 25, 2015

comment:21

Replying to @nathanncohen:

The stuff should be tested on a 32-bit system, just to make sure there is no arch-specific bugs...

Well, you can if you have one but I tried to be careful with respect to that and explicitly wrote uint64_t when I needed a 64-bits integer. Usually the 'int' variables that I use represent the vertex of a hypergraph, so I do not think that it will overflow anytime soon :-P

OK, it works both on 64 and 32 bit (arando is still alive).
LGTM.

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 25, 2015

comment:22

Wow ! Thank you very much.

Nathann

@vbraun
Copy link
Member

vbraun commented Feb 25, 2015

comment:23

I got this on OSX:

sage -t --long src/sage/combinat/designs/incidence_structures.py
**********************************************************************
File "src/sage/combinat/designs/incidence_structures.py", line 586, in sage.combinat.designs.incidence_structures.IncidenceStructure.isomorphic_substructures_iterator
Failed example:
    sum(1 for _ in IP.isomorphic_substructures_iterator(IC))
Expected:
    120
Got:
    0
**********************************************************************
File "src/sage/combinat/designs/incidence_structures.py", line 598, in sage.combinat.designs.incidence_structures.IncidenceStructure.isomorphic_substructures_iterator
Failed example:
    sum(1 for _ in IP.isomorphic_substructures_iterator(IC,induced=True))
Expected:
    120
Got:
    0
**********************************************************************
File "src/sage/combinat/designs/incidence_structures.py", line 606, in sage.combinat.designs.incidence_structures.IncidenceStructure.isomorphic_substructures_iterator
Failed example:
    sum(1 for _ in IP.isomorphic_substructures_iterator(IC))
Expected:
    420
Got:
    0
**********************************************************************
File "src/sage/combinat/designs/incidence_structures.py", line 608, in sage.combinat.designs.incidence_structures.IncidenceStructure.isomorphic_substructures_iterator
Failed example:
    sum(1 for _ in IP.isomorphic_substructures_iterator(IC,induced=True))
Expected:
    60
Got:
    0
**********************************************************************
File "src/sage/combinat/designs/incidence_structures.py", line 615, in sage.combinat.designs.incidence_structures.IncidenceStructure.isomorphic_substructures_iterator
Failed example:
    sum(1 for _ in H.isomorphic_substructures_iterator(H))
Expected:
    5616
Got:
    1
**********************************************************************
1 item had failures:
   5 of  16 in sage.combinat.designs.incidence_structures.IncidenceStructure.isomorphic_substructures_iterator
    [287 tests, 5 failures, 2.07 s]

Just as a stab in the dark, this is often a sign of comparisons by memory location somewhere. Somehow many Python objects end in different orders in ram on OSX.

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 26, 2015

comment:25

Can you give me access to an OSX machine ? I can't debug in the dark.

Nathann

@dimpase
Copy link
Member

dimpase commented Feb 26, 2015

comment:26

Replying to @nathanncohen:

Can you give me access to an OSX machine ? I can't debug in the dark.

If you can't find an OSX machine around, I can hook up a spare laptop running OSX so that you can ssh into it.Hopefully this will be fast enough. Do you still have access to arando box? Anyhow, you will need to ssh into arando, and from it to the laptop.
I'll have to figure out how to make ssh from laptop persistent.

Dima

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 26, 2015

comment:27

Hello,

If you can't find an OSX machine around, I can hook up a spare laptop running OSX so that you can ssh into it.Hopefully this will be fast enough. Do you still have access to arando box? Anyhow, you will need to ssh into arando, and from it to the laptop.

I just tried again the instructions you gave me on the 13/06/13 to connect to arando, but I got the following (on boxen):

ncohen@boxen:~$ ssh -p21925 localhost
ssh: connect to host localhost port 21925: Connection refused

A colleague of mine who has a Mac laptop "may" come in the afternoon. And if she is willing I "could" take it from her for a while, and compile Sage from its sources and stuff.

But really it would be cool if the same machine that Volker uses for his tests could be used for debugging, because really it is very very troublesome to get some code to work on an architecture that I do not have access to.

Nathann

@vbraun
Copy link
Member

vbraun commented Feb 26, 2015

comment:28

I can give you access, just email me your ssh key. The box is not always on, so let me know when you need it.

@dimpase
Copy link
Member

dimpase commented Feb 26, 2015

comment:29

Replying to @vbraun:

I can give you access, just email me your ssh key. The box is not always on, so let me know when you need it.

I think we're all set, Nathann uses an OSX laptop I hooked up via arando. At least it's not under any other load.

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 26, 2015

comment:30

I have spent severa hours on this bug, and all I can say right now is that after a call to qsort, what is sorted on my machine is not sorted on the OSX machine.

@vbraun
Copy link
Member

vbraun commented Feb 26, 2015

comment:31

Sounds like your comparison function is not a total order. This is illegal, and qsort behavior will be undefined (and different depending on the algorithm used by qsort, its often not quick sort but depends on the size of the input etc.).

@dimpase
Copy link
Member

dimpase commented Feb 26, 2015

comment:32
  The comparison function must return an integer less than, equal to, or greater than zero if the first
     argument is considered to be respectively less than, equal to, or greater than the second.

and you return True/False!

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 27, 2015

Changed commit from d83413a to 5d7a241

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 27, 2015

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

5d7a241trac #17309: Mac OS X ...

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 27, 2015

comment:34

and you return True/False!

That was it. The function returned 1 or 0, and Linux seemed to do the job alright with that. Mac OS X did not.

Nathann

@vbraun
Copy link
Member

vbraun commented Feb 28, 2015

Changed branch from u/ncohen/17309 to 5d7a241

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

2 participants