Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Latest commit

 

History

History
1011 lines (749 loc) · 46.5 KB

20495.md

File metadata and controls

1011 lines (749 loc) · 46.5 KB

Issue 20495: Add a function to generate random lattice (poset)

archive/issues_020258.json:

{
    "assignees": [],
    "body": "<div id=\"comment:0\"></div>\n\nThis patch will add a function to generate a random lattice with given number of elements.\n\nCurrently only \"dismantlable\" and \"planar\" are implemented as a property. Is this a good desing from user perspective? I hope to later add for example \"modular\", but of course most combinations will always just raise NotImplemented, as there are at least dozens of meaningful combinations that should be coded one by one.\n\nI am not satisfied of this code, but at least it works and is quite fast.\n\n\nCC:  @tscrim @fchapoton\n\nComponent: **combinatorics**\n\nKeywords: **latticeposet**\n\nAuthor: **Jori M\u00e4ntysalo**\n\nBranch/Commit: **[`5fc39b0`](https://github.com/sagemath/sagetrac-mirror/commit/5fc39b08f9ad24d57296b2e35c7a0552f126f715)**\n\nReviewer: **Travis Scrimshaw**\n\n_Issue created by migration from https://trac.sagemath.org/ticket/20495_\n\n",
    "closed_at": "2016-09-12T19:02:23Z",
    "created_at": "2016-04-24T07:37:53Z",
    "labels": [
        "https://github.com/sagemath/sage/labels/c%3A%20combinatorics",
        "https://github.com/sagemath/sage/labels/p%3A%20major%20/%203",
        "https://github.com/sagemath/sage/labels/enhancement"
    ],
    "milestone": "https://github.com/sagemath/sage/milestones/sage-7.4",
    "reactions": [],
    "repository": "https://github.com/sagemath/sage",
    "title": "Add a function to generate random lattice (poset)",
    "type": "issue",
    "updated_at": "2016-09-12T19:02:23Z",
    "url": "https://github.com/sagemath/sage/issues/20495",
    "user": "https://github.com/jm58660"
}

This patch will add a function to generate a random lattice with given number of elements.

Currently only "dismantlable" and "planar" are implemented as a property. Is this a good desing from user perspective? I hope to later add for example "modular", but of course most combinations will always just raise NotImplemented, as there are at least dozens of meaningful combinations that should be coded one by one.

I am not satisfied of this code, but at least it works and is quite fast.

CC: @tscrim @fchapoton

Component: combinatorics

Keywords: latticeposet

Author: Jori Mäntysalo

Branch/Commit: 5fc39b0

Reviewer: Travis Scrimshaw

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


archive/issue_events_286307.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-04-24T07:37:53Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/c%3A%20combinatorics",
    "label_color": "0000ff",
    "label_name": "c: combinatorics",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286307"
}

archive/issue_events_286308.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-04-24T07:37:53Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/p%3A%20major%20/%203",
    "label_color": "ffbb00",
    "label_name": "p: major / 3",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286308"
}

archive/issue_events_286309.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-04-24T07:37:53Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/enhancement",
    "label_color": "696969",
    "label_name": "enhancement",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286309"
}

archive/issue_events_286310.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-04-24T07:37:53Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/wishlist%20item",
    "label_color": "e81ff9",
    "label_name": "wishlist item",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286310"
}

archive/issue_comments_295837.json:

{
    "body": "Branch: **[u/jmantysalo/random-lattice](https://github.com/sagemath/sagetrac-mirror/tree/u/jmantysalo/random-lattice)**",
    "created_at": "2016-08-29T10:22:24Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295837",
    "user": "https://github.com/jm58660"
}

Branch: u/jmantysalo/random-lattice


archive/issue_comments_295838.json:

{
    "body": "Author: **Jori M\u00e4ntysalo**",
    "created_at": "2016-08-29T10:30:17Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295838",
    "user": "https://github.com/jm58660"
}

Author: Jori Mäntysalo


archive/issue_comments_295839.json:

