Skip to content
This repository

Diagram Layout #1429

Merged
merged 87 commits into from over 1 year ago

6 participants

Sergiu Ivanov Don't Add Me To Your Organization a.k.a The Travis Bot Stefan Krastanov Tom Bachmann Aaron Meurer Ondřej Čertík
Sergiu Ivanov

This pull request adds the code which lays out the objects of a diagram, depending how they are connected with morphisms and some other parameters.

Some tests for this pull request still fail half of the time, because of the issue with FiniteSet sort keys. I do submit this pull request though so that people can start reviewing it, while I'll be fixing the FiniteSet issue in parallel.

Sergiu Ivanov scolobb referenced this pull request July 18, 2012
Merged

Diagram Drawing #1430

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 698063bc into be3da02).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@scolobb: Please fix the test failures.

Test command: setup.py test
master hash: be3da02
branch hash: 698063b

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY9sAhDA

Interpreter 2: :red_circle: There were test failures.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY6PIgDA

Interpreter 3: :red_circle: There were test failures.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY5_IgDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYprEhDA

Automatic review by SymPy Bot.

Tom Bachmann
Collaborator
ness01 commented July 20, 2012

Ok. I have been sequentially through all the commits. Almost everything is fine, except:

  • handling of cases where the algorithm does not succeed
  • DiagramGrid has absolutely no pretty printing
  • some nitpicking

Let me know when these are fixed, and I will look through the stuff again.

sympy/categories/diagram_drawing.py
((204 lines not shown))
  204
+    >>> h = NamedMorphism(D, A, "h")
  205
+    >>> k = NamedMorphism(D, B, "k")
  206
+    >>> diagram = Diagram([f, g, h, k])
  207
+
  208
+    Lay it out with generic layout:
  209
+
  210
+    >>> grid = DiagramGrid(diagram)
  211
+    >>> [grid[0, j] for j in xrange(grid.width)]
  212
+    [Object("A"), Object("B"), Object("D")]
  213
+    >>> [grid[1, j] for j in xrange(grid.width)]
  214
+    [None, Object("C"), None]
  215
+
  216
+    Now, we can group the objects `A` and `D` to have them near one
  217
+    another:
  218
+
  219
+    >>> grid = DiagramGrid(diagram, groups=FiniteSet(FiniteSet(A, D), B, C))
3
Tom Bachmann Collaborator
ness01 added a note July 22, 2012

I think the "groups" argument should accept arbitrary iterables (i.e. tuples, lists, sets, FiniteSets, whatever).

Sergiu Ivanov
scolobb added a note July 22, 2012

OK, done.

Tom Bachmann Collaborator
ness01 added a note August 05, 2012

Change this docstring to not make it look like you have to pass FiniteSey, just pass a list or tuple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sergiu Ivanov

Ok. I have been sequentially through all the commits. Almost everything is fine, except:

handling of cases where the algorithm does not succeed

Fixed.

DiagramGrid has absolutely no pretty printing

I will restate it here that DiagramGrid does not derive from Basic, so I'm not sure whether I can benefit from the standard printers. Therefore, do you think I should something like a grid (or objects) property to DiagramGrid, which will return the list of lists?

The point is that a DiagramGrid is really not meant to be printed. In fact, if one wants to see what it is, one is advised to make use of the XypicDiagramDrawer class from the other pull request :-)

some nitpicking

Fixed.

Let me know when these are fixed, and I will look through the stuff again.

I think I have visited and addressed all of your comments, save for pretty printing. I have therefore rebased this branch on top of the new master and pushed it here. I have also rebased the other pull request on this one (as this is how they are meant to be) and pushed it to GitHub as well.

Sergiu Ivanov

As you can see, I have added a dozen new commits. The first commit among these is fc39fd1, "DiagramGrid: Comment _triangle_objects and _other_vertex.". I did make some minor changes to the previous commits as well, but they are small in number and mostly insignificant, so I guess we will be fine if you only read through the new commits.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged a3471f39 into c84e5df).

Sergiu Ivanov

I believe these failures are related to the FiniteSet sort key issue, which I am going to address in a different pull request, then rebase this one upon that fix and modify the tests accordingly.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@scolobb: Please fix the test failures.

Test command: setup.py test
master hash: c84e5df
branch hash: a3471f3

Interpreter 1: :red_circle: There were test failures.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY7fIgDA

Interpreter 2: :red_circle: There were test failures.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY3KEhDA

Interpreter 3: :red_circle: There were test failures.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYmrkhDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYsNghDA

Automatic review by SymPy Bot.

Tom Bachmann
Collaborator
ness01 commented July 23, 2012
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 72adcfab into c84e5df).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@scolobb: Please fix the test failures.

Test command: setup.py test
master hash: 82b045f
branch hash: 72adcfa

Interpreter 1: :red_circle: There were test failures.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYuP8hDA

Interpreter 2: :red_circle: There were test failures.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY75YiDA

Interpreter 3: :red_circle: There were test failures.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYho8iDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYpa4iDA

Automatic review by SymPy Bot.

Sergiu Ivanov

This branch is now based on #1446. This has created a bit of a mess, sorry for that :-( I was too eager to finally see all the tests pass.

Let's have #1446 merged, and I will rebase this branch again, thereby removing those extraneous commits which now show at the beginning of the history.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged d1d0274a into 9ad73da).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 72e47f93 into 9ad73da).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@scolobb: Please fix the test failures.

Test command: setup.py test
master hash: 5e2cf47
branch hash: 72e47f9

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYlbYiDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYg-UiDA

Interpreter 3: :red_circle: There were test failures.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYr64iDA

Build HTML Docs: :eight_spoked_asterisk: All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY1vQiDA

Automatic review by SymPy Bot.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 16434d1b into 9ad73da).

Tom Bachmann
Collaborator

This needs rebasing.

Sergiu Ivanov

This needs rebasing.

Sure, done.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 860bd2e5 into 7d92368).

Sergiu Ivanov

The fix (hopefully) is in #1464. Sorry for the additional fuss.

added some commits June 17, 2012
Sergiu Ivanov Start the diagram_drawing module.
This commit adds the new module, a docstring, and the declaration of
DiagramOutline.  The class itself will be implemented later.
f679274
Sergiu Ivanov Add _GrowableGrid and corresponding tests.
This class represents a simple grid (two-dimensional array) which can be
grown in any of the four directions by appending empty rows and columns.
c999b2d
Sergiu Ivanov Have Diagram add components of composite morphisms automatically.
Previously, diagram would not add the components of composite morphisms.
This leaved some subtle ambiguities as to how to handle composite
morphisms which had some components not included into the diagram.  This
commit fixes those ambiguities.
baf28a4
Sergiu Ivanov Add some rudimentary tests for DiagramGrid.
The goal of having this tests is assuring that DiagramGrid.__new__ is
invoked.  Further tests will come together the corresponding
functionality.
4e53dbe
Sergiu Ivanov DiagramGrid: Simplify the premises and conclusions and merge them.
At the drawing stage, the separation between the premises and
conclusions of the diagram is not relevant; DiagramGrid discards this
separation.  If a morphism is included both in premises and in
conclusions, after the merging the morphism will have the properties it
had in conclusions.
285d64a
Sergiu Ivanov DiagramGrid: Build the undirected skeleton.
The skeleton of a diagram is the (undirected) graph whose vertices are
the objects of the diagram and which contains an edge between any pair
of objects between which in (the simplified, cf. previous commit)
diagram there is at least one morphism.  The skeleton also includes
edges between vertices A and C, such that there exists and object B
which is connected by at least one morphism with A and at least one
morphism with C.

