@click.group(invoke_without_command=True, no_args_is_help=True)
@click.pass_context
@click.version_option(cssfinder.__version__, "-V", "--version", prog_name="cssfinder")
@click.option(
"-v",
"--verbose",
default=0,
count=True,
help="Control verbosity of logging, by default+ critical only, use "
"-v, -vv, -vvv to gradually increase it.",
)
@click.option(
"--numpy-thread-count",
type=int,
default=1,
required=False,
help="NumPy thread count override. Use '-1' to disable override and use defaults.",
)
@click.option(
"--seed",
type=int,
default=None,
required=False,
help="NumPy random generator seed override.",
)
@click.option("--debug", is_flag=True, default=False)
@click.option("--rich", "--no-rich", "is_rich", is_flag=True, default=True)
@click.option("--perf-log", is_flag=True, default=False)
def main(
ctx: click.Context,
verbose: int,
seed: Optional[int],
numpy_thread_count: int,
*,
debug: bool,
is_rich: bool,
perf_log: bool,
) -> None:
"""CSSFinder is a script for finding closest separable states."""
import os
from pprint import pformat
import pendulum
import rich
from threadpoolctl import threadpool_info
if numpy_thread_count != -1:
numpy_thread_count_str = str(numpy_thread_count)
os.environ["OMP_NUM_THREADS"] = numpy_thread_count_str
os.environ["OPENBLAS_NUM_THREADS"] = numpy_thread_count_str
os.environ["MKL_NUM_THREADS"] = numpy_thread_count_str
os.environ["VECLIB_MAXIMUM_THREADS"] = numpy_thread_count_str
os.environ["NUMEXPR_NUM_THREADS"] = numpy_thread_count_str
import numpy as np
from cssfinder.log import configure_logger, enable_performance_logging
configure_logger(verbosity=verbose, logger_name="cssfinder", use_rich=is_rich)
ctx.obj = Ctx(is_debug=debug, is_rich=is_rich)
if seed is not None:
logging.debug("NumPy random number generator seed set to %d", seed)
np.random.seed(seed) # noqa: NPY002
logging.debug("\n%s", pformat(threadpool_info(), indent=4))
logging.getLogger("numba").setLevel(logging.ERROR)
logging.info("CSSFinder started at %s", pendulum.now().isoformat(sep=" "))
if perf_log:
enable_performance_logging()
if verbose >= VERBOSITY_INFO:
rich.print(
f"""{'[blue]' if is_rich else ''}
██████╗███████╗███████╗███████╗██╗███╗ ██╗██████╗ ███████╗██████╗
██╔════╝██╔════╝██╔════╝██╔════╝██║████╗ ██║██╔══██╗██╔════╝██╔══██╗
██║ ███████╗███████╗█████╗ ██║██╔██╗ ██║██║ ██║█████╗ ██████╔╝
██║ ╚════██║╚════██║██╔══╝ ██║██║╚██╗██║██║ ██║██╔══╝ ██╔══██╗
╚██████╗███████║███████║██║ ██║██║ ╚████║██████╔╝███████╗██║ ██║
╚═════╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚══════╝╚═╝ ╚═╝
""",
)