From d0201db856fb72da882e7fd132f3340465312dfc Mon Sep 17 00:00:00 2001 From: Nate MacFadden Date: Fri, 30 Aug 2024 21:40:07 -0400 Subject: [PATCH] interface for cygv --- requirements.txt | 1 + src/cytools/calabiyau.py | 108 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/requirements.txt b/requirements.txt index dfabdb2..d1036ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,6 +18,7 @@ comm==0.1.3 contourpy==1.0.7 cvxopt==1.3.0 cycler==0.11.0 +cygv==0.1.1 cysignals==1.11.2 daqp==0.5.1 debugpy==1.6.7 diff --git a/src/cytools/calabiyau.py b/src/cytools/calabiyau.py index e571e42..950b13a 100644 --- a/src/cytools/calabiyau.py +++ b/src/cytools/calabiyau.py @@ -27,6 +27,7 @@ import warnings # 3rd party imports +import cygv from flint import fmpz_mat, fmpq_mat, fmpz, fmpq import numpy as np from scipy.sparse import csr_matrix @@ -1936,3 +1937,110 @@ def search_in_cache(): jj += 1 if ii < 0 or jj > self.dim(): break + + # GVs + # --- + def _compute_gvs_gws(self, + gv_or_gw: str, + grading_vec: "ArrayLike"=None, + max_deg: bool=None, + min_points: bool=None, + format="dok"): + """ + **Description:** + Wrapper for cygv GV and GW computations. A method of cytools.CalabiYau + + NOT INTENDED TO BE CALLED DIRECTLY! + + **Arguments:** + - `gv_or_gw`: String specifying whether 'gv' or 'gw' computations are + performed. + - `grading_vec`: The grading vector to use in the computations. A default + is chosen if none is provided. + - `max_deg`: The maximum degree to compute GVs/GWs to. Must be specified + iff min_points=None. + - `min_points`: The minimum number of GVs/GWs to compute. Must be + specified iff max_deg=None. + + **Returns:** + The GV/GW invariants. + """ + # check that the user either passed max_deg or min_points + if not (max_deg is None) ^ (min_points is None): + raise ValueError("Either max_deg or min_points must be set!") + + # get basics + kappa = self.intersection_numbers(in_basis=True, format='coo') + glsm = self.curve_basis(include_origin=False, as_matrix=True) + mori = self.toric_mori_cone(in_basis=True) + generators = mori.rays() + + # compute a grading vector if none is provided + if grading_vec is None: + grading_vec = mori.find_grading_vector() + + # compute the GVs + if gv_or_gw=='gv': + fct = cygv.compute_gv + else: + fct = cygv.compute_gw + gvs = fct(generators = mori.rays(), + grading_vector = grading_vec, + q = self.curve_basis(include_origin=False, as_matrix=True), + intnums = self.intersection_numbers(in_basis=True, format='dok'), + max_deg = max_deg, + min_points = min_points) + + # format/return the GVs + if format=='dok': + gvs = dict(gvs) + elif format=='coo': + gvs = [list(charge_gv[0])+[charge_gv[1]] for charge_gv in gvs] + else: + raise ValueError(f"format '{format}' is not recognized...") + + return gvs + + def compute_gvs(self, + grading_vec: "ArrayLike"=None, + max_deg: bool=None, + min_points: bool=None, + format: str=format): + """ + **Description:** + Wrapper for cygv GV computations. A method of cytools.CalabiYau + + **Arguments:** + - `grading_vec`: The grading vector to use in the computations. A default + is chosen if none is provided. + - `max_deg`: The maximum degree to compute GVs to. Must be specified iff + min_points=None. + - `min_points`: The minimum number of GVs/GWs to compute. Must be + specified iff max_deg=None. + + **Returns:** + The GV invariants. + """ + return self._compute_gvs_gws('gv', grading_vec, max_deg, min_points, format) + + def compute_gws(self, + grading_vec=None, + max_deg=None, + min_points=None, + format: str=format): + """ + **Description:** + Wrapper for cygv GW computations. A method of cytools.CalabiYau + + **Arguments:** + - `grading_vec`: The grading vector to use in the computations. A default + is chosen if none is provided. + - `max_deg`: The maximum degree to compute GWs to. Must be specified iff + min_points=None. + - `min_points`: The minimum number of GWs to compute. Must be specified + iff max_deg=None. + + **Returns:** + The GW invariants. + """ + return self._compute_gvs_gws('gw', grading_vec, max_deg, min_points, format)