{
    "body": "Description changed:\n``````diff\n--- \n+++ \n@@ -1 +1,6 @@\n-Add a function to generate a random lattice with given number of elements.\n+This patch will add a function to generate a random lattice with given number of elements.\n+\n+Currently only \"dismantlable\" is implemented as a property. Is this a good desing from user perspective? I hope to later add for example \"modular\", but of course most combinations will always just raise NotImplemented, as there are at least dozens of meaningful combinations that should be coded one by one.\n+\n+I am not satisfied of this code, but at least it works and is quite fast.\n+\n``````\n",
    "created_at": "2016-08-29T10:30:17Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295839",
    "user": "https://github.com/jm58660"
}

Description changed:

--- 
+++ 
@@ -1 +1,6 @@
-Add a function to generate a random lattice with given number of elements.
+This patch will add a function to generate a random lattice with given number of elements.
+
+Currently only "dismantlable" is implemented as a property. Is this a good desing from user perspective? I hope to later add for example "modular", but of course most combinations will always just raise NotImplemented, as there are at least dozens of meaningful combinations that should be coded one by one.
+
+I am not satisfied of this code, but at least it works and is quite fast.
+

archive/issue_comments_295840.json:

{
    "body": "<div id=\"comment:2\"></div>\n\nNew commits:\n<table><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/60eff31087c3784f997ae2f49bd5150e676fad85\"><code>60eff31</code></a></td><td><code>Add random lattice generation.</code></td></tr></table>\n",
    "created_at": "2016-08-29T10:30:17Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295840",
    "user": "https://github.com/jm58660"
}

New commits:

60eff31Add random lattice generation.

archive/issue_comments_295841.json:

{
    "body": "Commit: **[`60eff31`](https://github.com/sagemath/sagetrac-mirror/commit/60eff31087c3784f997ae2f49bd5150e676fad85)**",
    "created_at": "2016-08-29T10:30:17Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295841",
    "user": "https://github.com/jm58660"
}

Commit: 60eff31


archive/issue_events_286311.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-08-29T10:30:17Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/needs%20review",
    "label_color": "7fff00",
    "label_name": "needs review",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286311"
}

archive/issue_events_286312.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-08-29T10:30:17Z",
    "event": "milestoned",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "milestone_number": null,
    "milestone_title": "sage-7.4",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286312"
}

archive/issue_events_286313.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-08-29T10:30:17Z",
    "event": "unlabeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/wishlist%20item",
    "label_color": "e81ff9",
    "label_name": "wishlist item",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286313"
}

archive/issue_comments_295842.json:

{
    "body": "<div id=\"comment:3\" align=\"right\">comment:3</div>\n\nIf you pass in a tuple for the `properties`, e.g., `('dismantlable')`, it will result in an error. If you're going to compare it to a list, you should cast `properties` into a list. You should also future-proof your code by checking `properties[0] == 'dismantlable'`.\n\nAlso, I feel that `p = 0` should be acceptable and return a chain, as it is the unique lattice with the minimal number of cover relations.\n\nIs this model of random lattices known (i.e., is there a literature reference for it)?",
    "created_at": "2016-08-29T14:14:50Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295842",
    "user": "https://github.com/tscrim"
}
comment:3

If you pass in a tuple for the properties, e.g., ('dismantlable'), it will result in an error. If you're going to compare it to a list, you should cast properties into a list. You should also future-proof your code by checking properties[0] == 'dismantlable'.

Also, I feel that p = 0 should be acceptable and return a chain, as it is the unique lattice with the minimal number of cover relations.

Is this model of random lattices known (i.e., is there a literature reference for it)?


archive/issue_comments_295843.json:

{
    "body": "<div id=\"comment:4\" align=\"right\">comment:4</div>\n\nReplying to [@tscrim](#comment%3A3):\n> If you pass in a tuple for the `properties`, e.g., `('dismantlable')`, it will result in an error. If you're going to compare it to a list, you should cast `properties` into a list. You should also future-proof your code by checking `properties[0] == 'dismantlable'`.\n\nThe code must be something like\n\n```\nprops = ['dismantlable', 'modular', 'planar' . . .]\nfor p in properties:\n    if p not in props:\n        Raise ValueError(...)\n```\n\nBut the most important question is the \"interface\", that is hard to change later. What kind of parameters would be possible to have for different kind of lattices? What if type `x` lattices can have five different numerical parameters to choise from, and type `y` has two?\n\nOr maybe I am planning too much for a code not yet written.\n\n> Also, I feel that `p = 0` should be acceptable and return a chain, as it is the unique lattice with the minimal number of cover relations.\n\nActually it kind of works now, but generates a random semilattice with minimal number of covers, i.e. a tree, and then adds the top element. Would be strange if `p=0` would always give the chain and `p=0.001` would give a tree (+top).\n\n> Is this model of random lattices known (i.e., is there a literature reference for it)?\n\nI found only https://www.emis.de/journals/MB/125.2/mb125_2_1.pdf and the code in that paper is... Well, take a look at yourself.\n\nI don't know if there is even a theoretical results about \"random lattice\", like \"What is the average width of all non-isomorphic lattices on 100 elements?\" So is there anything to compare to be able to say how good or bad an algorithm is?",
    "created_at": "2016-08-29T15:00:41Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295843",
    "user": "https://github.com/jm58660"
}
comment:4

Replying to @tscrim:

If you pass in a tuple for the properties, e.g., ('dismantlable'), it will result in an error. If you're going to compare it to a list, you should cast properties into a list. You should also future-proof your code by checking properties[0] == 'dismantlable'.

The code must be something like

props = ['dismantlable', 'modular', 'planar' . . .]
for p in properties:
    if p not in props:
        Raise ValueError(...)

But the most important question is the "interface", that is hard to change later. What kind of parameters would be possible to have for different kind of lattices? What if type x lattices can have five different numerical parameters to choise from, and type y has two?

Or maybe I am planning too much for a code not yet written.

Also, I feel that p = 0 should be acceptable and return a chain, as it is the unique lattice with the minimal number of cover relations.

Actually it kind of works now, but generates a random semilattice with minimal number of covers, i.e. a tree, and then adds the top element. Would be strange if p=0 would always give the chain and p=0.001 would give a tree (+top).

Is this model of random lattices known (i.e., is there a literature reference for it)?

I found only https://www.emis.de/journals/MB/125.2/mb125_2_1.pdf and the code in that paper is... Well, take a look at yourself.

I don't know if there is even a theoretical results about "random lattice", like "What is the average width of all non-isomorphic lattices on 100 elements?" So is there anything to compare to be able to say how good or bad an algorithm is?


archive/issue_comments_295844.json:

{
    "body": "<div id=\"comment:5\" align=\"right\">comment:5</div>\n\nReplying to [@jm58660](#comment%3A4):\n> Replying to [@tscrim](#comment%3A3):\n> > If you pass in a tuple for the `properties`, e.g., `('dismantlable')`, it will result in an error. If you're going to compare it to a list, you should cast `properties` into a list. You should also future-proof your code by checking `properties[0] == 'dismantlable'`.\n> \n> \n> The code must be something like\n> \n> ```\n> props = ['dismantlable', 'modular', 'planar' . . .]\n> for p in properties:\n>     if p not in props:\n>         Raise ValueError(...)\n> ```\n\nYou can also do something like this:\n\n```python\nif not set('dismantlable', 'modular', 'planar', ...).is_superset(properties):\n    raise ValueError(\"invalid property\")\n```\n\n> But the most important question is the \"interface\", that is hard to change later. What kind of parameters would be possible to have for different kind of lattices? What if type `x` lattices can have five different numerical parameters to choise from, and type `y` has two?\n\nWe can easily add parameters and moderately easily change to an `*args` attribute if necessary.\n\n> Or maybe I am planning too much for a code not yet written.\n> \n> > Also, I feel that `p = 0` should be acceptable and return a chain, as it is the unique lattice with the minimal number of cover relations.\n> \n> \n> Actually it kind of works now, but generates a random semilattice with minimal number of covers, i.e. a tree, and then adds the top element. Would be strange if `p=0` would always give the chain and `p=0.001` would give a tree (+top).\n\nThe minimal number of covers has to be a chain, because a tree + top will have E+k covers, where k is the number leaves that is not the root and `E` is the number of edges of the tree. 2 leaves with one being the root minimizes `k`, which implies the tree must be a path/chain. So it is not strange to me because boundary points (at least for Gnp random graphs) can behave different.\n\n> > Is this model of random lattices known (i.e., is there a literature reference for it)?\n> \n> \n> I found only https://www.emis.de/journals/MB/125.2/mb125_2_1.pdf and the code in that paper is... Well, take a look at yourself.\n\nHmmm...I see your point. At least we could drop that C code in and link it easily in Sage to compare. Although it looks like it will generate a different distribution from a cursory look.\n\n> I don't know if there is even a theoretical results about \"random lattice\", like \"What is the average width of all non-isomorphic lattices on 100 elements?\" So is there anything to compare to be able to say how good or bad an algorithm is?\n\nWell, if its not known, it might result in a paper if you can determine some theoretical results. I was asking more if there was a reference that could be added.",
    "created_at": "2016-08-29T15:23:03Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295844",
    "user": "https://github.com/tscrim"
}
comment:5

Replying to @jm58660:

Replying to @tscrim:

If you pass in a tuple for the properties, e.g., ('dismantlable'), it will result in an error. If you're going to compare it to a list, you should cast properties into a list. You should also future-proof your code by checking properties[0] == 'dismantlable'.

The code must be something like

props = ['dismantlable', 'modular', 'planar' . . .]
for p in properties:
    if p not in props:
        Raise ValueError(...)

You can also do something like this:

if not set('dismantlable', 'modular', 'planar', ...).is_superset(properties):
    raise ValueError("invalid property")

But the most important question is the "interface", that is hard to change later. What kind of parameters would be possible to have for different kind of lattices? What if type x lattices can have five different numerical parameters to choise from, and type y has two?

We can easily add parameters and moderately easily change to an *args attribute if necessary.

Or maybe I am planning too much for a code not yet written.

Also, I feel that p = 0 should be acceptable and return a chain, as it is the unique lattice with the minimal number of cover relations.

Actually it kind of works now, but generates a random semilattice with minimal number of covers, i.e. a tree, and then adds the top element. Would be strange if p=0 would always give the chain and p=0.001 would give a tree (+top).

The minimal number of covers has to be a chain, because a tree + top will have E+k covers, where k is the number leaves that is not the root and E is the number of edges of the tree. 2 leaves with one being the root minimizes k, which implies the tree must be a path/chain. So it is not strange to me because boundary points (at least for Gnp random graphs) can behave different.

Is this model of random lattices known (i.e., is there a literature reference for it)?

I found only https://www.emis.de/journals/MB/125.2/mb125_2_1.pdf and the code in that paper is... Well, take a look at yourself.

Hmmm...I see your point. At least we could drop that C code in and link it easily in Sage to compare. Although it looks like it will generate a different distribution from a cursory look.

I don't know if there is even a theoretical results about "random lattice", like "What is the average width of all non-isomorphic lattices on 100 elements?" So is there anything to compare to be able to say how good or bad an algorithm is?

Well, if its not known, it might result in a paper if you can determine some theoretical results. I was asking more if there was a reference that could be added.


archive/issue_comments_295845.json:

