Skip to content

Commit

Permalink
interface for cygv
Browse files Browse the repository at this point in the history
  • Loading branch information
natemacfadden committed Aug 31, 2024
1 parent 47407a6 commit d0201db
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
108 changes: 108 additions & 0 deletions src/cytools/calabiyau.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit d0201db

Please sign in to comment.