The construction of this skeleton is one of the core tricks of the
layouting functionality.  The skeleton is constructed in such a way that
it can always be split into triangles.

Note that the term "skeleton" as used in the code, is defined ad-hoc.
824d760
Sergiu Ivanov DiagramGrid: Build meaningful triangles from the skeleton of the diag…
…ram.

DiagramGrid now sees which triangles are there in the skeleton, but also
discards the triangles which have less than 2 edges corresponding to
morphisms.  Such triangles may appear because of the how the skeleton is
constructed (cf. previous commit) and are irrelevant to laying the
diagram out, because only one edge of them will eventually be shown.
Note that such triangles are actually redundant in the sense that the
objects and morphisms they refer to will eventually be pulled into the
grid by other, more meaningful triangles.  This redundancy arises from
how the triangles are built and may be a point of further improvement
and/or optimisation.
a2c394e
Sergiu Ivanov DiagramGrid: Add some triangle utility functions.
This commit adds _triangle_objects which returns the set of vertices
of a triangle and _other_vertex, which, given a triangle and an edge,
returns the vertex which opposes the edge.
90ee353
Sergiu Ivanov DiagramGrid: Lay down the beginnings of the main construction loop.
This commit enables DiagramGrid to add the first edge to the layout and
introduces the (currently empty) function _weld_triangle, which welds
one triangle to the current fringe.

All triangles which are relevant to the plot are assumed to form a
prefix of the list of triangles.  Whether this is true will be later
revealed by further tests and the details of functionality.
75b080b
Sergiu Ivanov DiagramGrid: Find the place to attach a triangle to the existing fringe.
This commit adds and utilises _find_triangle_welding, which finds a
place in the fringe to weld the supplied triangle to.
23ecbc7
Sergiu Ivanov DiagramGrid: Prepare to fixing some of the degenerate situations in t…
…he fringe.

This commit adds _fix_degenerate which, given an edge from the fringe
and two points, checks whether one of the two points defines an edge,
which is in the fringe, and which is perpendicular on the given edge.
If such a situation is found, _fix_degenerate drops the two edges and
adds the corresponding diagonal to the fringe.
c287055
Sergiu Ivanov DiagramGrid: Decide how to place the outstanding vertex of the welded…
… triangle.

While _find_triangle_welding shows how to place one edge of the
triangle, it is important and nontrivial to decide where to place the
third vertex.  DiagramGrid is now capable to make this decision, while
also fixing some possible degenerate situations in the fringe.
cbde034
Sergiu Ivanov DiagramGrid: Finalise the basic layouting functionality.
DiagramGrid.__new__ now can cope with some simple diagrams.  It can
maybe cope with more complex diagrams; I don't know yet.
4cccb9a
Sergiu Ivanov DiagramGrid: Add _choose_target_cell.
This commit factors out the functionality of choosing one of the two
points above or below of a horizontal edge and to the left or to the
right of a vertical edge.  The new function will be later extended to
allow Diagram to avoid some of the intersections of the representations
of morphisms.
bd23826
Sergiu Ivanov DiagramGrid: Extend _choose_target_cell to choose the point better.
This commit enables _choose_target_cell (cf. previous commit) to
intelligently treat the situation when both points are free.  If this is
the case, the function now makes such a choice that, should the triangle
have only two visible edges, the edge different from the welding edge
will be drawn perpendicular to the welding edge.  This will eventually
help avoid some of the intersections of morphisms.
bfbda05
Sergiu Ivanov DiagramGrid: Use _put_object also to update the target cell.
If _put_object prepends the grid with a row or a column, the coordinates
of the target cell become different as well.  This must be taken into
account.
41703a2
Sergiu Ivanov DiagramGrid: Remove _fix_degenerate.
It turns out that the situations which I considered when implementing
_fix_degenerate are not at all degenerate.  Therefore, at the moment,
very little is done to minimise the size of the fringe after adding a
triangle to the grid.  I will analyse the question of keeping only the
outer edges of the structure in the fringe later.
ccbb32e
Sergiu Ivanov DiagramGrid: Keep track of the objects added to the diagram.
DiagramGrid now stops laying out the diagram when all objects have been
added to the grid.  Previously, it would zealously work on until all
triangles have been exhausted.
a74980a
Sergiu Ivanov DiagramGrid: Prefer going down and to the right when building diagrams.
This will in most cases result in a more natural placing of the objects
of the diagram, because of how humans read from left to right, from top
to bottom.
92b1fce
Sergiu Ivanov DiagramGrid: Fix the heuristics for welding triangles to vertical edges.
Before this commit DiagramGrid would wrongly choose where to put the
third vertex of the welded triangle, which would result in unnecessary
diagonal edges.
cb2c081
Sergiu Ivanov DiagramGrid: Assure independence of hash randomisation.
Previously DiagramGrid would often layout the same diagrams differently
because the list of triangles was sorted differently, depending on their
(randomised) hash.
0f1af7c
Sergiu Ivanov Don't derive DiagramGrid from Basic.
While DiagramGrid is essentially immutable, it does not model a
mathematical object and therefore should not be a subclass of Basic.
e509078
Sergiu Ivanov DiagramGrid: Store the grid of objects in the instance and offer acce…
…ss to it.

This commit makes it possible to use DiagramGrid from the outer world:
the class now stores the results of the analysis it has performed.
b67baa0
Sergiu Ivanov Add some proper tests for DiagramGrid.
Since DiagramGrid is already usable now, it is now possible to test how
some simple diagrams are laid out.
5fa96dd
Sergiu Ivanov DiagramGrid: Don't re-place objects on the grid.
After each new triangle placed in the grid, forget all triangles which
only include objects which have already been placed on the grid.
24a675c
Sergiu Ivanov DiagramGrid: Add a test for a strange diagram.
This test attempts to use DiagramGrid to lay out a diagram which
resulted from a typo in an attempt to lay out the  the five lemma.
DiagramGrid currently fails to lay it out properly because of
the fact that en route it encounters a situation where none of the
remaining triangles can be welded to the already constructed structure.
515ae01
Sergiu Ivanov DiagramGrid: Attach triangles by vertices when this cannot be done by…
… edges.

This commit enables DiagramGrid to lay out more complex diagrams, like
the five lemma.  Generally, using the function _grow_pseudopod, added in
this commit, should be avoided for as long as possible, and this is what
DiagramGrid currently does.
9761974
Sergiu Ivanov DiagramGrid: Test how DiagramGrid lays out a cube diagram.
The new test requires DiagramGrid to lay out a cube.  Rather obviously,
the result is not a cube, because of how DiagramGrid is designed.
42ccc71
Sergiu Ivanov DiagramGrid: Test a pullback.
This test currently fails because the loop in the constructor of
DiagramGrid fails to distinguish between the situations when
_weld_triangle has not found a welding and when it has corrected the
fringe and thus requires a restart of the search for weldings.
2be0f5c
Sergiu Ivanov DiagramGrid: Distinguish between welding failures and restarts.
The loop in the constructor DiagramGrid now can distinguish between the
situations when _weld_triangle has not found any welding and when it has
corrected the fringe and requires a restart of the process.  This makes
the test added in the previous commit pass.
8d3e193
Sergiu Ivanov DiagramGrid: Lay out one-morphism diagrams as well.
This commit also adds a corresponding test.
86d325b
Sergiu Ivanov Diagram: Add is_subdiagram and test it.
This method checks whether its argument is a subdiagram of self.
49f2ed3
Sergiu Ivanov Diagram: Fix the mess in handling conclusions.
Diagram would previously add the components of composite morphisms which
belonged to conclusions, which would clutter the conclusions.
Furthermore, it wouldn't sometimes properly add properties to the
morphisms in conclusions.  This commit fixes all of these.
4d88b4b
Sergiu Ivanov Diagram: Add subdiagram_from_objects.
This method returns a subdiagram of self which includes the objects
supplied in the argument.
ee8bbdc
Sergiu Ivanov DiagramGrid: Add the possibility to lay out diagrams in logical groups.
The constructor of DiagramGrid now accepts the argument groups, which
specifies groups of objects to be laid out independently from the others
in their own group.  This commit also adds the corresponding tests.
1fd263f
Sergiu Ivanov DiagramGrid: Test the five lemma.
I have just discovered that what I initially thought to be tests for the
five lemma has turned to be a weird diagram resulted from a typo.  This
commit adds the test for five lemma proper.
d246cbf
Sergiu Ivanov DiagramGrid: Test the five lemma with grouping of objects.
Grouping objects allows laying diagrams out in better structures.  For
example, with grouping, it is possible to make the automated layout of
the five lemma look more like how it is usually drawn by hand.
731e099
Sergiu Ivanov Make _GrowableGrid and DiagramGrid derive from object.
This transforms these classes into new-style classes.
fab82b6
Sergiu Ivanov DiagramGrid: Factor out the generic laying out functionality.
In the future, the constructor of DiagramGrid will live through further
enhancements, like hints, which makes it important to push what it does
to a higher level of abstraction.
43a9dc5
Sergiu Ivanov DiagramGrid: Implement the sequential layout for diagrams.
This layout method attempts to place the objects as closed to a line as
possible.  This commit also adds the corresponding tests.
b173213
Sergiu Ivanov DiagramGrid.__init__: Rearrange the code in a big if statement.
This commit makes the code in the constructor of DiagramGrid more
orderly and easy to extend later.
1dfd0e4
Sergiu Ivanov DiagramGrid: Implement the transpose hint.
If transpose == True, the constructor of DiagramGrid will transpose the
resulting grid.
236425c
Sergiu Ivanov DiagramGrid: Test the layout of a pullback with sequential layout.
This test is there just for stress testing the sequential layout,
because the pullback doesn't really look like nice when laid out with
this strategy.
24f0f5a
Sergiu Ivanov DiagramGrid: Rename hint "shape" to "layout". 6bd40c0
Sergiu Ivanov DiagramGrid: Rearrange the tests a bit.
This commit assures a slightly better logical grouping of the tests.
ff5223f
Sergiu Ivanov DiagramGrid: Support hints in groups as well.
Using only the two supported hints it is not possible to lay out the
five lemma almost exactly as it is normally laid out.  This commit adds
a test to show off this new capability.
84f50b2
Sergiu Ivanov DiagramGrid: Test a pull back laid out with generic layout.
Somewhere in the past I have accidentally removed the tests for a pull
back laid out with generic layout.  This test brings that code back.
38e0681
Sergiu Ivanov DiagramGrid._triangle_key: Remove the necessity of objects to have na…
…mes.

This method used to produced a key for sorting the triangles which was
dependent on objects having names.  This would fail for groups, where
objects are FiniteSet's.

Note that this method currently sorts the set of objects in order to
avoid the problem of the sort key of FiniteSet being different in
dependence of the order of the elements in it.
b421413
Sergiu Ivanov DiagramGrid._handle_groups: Fix a bug in copying child grids. 2b700da
Sergiu Ivanov DiagramGrid: Write an extensive docstring.
This docstring includes explanations and examples for all features
available to the user.
20f9625
Sergiu Ivanov DiagramGrid: Add examples for width, height, and __getitem__. ce5ec82
Sergiu Ivanov docs/modules/categories.rst: Add a reference to DiagramGrid. fec3bc0
Sergiu Ivanov diagram_drawing: Describe the layout algorithm in the module docstring. 0cae466
Sergiu Ivanov DiagramGrid: Store the simplified and merged morphisms.
This commit adds the property morphisms which returns the dictionary
mapping those morphisms to their properties which were considered worthy
by the constructor of DiagramGrid.
1c1e149
Sergiu Ivanov DiagramGrid: Sort the vertices in the root triangle.
Previously DiagramGrid would not sort the vertices in the edges of
the first triangle, out of which the root edge was picked.  This resulted
in different edges being sometimes picked, as well arbitrary positioning
of the vertices of the root edge.
cbfdf55
Sergiu Ivanov DiagramGrid: Don't use "loop" morphisms in laying out objects.
"Loop" morphisms are morphisms which have the same domains and
codomains.  They will be eventually drawn as loops and should not
influence the layout of the diagram.
de5a5b2
Sergiu Ivanov DiagramGrid: Comment _triangle_objects and _other_vertex.
The code of these two functions might be a little bit difficult to
comprehend; this commits adds what I believe to be extensive comments
explaining how and why these methods work.
8c7ae4f
Sergiu Ivanov Rename Diagram._add_morphism -> Diagram._add_morphism_closure.
The new name describes what the method does a little bit better, and
also removes the possible confusion with
CompositeMorphism._add_morphism.
c738ab8
Sergiu Ivanov DiagramGrid._merge_premises_conclusions: Use itertools.chain.
This simplifies the method and outsources the functionality to better
functions.
4926c1e
Sergiu Ivanov Fix some minor typos and space issues in DiagramGrid-related code. c679614
Sergiu Ivanov DiagramGrid: Use set's and frozenset's instead of FiniteSet.
This commit changes the code which needs sets for internal operations to
use the builtins set and frozenset instead of FiniteSet.
64d6242
Sergiu Ivanov DiagramGrid: Fix some redundant line breaks.
In a number of places (especially in list comprehensions) I used the
backslash to assure proper interpretation; it turns out a number of such
backslashes were not necessary.
3a0342b
Sergiu Ivanov _compute_triangle_min_sizes: Explain why this metric.
This commit adds a high-level explanation of the heuristic triangle
metric implemented in this function.
d7bb7e4
Sergiu Ivanov DiagramGrid._put_object: Make ``offset`` values clearer. 3e3d55e
Sergiu Ivanov DiagramGrid: Refactor _weld_triangle.
This method used to melange the missions of finding the triangle to weld
and actually welding the triangle.  This resulted in the necessity to
return a triangle or one of the two status codes.  This commit fixes
this ugliness by better splitting the functionality between __init__,
_weld_triangle and _find_triangle_welding (which is not called
_find_triangle_to_weld).
df16cfd
Sergiu Ivanov DiagramGrid: Store edges in two-element frozensets.
This commit transitions from storing edges as two-element tuples to
storing them as frozensets.  The rationale behind this change is that
the edges of the skeleton are undirected, which makes storing them in
tuples inconvenient and results in a lot of uglier code.
9977109
Sergiu Ivanov DiagramGrid: Add _get_undirected_graph.
This commit factors out of _sequential_layout the code producing the
adjacency lists of the underlying undirected graph of the diagram.
528318f
Sergiu Ivanov DiagramGrid: Add support for disconnected diagrams.
DiagramGrid is now capable of laying out disconnected diagrams by laying
out each connected component separately.  The grids of each of the
connected components are arranged in a line.  This is a place where
further improvements could be introduced.
ddfd51f
Sergiu Ivanov DiagramGrid: Support one-object diagrams.
While one doesn't construct one-object diagrams every day, this is a
valid edge case that has to be supported.  Furthermore, laying out
one-object diagrams will be useful for some internal purposes (see the
next commits).
5a3d764
Sergiu Ivanov DiagramGrid: Handle the situations when growing a pseudopod fails.
While I initially supposed that reaching such situations would be
difficult, it proved quite easy to get there by setting up a "star"
diagram, with many morphisms coming out of a central object.  This
commit adds the code to handle such situations and actually lay out all
objects.
7821c42
Sergiu Ivanov Diagram: Disallow identity morphisms to have properties.
Identity morphisms are trivial and properties for them do not make
sense.  This should not be confused with nontrivial morphisms with
the same domain and codomain, which are instances of NamedMorphism and
can always be annotated with properties.
ef2dc14
Sergiu Ivanov DiagramGrid: Use implicit generator expressions where possible.
This commit fixes the expressions func([<generator-expression>]) to look
like func(<generator-expression>), i.e., removes the redundant square
brackets.
dcfc319
Sergiu Ivanov DiagramGrid: Check out the transpose hint nicer.
Previously, the code would check out the value of the transpose hint
using two if statements.  Now it does so in one if statement.
0686a9e
Sergiu Ivanov DiagramGrid._handle_groups: Add lay_out_group.
Previously, the part of _handle_groups that laid out each of the group
would consist of two largely similar halves: one that processed groups
supplied as an array of FiniteSet's, and the other one which processed
groups as a dictionary mapping groups to their hints.  This commit
factors out the common part into lay_out_group.
efb8858
Sergiu Ivanov DiagramGrid: Support any iterable to describe groups.
Previously DiagramGrid would only agree if groups were supplied as
FiniteSet's of FiniteSet's.  This commit enables DiagramGrid to cope
with any iterable type.  The test added hereby shows how this can be
utilised.
0d69ed4
Sergiu Ivanov DiagramGrid: Add LaTeX pretty printing and __str__.
This makes DiagramGrid easier to show in doctests and, probably, easier
to use.  Pretty printing to string will come in the next commits.
8292883
Sergiu Ivanov DiagramGrid: Upgrade the docstrings to use string printing.
Previously, the docstrings would print the grid object by object.  Now
it relies on DiagramGrid.__str__ to show the contents of the grid.
93533c7
Sergiu Ivanov Factor _print_matrix_contents out of _print_MatrixBase.
This commit adds to the string pretty printer the method
_print_matrix_contents which only carries that part of the previous
version of _print_MatrixBase which refers to printing the grid.
_print_MatrixBase now only puts this grid in brackets.

