Skip to content

Fractions used even when explicitly turned off #30

@ttusar

Description

@ttusar

As reported by @MLopez-Ibanez, the following code

import moocore
from moarchiving import get_mo_archive as moarch_get_mo_archive
moarch_get_mo_archive.hypervolume_computation_float_type = float
moarch_get_mo_archive.hypervolume_final_float_type = float

x = moocore.generate_ndset(500,4,method="L", seed=42)
a = moarch_get_mo_archive(x, reference_point=[1,1,1,1])
print(a.contributing_hypervolumes) 

still uses Fractions. I.e., when the code is interrupted during execution (Ctrl+C), he gets:

File ~/work/perfassess/moocore/r/test.py:8
      6 x = moocore.generate_ndset(500,4,method="L", seed=42)
      7 a = moarch_get_mo_archive(x, reference_point=[1,1,1,1])
----> 8 print(a.contributing_hypervolumes)

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving_parent.py:205, in MOArchiveParent.contributing_hypervolumes(self)
    202 @property
    203 def contributing_hypervolumes(self):
    204     """`list` of hypervolume contributions of each point in the archive"""
--> 205     return [self.contributing_hypervolume(point[:self.n_obj]) for point in self]

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving_parent.py:231, in MOArchiveParent.contributing_hypervolume(self, f_vals)
    229     removed_info = self.remove(f_vals)
    230     hv_after = self._hypervolume
--> 231     self.add(f_vals, info=removed_info)
    232     return hv_before - hv_after
    233 else:

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving4obj.py:131, in MOArchive4obj.add(self, f_vals, info, update_hypervolume)
    128         self._hypervolume_plus = -dist_to_hv_area
    129     return False
--> 131 self.__init__(list(self) + [f_vals], self.reference_point, self.infos + [info])
    132 return True

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving4obj.py:84, in MOArchive4obj.__init__(self, list_of_f_vals, reference_point, infos, hypervolume_final_float_type, hypervolume_computation_float_type)
     82 self._hypervolume_already_computed = False
     83 self.remove_dominated()
---> 84 hv = self._set_HV()
     85 self._length = len(list(self))
     86 self._hypervolume_already_computed = True

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving_parent.py:300, in MOArchiveParent._set_HV(self)
    298 if self.reference_point is None:
    299     return None
--> 300 self._hypervolume = self.hypervolume_final_float_type(self.compute_hypervolume())
    301 if self._hypervolume > 0:
    302     self._hypervolume_plus = self._hypervolume

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving4obj.py:288, in MOArchive4obj.compute_hypervolume(self, reference_point)
    285 if self._hypervolume_already_computed:
    286     return self._hypervolume
    287 return self.hypervolume_final_float_type(
--> 288     hv4dplusR(self.head, self.hypervolume_computation_float_type))

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving_utils.py:456, in hv4dplusR(head, Fc)
    453 update_links(head, new, new.next[2])  # Update cx and cy of the points above 'new' in z
    454 # and remove dominated points
--> 456 volume = hv3dplus(head, Fc)  # Compute hv indicator in d=3 in linear time
    458 height = Fc(new.next[3].x[3]) - Fc(new.x[3])
    459 hv += volume * height  # Update hypervolume in d=4

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving_utils.py:430, in hv3dplus(head, Fc)
    427 p.cnext[0] = p.closest[0]
    428 p.cnext[1] = p.closest[1]
--> 430 area += compute_area_simple(p.x, 1, p.cnext[0], p.cnext[0].cnext[1], Fc)
    431 p.cnext[0].cnext[1] = p
    432 p.cnext[1].cnext[0] = p

File ~/.local/lib/python3.12/site-packages/moarchiving/moarchiving_utils.py:255, in compute_area_simple(p, di, s, u, Fc)
    253     q = u
    254     u = u.cnext[di]
--> 255     area += (Fc(q.x[dj]) - Fc(p[dj])) * (Fc(u.x[di]) - Fc(q.x[di]))
    257 return area

File /usr/lib/python3.12/fractions.py:615, in Fraction._operator_fallbacks.<locals>.forward(a, b)
    613 def forward(a, b):
    614     if isinstance(b, Fraction):
--> 615         return monomorphic_operator(a, b)
    616     elif isinstance(b, int):
    617         return monomorphic_operator(a, Fraction(b))

File /usr/lib/python3.12/fractions.py:754, in Fraction._mul(a, b)
    752     nb //= g2
    753     da //= g2
--> 754 return Fraction._from_coprime_ints(na * nb, db * da)

File /usr/lib/python3.12/fractions.py:324, in Fraction._from_coprime_ints(cls, numerator, denominator)
    317 @classmethod
    318 def _from_coprime_ints(cls, numerator, denominator, /):
    319     """Convert a pair of ints to a rational number, for internal use.
    320 
    321     The ratio of integers should be in lowest terms and the denominator
    322     should be positive.
    323     """
--> 324     obj = super(Fraction, cls).__new__(cls)
    325     obj._numerator = numerator
    326     obj._denominator = denominator

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions