Repository: sagemath/sage

Issue:
MIPVariable: Change to a subclass of FiniteFamily
<div id="comment:0"></div>

... to give it a richer set of operations, such as `len()` to get the number of components and an implementation of `.inverse_family()` to allow looking up the key of a given component (`LinearFunction` instance).

This requires making `AbstractFamily` and `FiniteFamily` Cython classes.


Depends on #34839

CC:  @yuan-zhou @tscrim @mantepse

Component: **linear programming**

Author: **Matthias Koeppe**

_Issue created by migration from https://trac.sagemath.org/ticket/31750_




Discussion:
Description changed:
``````diff
--- 
+++ 
@@ -1,3 +1,4 @@
 ... to give it a richer set of operations, such as `len()` to get the number of components and an implementation of `.inverse_family()` to allow looking up the key of a given component (`LinearFunction` instance).
 
+This requires making `AbstractFamily` and `FiniteFamily` Cython classes.
 
``````

Author: **Matthias Koeppe**
Branch: **[u/mkoeppe/mipvariable__change_to_a_subclass_of_finitefamily](https://github.com/sagemath/sagetrac-mirror/tree/u/mkoeppe/mipvariable__change_to_a_subclass_of_finitefamily)**
Commit: **[`3beb977`](https://github.com/sagemath/sagetrac-mirror/commit/3beb9779f2278fa75961784ca22c219d1aaeef9e)**
<div id="comment:9"></div>

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/96366a667a5d91663dd9b3be660a4a015653ae91"><code>96366a6</code></a></td><td><code>sage.sets.family: Cythonize</code></td></tr><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/3beb9779f2278fa75961784ca22c219d1aaeef9e"><code>3beb977</code></a></td><td><code>MIPVariable: Make it a subclass of FiniteFamily</code></td></tr></table>

<div id="comment:10"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/a278c804bd605dcaf656adfc8448a5a7d5e68a84"><code>a278c80</code></a></td><td><code>src/sage/sets/family.py: Update copyright according to git blame -w --date=format:%Y FILE | sort -k2</code></td></tr><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/11aeb808166506e4f733f221b2fa28f8bb477b09"><code>11aeb80</code></a></td><td><code>sage.sets.family: Fix pickling</code></td></tr></table>

Changed commit from **[`3beb977`](https://github.com/sagemath/sagetrac-mirror/commit/3beb9779f2278fa75961784ca22c219d1aaeef9e)** to **[`11aeb80`](https://github.com/sagemath/sagetrac-mirror/commit/11aeb808166506e4f733f221b2fa28f8bb477b09)**
<div id="comment:11" align="right">comment:11</div>


```
sage -t --random-seed=163374757519390176193284183888236547352 doc/en/thematic_tutorials/lie/weyl_groups.rst  # 2 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/algebras/fusion_rings/fusion_ring.py  # 17 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/algebras/iwahori_hecke_algebra.py  # 3 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/algebras/lie_algebras/nilpotent_lie_algebra.py  # 10 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/algebras/lie_algebras/quotient.py  # 7 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/algebras/lie_algebras/subalgebra.py  # 4 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/categories/finite_dimensional_algebras_with_basis.py  # 26 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/categories/finite_dimensional_lie_algebras_with_basis.py  # 3 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/categories/finite_dimensional_semisimple_algebras_with_basis.py  # 9 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/categories/lie_algebras.py  # 2 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/groups/lie_gps/nilpotent_lie_group.py  # 2 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/modules/with_basis/morphism.py  # 1 doctest failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/modules/with_basis/subquotient.py  # 2 doctests failed
sage -t --random-seed=163374757519390176193284183888236547352 sage/sets/family.pyx  # 1 doctest failed
```
Changed commit from **[`11aeb80`](https://github.com/sagemath/sagetrac-mirror/commit/11aeb808166506e4f733f221b2fa28f8bb477b09)** to **[`d312578`](https://github.com/sagemath/sagetrac-mirror/commit/d312578e1c9215ac602a7d26feccfb4fd4ce1032)**
<div id="comment:12"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/d312578e1c9215ac602a7d26feccfb4fd4ce1032"><code>d312578</code></a></td><td><code>src/sage/sets/family.pxd: Make attributes public</code></td></tr></table>

Changed commit from **[`d312578`](https://github.com/sagemath/sagetrac-mirror/commit/d312578e1c9215ac602a7d26feccfb4fd4ce1032)** to **[`450f9c6`](https://github.com/sagemath/sagetrac-mirror/commit/450f9c63e05cae3661f147c6bb54b9137cf15bf6)**
<div id="comment:13"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/450f9c63e05cae3661f147c6bb54b9137cf15bf6"><code>450f9c6</code></a></td><td><code>Make FiniteFamily a Python subclass of FiniteFamily_base - so that EnumeratedSets mixins work correctly</code></td></tr></table>

Dependencies: **#34839**
<div id="comment:15"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/d302a628936a965d4e5c3501b7989028274fac95"><code>d302a62</code></a></td><td><code>tox.ini, src/tox.ini: Adjust to tox 4, autoprovision tox >= 3.18</code></td></tr><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/f8703aeba13b8663e55b46494dec4fd305e65374"><code>f8703ae</code></a></td><td><code>.github/workflows/lint.yml: Invoke tox with --</code></td></tr><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/9d76204fb5801054755b2e7bc54aeb6743742ced"><code>9d76204</code></a></td><td><code>fix some rst issues in sage_docbuild and sage_setup</code></td></tr><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/70da140f5f430c1cab53a858a8b33d43d23baf1e"><code>70da140</code></a></td><td><code>Merge branch 'u/chapoton/support_tox_4' in 9.8.b6</code></td></tr><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/8b2ada9af6a29fc808b23df0dbc6c7b1a2f64237"><code>8b2ada9</code></a></td><td><code>Merge #34839</code></td></tr></table>

Changed commit from **[`450f9c6`](https://github.com/sagemath/sagetrac-mirror/commit/450f9c63e05cae3661f147c6bb54b9137cf15bf6)** to **[`8b2ada9`](https://github.com/sagemath/sagetrac-mirror/commit/8b2ada9af6a29fc808b23df0dbc6c7b1a2f64237)**
Changed commit from **[`8b2ada9`](https://github.com/sagemath/sagetrac-mirror/commit/8b2ada9af6a29fc808b23df0dbc6c7b1a2f64237)** to **[`02ffd0a`](https://github.com/sagemath/sagetrac-mirror/commit/02ffd0a92969d389c3918f96bae73712cd1a7fe3)**
<div id="comment:16"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/e521c9c85214e9f9e0b4854d19905916e4cb8a12"><code>e521c9c</code></a></td><td><code>Revert "Make FiniteFamily a Python subclass of FiniteFamily_base - so that EnumeratedSets mixins work correctly"</code></td></tr><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/02ffd0a92969d389c3918f96bae73712cd1a7fe3"><code>02ffd0a</code></a></td><td><code>FiniteFamily: Simpler solution that makes EnumeratedSets mixins work correctly</code></td></tr></table>

Removed branch from issue description; replaced by PR #35121

Resolving patch:
diff --git a/src/sage/combinat/root_system/type_relabel.py b/src/sage/combinat/root_system/type_relabel.py
--- a/src/sage/combinat/root_system/type_relabel.py
+++ b/src/sage/combinat/root_system/type_relabel.py
@@ -10,7 +10,7 @@
 
 from sage.misc.cachefunc import cached_method
 from sage.misc.lazy_attribute import lazy_attribute
-from sage.sets.family import FiniteFamily
+from sage.sets.family import Family, FiniteFamily
 from sage.combinat.root_system import cartan_type
 from sage.combinat.root_system import ambient_space
 from sage.combinat.root_system.root_lattice_realizations import RootLatticeRealizations
@@ -173,10 +173,10 @@ def __init__(self, type, relabelling):
             sage: rI5 = CartanType(['I',5]).relabel({1:0,2:1})
             sage: rI5.root_system().ambient_space()
         """
-        assert isinstance(relabelling, FiniteFamily)
         cartan_type.CartanType_decorator.__init__(self, type)
-        self._relabelling = relabelling._dictionary
-        self._relabelling_inverse = relabelling.inverse_family()._dictionary
+        relabelling = Family(relabelling)
+        self._relabelling = dict(relabelling.items())
+        self._relabelling_inverse = dict(relabelling.inverse_family().items())
         self._index_set = tuple(sorted(relabelling[i] for i in type.index_set()))
         # TODO: design an appropriate infrastructure to handle this
         # automatically? Maybe using categories and axioms?


Test patch: