Skip to content

Configuration

There is a configuration submodule, cytools.config, that allows changing a few settings for those adventurous enough to use CYTools in a non-standard way.

Experimental features

There are a few experimental features that are locked by default since they haven't been through enough testing. They can be enabled as follows.

import cytools
cytools.config.enable_experimental_features()

More details can be found in the experimental features section.

Restricting parallelism

When running multiple scripts at the same time, it can be detrimental if each process tries to use all available CPU threads. To limit the number of CPU threads that CYTools uses you can set the n_threads variable, say to 1, as follows.

import cytools
cytools.config.n_threads = 1

Mosek license

By default, Mosek looks for its license file at ~/mosek/mosek.lic, or at the path given by the MOSEKLM_LICENSE_FILE environment variable. If the license file is stored somewhere else, you can specify its location as follows.

import cytools
cytools.config.set_mosek_path("/path/to/mosek.lic")

See the advanced usage page for instructions on how to obtain a license.

Reference

Configuration options for CYTools.

This module, accessible as cytools.config, holds a few settings that control how CYTools runs, as well as the switch that unlocks its experimental features.

CYTools can use the Mosek optimizer, when it is installed and licensed, for some optimization problems in high dimensions, where the other available solvers can be less reliable, such as those in Cone.tip_of_stretched_cone and Cone.find_interior_point for cones in 25 or more dimensions. When Mosek is not available, an alternative optimizer is used. By default, the license is located through Mosek's own discovery mechanism (the MOSEKLM_LICENSE_FILE environment variable, or ~/mosek/mosek.lic); a license stored elsewhere can be specified with set_mosek_path.

Attributes:

  • n_threads (int | None) –

    The number of CPU threads to use in parallelized computations, such as finding the extremal rays of a cone with Cone.extremal_rays. If None, the number is chosen automatically: a single thread is used for small problems, and all available threads otherwise. When running several CYTools processes at the same time, it is usually best to set this to a small number such as 1.

Examples:

We restrict CYTools to a single CPU thread, and then enable the experimental features.

>>> import cytools
>>> cytools.config.n_threads = 1
>>> cytools.config.enable_experimental_features()

Functions:

check_mosek_license

check_mosek_license(silent=False)

Check whether Mosek is installed and has a valid license.

This tries to solve an empty optimization problem with Mosek, and records whether it succeeded, which is what mosek_is_activated reports. If a custom license path was set with set_mosek_path, the MOSEKLM_LICENSE_FILE environment variable is set to it first.

The license is checked automatically the first time Mosek might be used, so there is usually no need to call this function directly.

Parameters:

  • silent (bool, default: False ) –

    Whether to suppress the printed messages. Otherwise, a message is printed saying either that Mosek was successfully activated or why it could not be used.

Examples:

We check the Mosek license. If Mosek is working, a success message is printed. Otherwise, a message explaining the problem is printed.

>>> import cytools
>>> cytools.config.check_mosek_license()
Mosek was successfully activated.

enable_experimental_features

enable_experimental_features()

Enable the experimental features of CYTools.

Some features are locked by default because they have not been tested enough, such as Calabi-Yau manifolds of dimension other than 3, non-favorable Calabi-Yau hypersurfaces, complete intersection Calabi-Yaus, and generic divisor and curve bases specified as matrices. This function unlocks them for the rest of the session and emits a warning, since these features may be broken or change significantly in future versions. See the Experimental Features page of the documentation for more details.

Examples:

We enable the experimental features.

>>> import cytools
>>> cytools.config.enable_experimental_features()

mosek_is_activated

mosek_is_activated()

Return whether Mosek is installed and has a valid license.

The license is checked (silently) with check_mosek_license the first time this function is called, and the result is reused afterwards. Calling check_mosek_license or set_mosek_path again updates it.

Returns:

  • bool –

    Whether Mosek can be used.

Examples:

We check whether Mosek is available. The result depends on the local installation.

>>> import cytools
>>> cytools.config.mosek_is_activated()
False

set_mosek_path

set_mosek_path(path)

Set a custom path to the Mosek license file.

This is needed when the license is stored in a location where Mosek does not find it by default. The path is exported through the MOSEKLM_LICENSE_FILE environment variable, and the license is then checked with check_mosek_license, which prints whether Mosek could be activated.

Parameters:

  • path (str) –

    The path to the Mosek license file.

Examples:

We set the path to a license file stored in a custom location.

>>> import cytools
>>> cytools.config.set_mosek_path("/path/to/mosek.lic")