{
    "body": "<div id=\"comment:6\" align=\"right\">comment:6</div>\n\nReplying to [@tscrim](#comment%3A5):\n\n> You can also do something like this:\n> \n> ```python\n> if not set('dismantlable', 'modular', 'planar', ...).is_superset(properties):\n>     raise ValueError(\"invalid property\")\n> ```\n\nBut then we can not raise exception saying *what* property was invalid.\n\n> We can easily add parameters and moderately easily change to an `*args` attribute if necessary.\n\nTrue. We could add something like `extra` parameter if needed for some special type of lattices.\n\n> > > Also, I feel that `p = 0` should be acceptable and return a chain, as it is the unique lattice with the minimal number of cover relations.\n> > \n> > \n> > Actually it kind of works now, but generates a random semilattice with minimal number of covers, i.e. a tree, and then adds the top element. Would be strange if `p=0` would always give the chain and `p=0.001` would give a tree (+top).\n> \n> \n> The minimal number of covers has to be a chain\n\nYes for lattices. Not for semilattices.\n\nBut after all, I don't know if we really have to think about semilattices. I did the code such way that internal function generates a semilattice, which can be used directly as a meet-semilattice, inversed as a join-semilattice or after adding one element as a lattice.\n\n> > > Is this model of random lattices known (i.e., is there a literature reference for it)?\n> > \n> > \n> > I found only https://www.emis.de/journals/MB/125.2/mb125_2_1.pdf and the code in that paper is... Well, take a look at yourself.\n> \n> \n> Hmmm...I see your point. At least we could drop that C code in and link it easily in Sage to compare. Although it looks like it will generate a different distribution from a cursory look.\n\nCan you copypaste and compile it from PDF? I think I tried and failed.\n\n> > I don't know if there is even a theoretical results about \"random lattice\", like \"What is the average width of all non-isomorphic lattices on 100 elements?\" So is there anything to compare to be able to say how good or bad an algorithm is?\n> \n> \n> Well, if its not known, it might result in a paper if you can determine some theoretical results. I was asking more if there was a reference that could be added.\n\nTrue. The paper http://users.cecs.anu.edu.au/~bdm/papers/posets.pdf actually refers to a result about posets: \"Our results do not show this behaviour, emphasizing again that the convergence of posets to their asymptotic behaviour is quite slow.\"\n\nBut at least the average number of atoms equals to number of coatoms. My ad hoc code does not achieve this. I used `sqrt(random())` as a slight help to this direction.\n\nI tested that my code generates all lattices of given (small) size eventually, and it should be theoretically clear too.",
    "created_at": "2016-08-29T16:35:48Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295845",
    "user": "https://github.com/jm58660"
}
comment:6

Replying to @tscrim:

You can also do something like this:

if not set('dismantlable', 'modular', 'planar', ...).is_superset(properties):
    raise ValueError("invalid property")

But then we can not raise exception saying what property was invalid.

We can easily add parameters and moderately easily change to an *args attribute if necessary.

True. We could add something like extra parameter if needed for some special type of lattices.

Also, I feel that p = 0 should be acceptable and return a chain, as it is the unique lattice with the minimal number of cover relations.

Actually it kind of works now, but generates a random semilattice with minimal number of covers, i.e. a tree, and then adds the top element. Would be strange if p=0 would always give the chain and p=0.001 would give a tree (+top).

The minimal number of covers has to be a chain

Yes for lattices. Not for semilattices.

But after all, I don't know if we really have to think about semilattices. I did the code such way that internal function generates a semilattice, which can be used directly as a meet-semilattice, inversed as a join-semilattice or after adding one element as a lattice.

Is this model of random lattices known (i.e., is there a literature reference for it)?

I found only https://www.emis.de/journals/MB/125.2/mb125_2_1.pdf and the code in that paper is... Well, take a look at yourself.

Hmmm...I see your point. At least we could drop that C code in and link it easily in Sage to compare. Although it looks like it will generate a different distribution from a cursory look.

Can you copypaste and compile it from PDF? I think I tried and failed.

I don't know if there is even a theoretical results about "random lattice", like "What is the average width of all non-isomorphic lattices on 100 elements?" So is there anything to compare to be able to say how good or bad an algorithm is?

Well, if its not known, it might result in a paper if you can determine some theoretical results. I was asking more if there was a reference that could be added.

True. The paper http://users.cecs.anu.edu.au/~bdm/papers/posets.pdf actually refers to a result about posets: "Our results do not show this behaviour, emphasizing again that the convergence of posets to their asymptotic behaviour is quite slow."

But at least the average number of atoms equals to number of coatoms. My ad hoc code does not achieve this. I used sqrt(random()) as a slight help to this direction.

I tested that my code generates all lattices of given (small) size eventually, and it should be theoretically clear too.


archive/issue_comments_295846.json:

{
    "body": "<div id=\"comment:7\"></div>\n\nBranch pushed to git repo; I updated commit sha1. New commits:\n<table><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/cd7104619519cee19b5c741888870d96d53f6ed2\"><code>cd71046</code></a></td><td><code>Add random planar lattices.</code></td></tr></table>\n",
    "created_at": "2016-08-30T12:50:42Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295846",
    "user": "https://github.com/sagetrac-git"
}

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

cd71046Add random planar lattices.

archive/issue_comments_295847.json:

{
    "body": "Changed commit from **[`60eff31`](https://github.com/sagemath/sagetrac-mirror/commit/60eff31087c3784f997ae2f49bd5150e676fad85)** to **[`cd71046`](https://github.com/sagemath/sagetrac-mirror/commit/cd7104619519cee19b5c741888870d96d53f6ed2)**",
    "created_at": "2016-08-30T12:50:42Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295847",
    "user": "https://github.com/sagetrac-git"
}

Changed commit from 60eff31 to cd71046


archive/issue_events_286314.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-08-30T12:53:42Z",
    "event": "unlabeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/needs%20review",
    "label_color": "7fff00",
    "label_name": "needs review",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286314"
}

archive/issue_events_286315.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-08-30T12:53:42Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/needs%20work",
    "label_color": "ffff00",
    "label_name": "needs work",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286315"
}

archive/issue_comments_295848.json:

{
    "body": "<div id=\"comment:8\" align=\"right\">comment:8</div>\n\nHow this looks? I think that this should still simplified, so that `RandomLattice` will contain only the parameters check and the logic to choise right function to do the job.",
    "created_at": "2016-08-30T12:53:42Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295848",
    "user": "https://github.com/jm58660"
}
comment:8

How this looks? I think that this should still simplified, so that RandomLattice will contain only the parameters check and the logic to choise right function to do the job.


archive/issue_comments_295849.json:

{
    "body": "Description changed:\n``````diff\n--- \n+++ \n@@ -1,6 +1,6 @@\n This patch will add a function to generate a random lattice with given number of elements.\n \n-Currently only \"dismantlable\" is implemented as a property. Is this a good desing from user perspective? I hope to later add for example \"modular\", but of course most combinations will always just raise NotImplemented, as there are at least dozens of meaningful combinations that should be coded one by one.\n+Currently only \"dismantlable\" and \"planar\" are implemented as a property. Is this a good desing from user perspective? I hope to later add for example \"modular\", but of course most combinations will always just raise NotImplemented, as there are at least dozens of meaningful combinations that should be coded one by one.\n \n I am not satisfied of this code, but at least it works and is quite fast.\n \n``````\n",
    "created_at": "2016-08-30T12:53:42Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295849",
    "user": "https://github.com/jm58660"
}

Description changed:

--- 
+++ 
@@ -1,6 +1,6 @@
 This patch will add a function to generate a random lattice with given number of elements.
 
-Currently only "dismantlable" is implemented as a property. Is this a good desing from user perspective? I hope to later add for example "modular", but of course most combinations will always just raise NotImplemented, as there are at least dozens of meaningful combinations that should be coded one by one.
+Currently only "dismantlable" and "planar" are implemented as a property. Is this a good desing from user perspective? I hope to later add for example "modular", but of course most combinations will always just raise NotImplemented, as there are at least dozens of meaningful combinations that should be coded one by one.
 
 I am not satisfied of this code, but at least it works and is quite fast.
 

archive/issue_comments_295850.json:

{
    "body": "<div id=\"comment:9\" align=\"right\">comment:9</div>\n\nI think you should make `known_properties` into a `set` for faster checking. (Actually, to still have your desired error message, you could do `if properties.difference(known_properties):`, then pop an element off from that different for the error message.) There is a discrepancy between the doc and the code in that the doc says `p=0` is valid input, but the code will error out. Otherwise it seems okay.",
    "created_at": "2016-08-30T14:27:33Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295850",
    "user": "https://github.com/tscrim"
}
comment:9

I think you should make known_properties into a set for faster checking. (Actually, to still have your desired error message, you could do if properties.difference(known_properties):, then pop an element off from that different for the error message.) There is a discrepancy between the doc and the code in that the doc says p=0 is valid input, but the code will error out. Otherwise it seems okay.


archive/issue_comments_295851.json:

{
    "body": "<div id=\"comment:10\"></div>\n\nBranch pushed to git repo; I updated commit sha1. New commits:\n<table><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/07ea77dcc7c146c652732ee269f72f6448d9d1ff\"><code>07ea77d</code></a></td><td><code>Some random :=) changes.</code></td></tr></table>\n",
    "created_at": "2016-08-31T09:16:56Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295851",
    "user": "https://github.com/sagetrac-git"
}

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

07ea77dSome random :=) changes.

archive/issue_comments_295852.json:

{
    "body": "Changed commit from **[`cd71046`](https://github.com/sagemath/sagetrac-mirror/commit/cd7104619519cee19b5c741888870d96d53f6ed2)** to **[`07ea77d`](https://github.com/sagemath/sagetrac-mirror/commit/07ea77dcc7c146c652732ee269f72f6448d9d1ff)**",
    "created_at": "2016-08-31T09:16:56Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295852",
    "user": "https://github.com/sagetrac-git"
}

Changed commit from cd71046 to 07ea77d


archive/issue_comments_295853.json:

{
    "body": "<div id=\"comment:11\"></div>\n\nBranch pushed to git repo; I updated commit sha1. New commits:\n<table><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/5fc39b08f9ad24d57296b2e35c7a0552f126f715\"><code>5fc39b0</code></a></td><td><code>Minor correction.</code></td></tr></table>\n",
    "created_at": "2016-08-31T09:18:44Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295853",
    "user": "https://github.com/sagetrac-git"
}

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

5fc39b0Minor correction.

archive/issue_comments_295854.json:

{
    "body": "Changed commit from **[`07ea77d`](https://github.com/sagemath/sagetrac-mirror/commit/07ea77dcc7c146c652732ee269f72f6448d9d1ff)** to **[`5fc39b0`](https://github.com/sagemath/sagetrac-mirror/commit/5fc39b08f9ad24d57296b2e35c7a0552f126f715)**",
    "created_at": "2016-08-31T09:18:44Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295854",
    "user": "https://github.com/sagetrac-git"
}

Changed commit from 07ea77d to 5fc39b0


archive/issue_events_286316.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-08-31T09:24:33Z",
    "event": "unlabeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/needs%20work",
    "label_color": "ffff00",
    "label_name": "needs work",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286316"
}

archive/issue_events_286317.json:

{
    "actor": "https://github.com/jm58660",
    "created_at": "2016-08-31T09:24:33Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/needs%20review",
    "label_color": "7fff00",
    "label_name": "needs review",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286317"
}

archive/issue_comments_295855.json:

{
    "body": "<div id=\"comment:12\" align=\"right\">comment:12</div>\n\nReplying to [@tscrim](#comment%3A9):\n> I think you should make `known_properties` into a `set` for faster checking. (Actually, to still have your desired error message, you could do `if properties.difference(known_properties):`, then pop an element off from that different for the error message.) There is a discrepancy between the doc and the code in that the doc says `p=0` is valid input, but the code will error out. Otherwise it seems okay.\n\nOK, done that, even if this should not be an issue: I suppose we wont have *that* many properties ever available.\n\nNow if someone says `Posets.RandomLattice(30, 0, properties='dismantlable')` it will also work, and not raise an error about parameter value 'd'. (See `set('hello')`.)\n\nI also rethinked something, but the algorithms themself have not changed. I added tests and docstrings.\n\nMaybe a time to close this and do other additions later. Will be a nice challenge, I guess, to make for example a random lattice that is both atomic and co-atomic.",
    "created_at": "2016-08-31T09:24:33Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295855",
    "user": "https://github.com/jm58660"
}
comment:12

Replying to @tscrim:

I think you should make known_properties into a set for faster checking. (Actually, to still have your desired error message, you could do if properties.difference(known_properties):, then pop an element off from that different for the error message.) There is a discrepancy between the doc and the code in that the doc says p=0 is valid input, but the code will error out. Otherwise it seems okay.

OK, done that, even if this should not be an issue: I suppose we wont have that many properties ever available.

Now if someone says Posets.RandomLattice(30, 0, properties='dismantlable') it will also work, and not raise an error about parameter value 'd'. (See set('hello').)