The motivation behind this commit is that grid printing is useful in
itself and thus should be available as a separate method.  See the next
commit for an example of such usage.
b7e5772
Sergiu Ivanov DiagramGrid: Add string pretty printing.
DiagramGrid is not printing use the core functionality of matrix
printing.  This code should serve as an example that printing stuff in a
grid is useful not only in matrix printing.
33bef6e
Sergiu Ivanov Fix DiagramGrid tests to work with hash-stabilised FiniteSet and Dict.
This commit fixes the tests for DiagramGrid to test the correct,
hash-independent outcome.  Previously, the tests would test for one of
the possible outcomes.
1f241da
Sergiu Ivanov DiagramGrid._grow_pseudopod: Remove a redundant check.
This commit removes a check for an impossible situation.  The
explanation is provided in a comment.
387229e
Sergiu Ivanov DiagramGrid._triangle_key: Remove the TODO notice.
This TODO notice was valid when triangles were stored as FiniteSet's.
Now that triangles are stored as frozenset's, it is actually necessary
to sort the objects explicitly, because frozenset's do not have sort
keys.
a8b6acd
Sergiu Ivanov DiagramGrid._grow_pseudopod: Fix a very ugly mistake.
Initially I forgot to pick a certain element from the list of triangles
which could be attached and used the implicit value of the loop
variable, which would be the last element of the list.  This commit
fixes this mistake by explicitly picking the first triangle in the list.

This change has slightly changed the result for a test case; this commit
fixes the test as well.
ccc3b76
Sergiu Ivanov DiagramGrid._grow_pseudopod: Properly sort the edges.
The previous version of the code essentially invoked default_sort_key on
a frozenset, which didn't obviously produce the necessary result.
14489d5
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged ccc3b76 into 41e968b).

Tom Bachmann
Collaborator

This is ready to go in, isn't it?

sympy/categories/baseclasses.py
@@ -814,3 +840,77 @@ def hom(self, A, B):
814 840
                 conclusions |= FiniteSet(morphism)
815 841
 
816 842
         return (premises, conclusions)
  843
+
  844
+    def is_subdiagram(self, diagram):
  845
+        """
  846
+        Checks whether ``diagram`` is a subdiagram of ``self``.
  847
+        Diagram `D'` is a subdiagram of `D` if all premises
  848
+        (conclusions) of `D'` are contained in the premises
  849
+        (conclusions) of `D`.  The morphisms contained
  850
+        both in `D'` and `D` should have the same properties for `D'`
  851
+        to be a subdiagram of `D`.
  852
+
  853
+        Examples
  854
+        ========
  855
+        >>> from sympy.categories import Object, NamedMorphism, Diagram
  856
+        >>> from sympy import FiniteSet, pretty
2
Tom Bachmann Collaborator
ness01 added a note August 05, 2012

Why this line?

Tom Bachmann Collaborator
ness01 added a note August 05, 2012

We don't need pretty, do we?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/categories/baseclasses.py
((44 lines not shown))
  883
+        """
  884
+        If ``objects`` is a subset of the objects of ``self``, returns
  885
+        a diagram which has as premises all those premises of ``self``
  886
+        which have a domains and codomains in ``objects``, likewise
  887
+        for conclusions.  Properties are preserved.
  888
+
  889
+        Examples
  890
+        ========
  891
+        >>> from sympy.categories import Object, NamedMorphism, Diagram
  892
+        >>> from sympy import FiniteSet, pretty
  893
+        >>> A = Object("A")
  894
+        >>> B = Object("B")
  895
+        >>> C = Object("C")
  896
+        >>> f = NamedMorphism(A, B, "f")
  897
+        >>> g = NamedMorphism(B, C, "g")
  898
+        >>> d = Diagram([f, g], {f:"unique", g*f:"veryunique"})
1
Tom Bachmann Collaborator
ness01 added a note August 05, 2012

missing space after colon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/categories/diagram_drawing.py
((177 lines not shown))
  177
+    >>> from sympy.categories import Object, NamedMorphism
  178
+    >>> from sympy.categories import Diagram, DiagramGrid
  179
+    >>> from sympy import FiniteSet
  180
+    >>> A = Object("A")
  181
+    >>> B = Object("B")
  182
+    >>> C = Object("C")
  183
+    >>> f = NamedMorphism(A, B, "f")
  184
+    >>> g = NamedMorphism(B, C, "g")
  185
+    >>> diagram = Diagram([f, g])
  186
+
  187
+    The simplest way to have a diagram laid out is the following:
  188
+
  189