I also rethinked something, but the algorithms themself have not changed. I added tests and docstrings.

Maybe a time to close this and do other additions later. Will be a nice challenge, I guess, to make for example a random lattice that is both atomic and co-atomic.


archive/issue_comments_295856.json:

{
    "body": "<div id=\"comment:13\" align=\"right\">comment:13</div>\n\nI have already thinked about adding random atomic, distributive, modular and semimodular lattices. However I think it is easier to first integrate this patch to Sage and continue after that. Then patches are of manageable size.",
    "created_at": "2016-09-02T16:52:20Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295856",
    "user": "https://github.com/jm58660"
}
comment:13

I have already thinked about adding random atomic, distributive, modular and semimodular lattices. However I think it is easier to first integrate this patch to Sage and continue after that. Then patches are of manageable size.


archive/issue_comments_295857.json:

{
    "body": "<div id=\"comment:14\" align=\"right\">comment:14</div>\n\nJust pinging. I think I did nothing very special after your comment \"Otherwise it seems okay.\"\n\nThis would be nice to have, as this can used for testing other functions.",
    "created_at": "2016-09-10T06:29:15Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295857",
    "user": "https://github.com/jm58660"
}
comment:14

Just pinging. I think I did nothing very special after your comment "Otherwise it seems okay."

This would be nice to have, as this can used for testing other functions.


archive/issue_comments_295858.json:

{
    "body": "<div id=\"comment:15\" align=\"right\">comment:15</div>\n\nSorry, forgot about this. Yes, LGTM now. Thanks.",
    "created_at": "2016-09-10T12:18:43Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295858",
    "user": "https://github.com/tscrim"
}
comment:15

Sorry, forgot about this. Yes, LGTM now. Thanks.


archive/issue_events_286318.json:

{
    "actor": "https://github.com/tscrim",
    "created_at": "2016-09-10T12:18:43Z",
    "event": "unlabeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/needs%20review",
    "label_color": "7fff00",
    "label_name": "needs review",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286318"
}

archive/issue_events_286319.json:

{
    "actor": "https://github.com/tscrim",
    "created_at": "2016-09-10T12:18:43Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/positive%20review",
    "label_color": "dfffc0",
    "label_name": "positive review",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286319"
}

archive/issue_comments_295859.json:

{
    "body": "Reviewer: **Travis Scrimshaw**",
    "created_at": "2016-09-10T12:18:43Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295859",
    "user": "https://github.com/tscrim"
}

Reviewer: Travis Scrimshaw


archive/issue_comments_295860.json:

{
    "body": "<div id=\"comment:16\" align=\"right\">comment:16</div>\n\nThanks! Hopefully this will be used to test and optimize other parts of `lattices.py`.",
    "created_at": "2016-09-10T12:20:36Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295860",
    "user": "https://github.com/jm58660"
}
comment:16

Thanks! Hopefully this will be used to test and optimize other parts of lattices.py.


archive/issue_events_286320.json:

{
    "actor": "https://github.com/vbraun",
    "created_at": "2016-09-12T19:02:23Z",
    "event": "unlabeled",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "label": "https://github.com/sagemath/sage/labels/positive%20review",
    "label_color": "dfffc0",
    "label_name": "positive review",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286320"
}

archive/issue_events_286321.json:

{
    "actor": "https://github.com/vbraun",
    "commit_id": "1b404f3e0fa102a898bc70d70dea04c38f0ca956",
    "commit_repository": "https://github.com/sagemath/sage",
    "created_at": "2016-09-12T19:02:23Z",
    "event": "closed",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20495#event-286321"
}

archive/issue_comments_295861.json:

{
    "body": "Changed branch from **[u/jmantysalo/random-lattice](https://github.com/sagemath/sagetrac-mirror/tree/u/jmantysalo/random-lattice)** to **[`5fc39b0`](https://github.com/sagemath/sagetrac-mirror/commit/5fc39b08f9ad24d57296b2e35c7a0552f126f715)**",
    "created_at": "2016-09-12T19:02:23Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20495",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20495#issuecomment-295861",
    "user": "https://github.com/vbraun"
}

Changed branch from u/jmantysalo/random-lattice to 5fc39b0