+    >>> grid = DiagramGrid(diagram)
  190
+    >>> (grid.width, grid.height)
  191
+    (2, 2)
  192
+    >>> print grid
2
Tom Bachmann Collaborator
ness01 added a note August 05, 2012

how about pretty(grid)?

Sergiu Ivanov
scolobb added a note August 07, 2012

That's a very cool idea, thanks for spotting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/categories/diagram_drawing.py
((1,205 lines not shown))
  1205
+            for i in xrange(self._grid.height):
  1206
+                for j in xrange(self._grid.width):
  1207
+                    grid[j, i] = self._grid[i, j]
  1208
+            self._grid = grid
  1209
+
  1210
+    @property
  1211
+    def width(self):
  1212
+        """
  1213
+        Returns the number of columns in this diagram layout.
  1214
+
  1215
+        Examples
  1216
+        ========
  1217
+
  1218
+        >>> from sympy.categories import Object, NamedMorphism
  1219
+        >>> from sympy.categories import Diagram, DiagramGrid
  1220
+        >>> from sympy import FiniteSet
2
Tom Bachmann Collaborator
ness01 added a note August 05, 2012

No need for this line.

Tom Bachmann Collaborator
ness01 added a note August 05, 2012

dito

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/categories/tests/test_baseclasses.py
@@ -124,7 +124,7 @@ def test_diagram():
124 124
     # Make sure that (re-)adding composites (with new properties)
125 125
     # works as expected.
126 126
     d = Diagram([f, g], {g * f:"unique"})
127  
-    assert d.conclusions[g * f] == FiniteSet("unique")
  127
+    assert d.conclusions == Dict({g*f:FiniteSet("unique")})
1
Tom Bachmann Collaborator
ness01 added a note August 05, 2012

space after colon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Tom Bachmann
Collaborator

Modulo my nitpicks, I think this is ready to go in.

As a side note, does this work in python3.3? I tried to check, but I get weird errors all over the place (not related to categories, as far as I can tell):

================================================================================================================================ test process starts =================================================================================================================================
executable:         /usr/bin/python3.3  (3.3.0-beta-1)
architecture:       64-bit
cache:              yes
ground types:       python
random seed:        7848159
hash randomization: on (PYTHONHASHSEED=1798822454)

sympy/categories/tests/test_baseclasses.py[3] .E.                                                                                                                                                                                                                               [FAIL]
sympy/categories/tests/test_drawing.py[2] .E                                                                                                                                                                                                                                    [FAIL]

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
______________________________________________________________________________________________________________ sympy/categories/tests/test_baseclasses.py:test_diagram _______________________________________________________________________________________________________________
  File "/home/ness/src/sympy/py3k-sympy/sympy/categories/tests/test_baseclasses.py", line 121, in test_diagram
    d11 = Diagram({f:"unique"})
  File "./sympy/categories/baseclasses.py", line 700, in __new__
    premises, morphism, FiniteSet(props))
  File "./sympy/categories/baseclasses.py", line 618, in _add_morphism_closure
    new_props = existing_props & props
  File "./sympy/core/sets.py", line 237, in __and__
    return self.intersect(other)
  File "./sympy/core/sets.py", line 84, in intersect
    return Intersection(self, other)
  File "./sympy/core/sets.py", line 927, in __new__
    return Intersection.reduce(args)
  File "./sympy/core/sets.py", line 981, in reduce
    return s.__class__(x for x in s
  File "./sympy/core/sets.py", line 1144, in __new__
    args = list(map(sympify, args))
  File "./sympy/core/sets.py", line 982, in <genexpr>
    if all(x in other for other in args))
  File "./sympy/core/sets.py", line 982, in <genexpr>
    if all(x in other for other in args))
  File "./sympy/core/sets.py", line 258, in __contains__
    result = ask(symb)
  File "./sympy/assumptions/ask.py", line 86, in ask
    res = key(expr)._eval_ask(assumptions)
  File "./sympy/assumptions/assume.py", line 88, in _eval_ask
    return self.func.eval(self.arg, assumptions)
  File "./sympy/assumptions/assume.py", line 147, in eval
    cls = get_class(handler)
  File "./sympy/utilities/source.py", line 27, in get_class
    lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
ImportError: No module named 'sympy.assumptions.handlers.'
______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
______________________________________________________________________________________________________________ sympy/categories/tests/test_drawing.py:test_DiagramGrid _______________________________________________________________________________________________________________
  File "/home/ness/src/sympy/py3k-sympy/sympy/categories/tests/test_drawing.py", line 96, in test_DiagramGrid
    d = Diagram([f, g], {g * f:"unique"})
  File "./sympy/categories/baseclasses.py", line 726, in __new__
    if (morphism.domain in objects) and \
  File "./sympy/core/sets.py", line 258, in __contains__
    result = ask(symb)
  File "./sympy/assumptions/ask.py", line 86, in ask
    res = key(expr)._eval_ask(assumptions)
  File "./sympy/assumptions/assume.py", line 88, in _eval_ask
    return self.func.eval(self.arg, assumptions)
  File "./sympy/assumptions/assume.py", line 147, in eval
    cls = get_class(handler)
  File "./sympy/utilities/source.py", line 27, in get_class
    lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
ImportError: No module named 'sympy.assumptions.handlers.'

============================================================================================================== tests finished: 3 passed, 2 exceptions, in 0.17 seconds ===============================================================================================================
DO *NOT* COMMIT!
Stefan Krastanov
Collaborator

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test command: setup.py test
master hash: 1627b32
branch hash: ccc3b76

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY7JsjDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY6_8hDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY9fQiDA

Build HTML Docs: :eight_spoked_asterisk: All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYt6sjDA

Automatic review by SymPy Bot.

Tom Bachmann
Collaborator

Great, so the tests pass. @scolobb this can go in whenever you're done with the nitpicks.

added some commits August 07, 2012
Sergiu Ivanov Brush the doctests a little bit.
This commit removes bogus imports, as well as fixes an example to not
use ``FiniteSet`` to supply groups to ``DiagramGrid``.
3e23f68
Sergiu Ivanov Comply with PEP8 whitespace recommendations in writing dicts.
This commit fixes the whitespace after the colon in dicts.  Previously,
I would sometimes not write them.
2704fc5
Sergiu Ivanov DiagramGrid: Use pretty printing in the main docstring. 47b7640
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 47b7640 into 41e968b).

Sergiu Ivanov

@ness01 , thanks for the extra round of review! I have fixed everything you have pointed out, including fixing all whitespace in writing dicts.

I get the same errors with Python 3.3, but I get them all over SymPy anyway, so I believe they are hardly introduced by my code.

Tom Bachmann ness01 merged commit 3c2c3c7 into from August 07, 2012
Tom Bachmann ness01 closed this August 07, 2012
Tom Bachmann
Collaborator

@scolobb solid work! I'll review diagram-drawing as soon as I can.

Sergiu Ivanov

Oh yeah! Thank you very much :-)

I'm looking forward to your feedback, but be sure to only review the pull request when you really have the time.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test command: setup.py test
master hash: 3c2c3c7
branch hash: 47b7640

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYl_AhDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYvo8iDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYj7MjDA

Build HTML Docs: :eight_spoked_asterisk: All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYipQjDA

Automatic review by SymPy Bot.

Aaron Meurer
Owner

SymPy Bot Summary: :red_circle: There were test failures (merged scolobb/ct1-diagram-layout (47b7640) into master (c7a4a4a)).

@scolobb: Please fix the test failures.

Build HTML Docs: :red_circle: There were test failures.
Sphinx version: 1.1.3

Aaron Meurer
Owner

@scolobb I think these doc failures are due to this branch.

Ondřej Čertík
Owner

But otherwise great job on the patch.

Sergiu Ivanov

Hm, note that Stefan's bot reported no problems, and neither do I see any errors on my box. I'll try to see what's different in Aaron's configuration.

Aaron Meurer
Owner

I also don't see anything in master. Perhaps this is yet another bug in my sympy-bot branch. Let me figure it out.

Aaron Meurer
Owner

Well, now it's passing for me even in SymPy bot. So maybe it was just fixed (?). Anyway, if it doesn't show up again, I'm not going to worry about it.

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

Showing 87 unique commits by 1 author.

Aug 04, 2012
Sergiu Ivanov Start the diagram_drawing module.
This commit adds the new module, a docstring, and the declaration of
DiagramOutline.  The class itself will be implemented later.
f679274
Sergiu Ivanov Add _GrowableGrid and corresponding tests.
This class represents a simple grid (two-dimensional array) which can be
grown in any of the four directions by appending empty rows and columns.
c999b2d
Sergiu Ivanov Have Diagram add components of composite morphisms automatically.
Previously, diagram would not add the components of composite morphisms.
This leaved some subtle ambiguities as to how to handle composite
morphisms which had some components not included into the diagram.  This
commit fixes those ambiguities.
baf28a4
Sergiu Ivanov Add some rudimentary tests for DiagramGrid.
The goal of having this tests is assuring that DiagramGrid.__new__ is
invoked.  Further tests will come together the corresponding
functionality.
4e53dbe
Sergiu Ivanov DiagramGrid: Simplify the premises and conclusions and merge them.
At the drawing stage, the separation between the premises and
conclusions of the diagram is not relevant; DiagramGrid discards this
separation.  If a morphism is included both in premises and in
conclusions, after the merging the morphism will have the properties it
had in conclusions.
285d64a
Sergiu Ivanov DiagramGrid: Build the undirected skeleton.
The skeleton of a diagram is the (undirected) graph whose vertices are
the objects of the diagram and which contains an edge between any pair
of objects between which in (the simplified, cf. previous commit)
diagram there is at least one morphism.  The skeleton also includes
edges between vertices A and C, such that there exists and object B
which is connected by at least one morphism with A and at least one
morphism with C.

The construction of this skeleton is one of the core tricks of the
layouting functionality.  The skeleton is constructed in such a way that
it can always be split into triangles.

Note that the term "skeleton" as used in the code, is defined ad-hoc.
824d760
Sergiu Ivanov DiagramGrid: Build meaningful triangles from the skeleton of the diag…
…ram.

DiagramGrid now sees which triangles are there in the skeleton, but also
discards the triangles which have less than 2 edges corresponding to
morphisms.  Such triangles may appear because of the how the skeleton is
constructed (cf. previous commit) and are irrelevant to laying the
diagram out, because only one edge of them will eventually be shown.
Note that such triangles are actually redundant in the sense that the
objects and morphisms they refer to will eventually be pulled into the
grid by other, more meaningful triangles.  This redundancy arises from
how the triangles are built and may be a point of further improvement
and/or optimisation.
a2c394e
Sergiu Ivanov DiagramGrid: Add some triangle utility functions.
This commit adds _triangle_objects which returns the set of vertices
of a triangle and _other_vertex, which, given a triangle and an edge,
returns the vertex which opposes the edge.
90ee353
Sergiu Ivanov DiagramGrid: Lay down the beginnings of the main construction loop.
This commit enables DiagramGrid to add the first edge to the layout and
introduces the (currently empty) function _weld_triangle, which welds
one triangle to the current fringe.

All triangles which are relevant to the plot are assumed to form a
prefix of the list of triangles.  Whether this is true will be later
revealed by further tests and the details of functionality.
75b080b
Sergiu Ivanov DiagramGrid: Find the place to attach a triangle to the existing fringe.
This commit adds and utilises _find_triangle_welding, which finds a
place in the fringe to weld the supplied triangle to.
23ecbc7
Sergiu Ivanov DiagramGrid: Prepare to fixing some of the degenerate situations in t…
…he fringe.

This commit adds _fix_degenerate which, given an edge from the fringe
and two points, checks whether one of the two points defines an edge,
which is in the fringe, and which is perpendicular on the given edge.
If such a situation is found, _fix_degenerate drops the two edges and
adds the corresponding diagonal to the fringe.
c287055
Sergiu Ivanov DiagramGrid: Decide how to place the outstanding vertex of the welded…
… triangle.

While _find_triangle_welding shows how to place one edge of the
triangle, it is important and nontrivial to decide where to place the
third vertex.  DiagramGrid is now capable to make this decision, while
also fixing some possible degenerate situations in the fringe.
cbde034
Sergiu Ivanov DiagramGrid: Finalise the basic layouting functionality.
DiagramGrid.__new__ now can cope with some simple diagrams.  It can
maybe cope with more complex diagrams; I don't know yet.
4cccb9a
Sergiu Ivanov DiagramGrid: Add _choose_target_cell.
This commit factors out the functionality of choosing one of the two
points above or below of a horizontal edge and to the left or to the
right of a vertical edge.  The new function will be later extended to
allow Diagram to avoid some of the intersections of the representations
of morphisms.
bd23826
Sergiu Ivanov DiagramGrid: Extend _choose_target_cell to choose the point better.
This commit enables _choose_target_cell (cf. previous commit) to
intelligently treat the situation when both points are free.  If this is
the case, the function now makes such a choice that, should the triangle
have only two visible edges, the edge different from the welding edge
will be drawn perpendicular to the welding edge.  This will eventually
help avoid some of the intersections of morphisms.
bfbda05
Sergiu Ivanov DiagramGrid: Use _put_object also to update the target cell.
If _put_object prepends the grid with a row or a column, the coordinates
of the target cell become different as well.  This must be taken into
account.
41703a2
Sergiu Ivanov DiagramGrid: Remove _fix_degenerate.
It turns out that the situations which I considered when implementing
_fix_degenerate are not at all degenerate.  Therefore, at the moment,
very little is done to minimise the size of the fringe after adding a
triangle to the grid.  I will analyse the question of keeping only the
outer edges of the structure in the fringe later.
ccbb32e
Sergiu Ivanov DiagramGrid: Keep track of the objects added to the diagram.
DiagramGrid now stops laying out the diagram when all objects have been
added to the grid.  Previously, it would zealously work on until all
triangles have been exhausted.
a74980a
Sergiu Ivanov DiagramGrid: Prefer going down and to the right when building diagrams.
This will in most cases result in a more natural placing of the objects
of the diagram, because of how humans read from left to right, from top
to bottom.
92b1fce
Sergiu Ivanov DiagramGrid: Fix the heuristics for welding triangles to vertical edges.
Before this commit DiagramGrid would wrongly choose where to put the
third vertex of the welded triangle, which would result in unnecessary
diagonal edges.
cb2c081
Sergiu Ivanov DiagramGrid: Assure independence of hash randomisation.
Previously DiagramGrid would often layout the same diagrams differently
because the list of triangles was sorted differently, depending on their
(randomised) hash.
0f1af7c
Sergiu Ivanov Don't derive DiagramGrid from Basic.
While DiagramGrid is essentially immutable, it does not model a
mathematical object and therefore should not be a subclass of Basic.
e509078
Sergiu Ivanov DiagramGrid: Store the grid of objects in the instance and offer acce…
…ss to it.

This commit makes it possible to use DiagramGrid from the outer world:
the class now stores the results of the analysis it has performed.
b67baa0
Sergiu Ivanov Add some proper tests for DiagramGrid.
Since DiagramGrid is already usable now, it is now possible to test how
some simple diagrams are laid out.
5fa96dd
Sergiu Ivanov DiagramGrid: Don't re-place objects on the grid.
After each new triangle placed in the grid, forget all triangles which
only include objects which have already been placed on the grid.
24a675c
Sergiu Ivanov DiagramGrid: Add a test for a strange diagram.
This test attempts to use DiagramGrid to lay out a diagram which
resulted from a typo in an attempt to lay out the  the five lemma.
DiagramGrid currently fails to lay it out properly because of
the fact that en route it encounters a situation where none of the
remaining triangles can be welded to the already constructed structure.
515ae01
Sergiu Ivanov DiagramGrid: Attach triangles by vertices when this cannot be done by…
… edges.

This commit enables DiagramGrid to lay out more complex diagrams, like
the five lemma.  Generally, using the function _grow_pseudopod, added in
this commit, should be avoided for as long as possible, and this is what
DiagramGrid currently does.
9761974
Sergiu Ivanov DiagramGrid: Test how DiagramGrid lays out a cube diagram.
The new test requires DiagramGrid to lay out a cube.  Rather obviously,
the result is not a cube, because of how DiagramGrid is designed.
42ccc71
Sergiu Ivanov DiagramGrid: Test a pullback.
This test currently fails because the loop in the constructor of
DiagramGrid fails to distinguish between the situations when
_weld_triangle has not found a welding and when it has corrected the
fringe and thus requires a restart of the search for weldings.
2be0f5c
Sergiu Ivanov DiagramGrid: Distinguish between welding failures and restarts.
The loop in the constructor DiagramGrid now can distinguish between the
situations when _weld_triangle has not found any welding and when it has
corrected the fringe and requires a restart of the process.  This makes
the test added in the previous commit pass.
8d3e193
Sergiu Ivanov DiagramGrid: Lay out one-morphism diagrams as well.
This commit also adds a corresponding test.
86d325b
Sergiu Ivanov Diagram: Add is_subdiagram and test it.
This method checks whether its argument is a subdiagram of self.
49f2ed3
Sergiu Ivanov Diagram: Fix the mess in handling conclusions.
Diagram would previously add the components of composite morphisms which
belonged to conclusions, which would clutter the conclusions.
Furthermore, it wouldn't sometimes properly add properties to the
morphisms in conclusions.  This commit fixes all of these.
4d88b4b
Sergiu Ivanov Diagram: Add subdiagram_from_objects.
This method returns a subdiagram of self which includes the objects
supplied in the argument.
ee8bbdc
Sergiu Ivanov DiagramGrid: Add the possibility to lay out diagrams in logical groups.
The constructor of DiagramGrid now accepts the argument groups, which
specifies groups of objects to be laid out independently from the others
in their own group.  This commit also adds the corresponding tests.
1fd263f
Sergiu Ivanov DiagramGrid: Test the five lemma.
I have just discovered that what I initially thought to be tests for the
five lemma has turned to be a weird diagram resulted from a typo.  This
commit adds the test for five lemma proper.
d246cbf
Sergiu Ivanov DiagramGrid: Test the five lemma with grouping of objects.
Grouping objects allows laying diagrams out in better structures.  For
example, with grouping, it is possible to make the automated layout of
the five lemma look more like how it is usually drawn by hand.
731e099
Sergiu Ivanov Make _GrowableGrid and DiagramGrid derive from object.
This transforms these classes into new-style classes.
fab82b6
Sergiu Ivanov DiagramGrid: Factor out the generic laying out functionality.
In the future, the constructor of DiagramGrid will live through further
enhancements, like hints, which makes it important to push what it does
to a higher level of abstraction.
43a9dc5
Sergiu Ivanov DiagramGrid: Implement the sequential layout for diagrams.
This layout method attempts to place the objects as closed to a line as
possible.  This commit also adds the corresponding tests.
b173213
Sergiu Ivanov DiagramGrid.__init__: Rearrange the code in a big if statement.
This commit makes the code in the constructor of DiagramGrid more
orderly and easy to extend later.
1dfd0e4
Sergiu Ivanov DiagramGrid: Implement the transpose hint.
If transpose == True, the constructor of DiagramGrid will transpose the
resulting grid.
236425c
Sergiu Ivanov DiagramGrid: Test the layout of a pullback with sequential layout.
This test is there just for stress testing the sequential layout,
because the pullback doesn't really look like nice when laid out with
this strategy.
24f0f5a
Sergiu Ivanov DiagramGrid: Rename hint "shape" to "layout". 6bd40c0
Sergiu Ivanov DiagramGrid: Rearrange the tests a bit.
This commit assures a slightly better logical grouping of the tests.
ff5223f
Sergiu Ivanov DiagramGrid: Support hints in groups as well.
Using only the two supported hints it is not possible to lay out the
five lemma almost exactly as it is normally laid out.  This commit adds
a test to show off this new capability.
84f50b2
Sergiu Ivanov DiagramGrid: Test a pull back laid out with generic layout.
Somewhere in the past I have accidentally removed the tests for a pull
back laid out with generic layout.  This test brings that code back.
38e0681
Sergiu Ivanov DiagramGrid._triangle_key: Remove the necessity of objects to have na…
…mes.

This method used to produced a key for sorting the triangles which was
dependent on objects having names.  This would fail for groups, where
objects are FiniteSet's.

Note that this method currently sorts the set of objects in order to
avoid the problem of the sort key of FiniteSet being different in
dependence of the order of the elements in it.
b421413
Sergiu Ivanov DiagramGrid._handle_groups: Fix a bug in copying child grids. 2b700da
Sergiu Ivanov DiagramGrid: Write an extensive docstring.
This docstring includes explanations and examples for all features
available to the user.
20f9625
Sergiu Ivanov DiagramGrid: Add examples for width, height, and __getitem__. ce5ec82
Sergiu Ivanov docs/modules/categories.rst: Add a reference to DiagramGrid. fec3bc0
Sergiu Ivanov diagram_drawing: Describe the layout algorithm in the module docstring. 0cae466
Sergiu Ivanov DiagramGrid: Store the simplified and merged morphisms.
This commit adds the property morphisms which returns the dictionary
mapping those morphisms to their properties which were considered worthy
by the constructor of DiagramGrid.
1c1e149
Sergiu Ivanov DiagramGrid: Sort the vertices in the root triangle.
Previously DiagramGrid would not sort the vertices in the edges of
the first triangle, out of which the root edge was picked.  This resulted
in different edges being sometimes picked, as well arbitrary positioning
of the vertices of the root edge.
cbfdf55
Sergiu Ivanov DiagramGrid: Don't use "loop" morphisms in laying out objects.
"Loop" morphisms are morphisms which have the same domains and
codomains.  They will be eventually drawn as loops and should not
influence the layout of the diagram.
de5a5b2
Sergiu Ivanov DiagramGrid: Comment _triangle_objects and _other_vertex.
The code of these two functions might be a little bit difficult to
comprehend; this commits adds what I believe to be extensive comments
explaining how and why these methods work.
8c7ae4f
Sergiu Ivanov Rename Diagram._add_morphism -> Diagram._add_morphism_closure.
The new name describes what the method does a little bit better, and
also removes the possible confusion with
CompositeMorphism._add_morphism.
c738ab8
Sergiu Ivanov DiagramGrid._merge_premises_conclusions: Use itertools.chain.
This simplifies the method and outsources the functionality to better
functions.
4926c1e
Sergiu Ivanov Fix some minor typos and space issues in DiagramGrid-related code. c679614
Sergiu Ivanov DiagramGrid: Use set's and frozenset's instead of FiniteSet.
This commit changes the code which needs sets for internal operations to
use the builtins set and frozenset instead of FiniteSet.
64d6242
Sergiu Ivanov DiagramGrid: Fix some redundant line breaks.
In a number of places (especially in list comprehensions) I used the
backslash to assure proper interpretation; it turns out a number of such
backslashes were not necessary.
3a0342b
Sergiu Ivanov _compute_triangle_min_sizes: Explain why this metric.
This commit adds a high-level explanation of the heuristic triangle
metric implemented in this function.
d7bb7e4
Sergiu Ivanov DiagramGrid._put_object: Make ``offset`` values clearer. 3e3d55e
Sergiu Ivanov DiagramGrid: Refactor _weld_triangle.
This method used to melange the missions of finding the triangle to weld
and actually welding the triangle.  This resulted in the necessity to
return a triangle or one of the two status codes.  This commit fixes
this ugliness by better splitting the functionality between __init__,
_weld_triangle and _find_triangle_welding (which is not called
_find_triangle_to_weld).
df16cfd
Sergiu Ivanov DiagramGrid: Store edges in two-element frozensets.
This commit transitions from storing edges as two-element tuples to
storing them as frozensets.  The rationale behind this change is that
the edges of the skeleton are undirected, which makes storing them in
tuples inconvenient and results in a lot of uglier code.
9977109
Sergiu Ivanov DiagramGrid: Add _get_undirected_graph.
This commit factors out of _sequential_layout the code producing the
adjacency lists of the underlying undirected graph of the diagram.
528318f
Sergiu Ivanov DiagramGrid: Add support for disconnected diagrams.
DiagramGrid is now capable of laying out disconnected diagrams by laying
out each connected component separately.  The grids of each of the
connected components are arranged in a line.  This is a place where
further improvements could be introduced.
ddfd51f
Sergiu Ivanov DiagramGrid: Support one-object diagrams.
While one doesn't construct one-object diagrams every day, this is a
valid edge case that has to be supported.  Furthermore, laying out
one-object diagrams will be useful for some internal purposes (see the
next commits).
5a3d764
Sergiu Ivanov DiagramGrid: Handle the situations when growing a pseudopod fails.
While I initially supposed that reaching such situations would be
difficult, it proved quite easy to get there by setting up a "star"
diagram, with many morphisms coming out of a central object.  This
commit adds the code to handle such situations and actually lay out all
objects.
7821c42
Sergiu Ivanov Diagram: Disallow identity morphisms to have properties.
Identity morphisms are trivial and properties for them do not make
sense.  This should not be confused with nontrivial morphisms with
the same domain and codomain, which are instances of NamedMorphism and
can always be annotated with properties.
ef2dc14
Sergiu Ivanov DiagramGrid: Use implicit generator expressions where possible.
This commit fixes the expressions func([<generator-expression>]) to look
like func(<generator-expression>), i.e., removes the redundant square
brackets.
dcfc319
Sergiu Ivanov DiagramGrid: Check out the transpose hint nicer.
Previously, the code would check out the value of the transpose hint
using two if statements.  Now it does so in one if statement.
0686a9e
Sergiu Ivanov DiagramGrid._handle_groups: Add lay_out_group.
Previously, the part of _handle_groups that laid out each of the group
would consist of two largely similar halves: one that processed groups
supplied as an array of FiniteSet's, and the other one which processed
groups as a dictionary mapping groups to their hints.  This commit
factors out the common part into lay_out_group.
efb8858
Sergiu Ivanov DiagramGrid: Support any iterable to describe groups.
Previously DiagramGrid would only agree if groups were supplied as
FiniteSet's of FiniteSet's.  This commit enables DiagramGrid to cope
with any iterable type.  The test added hereby shows how this can be
utilised.
0d69ed4
Sergiu Ivanov DiagramGrid: Add LaTeX pretty printing and __str__.
This makes DiagramGrid easier to show in doctests and, probably, easier
to use.  Pretty printing to string will come in the next commits.
8292883
Sergiu Ivanov DiagramGrid: Upgrade the docstrings to use string printing.
Previously, the docstrings would print the grid object by object.  Now
it relies on DiagramGrid.__str__ to show the contents of the grid.
93533c7
Sergiu Ivanov Factor _print_matrix_contents out of _print_MatrixBase.
This commit adds to the string pretty printer the method
_print_matrix_contents which only carries that part of the previous
version of _print_MatrixBase which refers to printing the grid.
_print_MatrixBase now only puts this grid in brackets.

The motivation behind this commit is that grid printing is useful in
itself and thus should be available as a separate method.  See the next
commit for an example of such usage.
b7e5772
Sergiu Ivanov DiagramGrid: Add string pretty printing.
DiagramGrid is not printing use the core functionality of matrix
printing.  This code should serve as an example that printing stuff in a
grid is useful not only in matrix printing.
33bef6e
Sergiu Ivanov Fix DiagramGrid tests to work with hash-stabilised FiniteSet and Dict.
This commit fixes the tests for DiagramGrid to test the correct,
hash-independent outcome.  Previously, the tests would test for one of
the possible outcomes.
1f241da
Sergiu Ivanov DiagramGrid._grow_pseudopod: Remove a redundant check.
This commit removes a check for an impossible situation.  The
explanation is provided in a comment.
387229e
Sergiu Ivanov DiagramGrid._triangle_key: Remove the TODO notice.
This TODO notice was valid when triangles were stored as FiniteSet's.
Now that triangles are stored as frozenset's, it is actually necessary
to sort the objects explicitly, because frozenset's do not have sort
keys.
a8b6acd
Sergiu Ivanov DiagramGrid._grow_pseudopod: Fix a very ugly mistake.
Initially I forgot to pick a certain element from the list of triangles
which could be attached and used the implicit value of the loop
variable, which would be the last element of the list.  This commit
fixes this mistake by explicitly picking the first triangle in the list.

This change has slightly changed the result for a test case; this commit
fixes the test as well.
ccc3b76
Sergiu Ivanov DiagramGrid._grow_pseudopod: Properly sort the edges.
The previous version of the code essentially invoked default_sort_key on
a frozenset, which didn't obviously produce the necessary result.
14489d5
Aug 07, 2012
Sergiu Ivanov Brush the doctests a little bit.
This commit removes bogus imports, as well as fixes an example to not
use ``FiniteSet`` to supply groups to ``DiagramGrid``.
3e23f68
Sergiu Ivanov Comply with PEP8 whitespace recommendations in writing dicts.
This commit fixes the whitespace after the colon in dicts.  Previously,
I would sometimes not write them.
2704fc5
Sergiu Ivanov DiagramGrid: Use pretty printing in the main docstring. 47b7640
Something went wrong with that request. Please try again.