From a0713841f40915d15df4662c074ecba6085ef36e Mon Sep 17 00:00:00 2001 From: Max Radin Date: Mon, 2 Dec 2024 14:47:14 -0800 Subject: [PATCH 1/2] Updating LRE script to allow for overlaps to be specified per task --- README.md | 5 +++-- scripts/LRE_config.json | 1 + scripts/LRE_config_overlaps.json | 16 ++++++++++++++++ scripts/compute_all_LREs_script.py | 30 +++++++++++++++++++++++++++--- scripts/overlaps.csv | 4 ++++ 5 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 scripts/LRE_config_overlaps.json create mode 100644 scripts/overlaps.csv diff --git a/README.md b/README.md index 9c41335..31fdf03 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,11 @@ Contact the repository maintainers to get these. ### Generating Logical Quantum Resource Estimates The [`scripts/compute_all_LREs_script.py`](scripts/compute_all_LREs_script.py) script can be used to generate LQREs. -In order to run this script, two files are required: +In order to run this script, several files are required: * A PPK file containing a key to access the SFTP server that provides access to FCIDUMP files as described above. -* A configuration file similar to [`scripts/LRE_config.json`](scripts/LRE_config.json) which specifies algorithm parameters, solver UUID, and other information. +* A configuration file similar to [`scripts/LRE_config.json`](scripts/LRE_config.json) or [`scripts/LRE_config.json`](scripts/LRE_config_overlaps.json) which specifies algorithm parameters, solver UUID, and other information. +* If the `algorithm_parameters` object in the config file specifies a value for `overlap_csv`, then this CSV file must also be present. See for example [`scripts/overlaps.csv`](scripts/overlaps.csv) The paths to these files must be passed as arguments to the script, for example: ```bash diff --git a/scripts/LRE_config.json b/scripts/LRE_config.json index 1fbd369..7da759d 100644 --- a/scripts/LRE_config.json +++ b/scripts/LRE_config.json @@ -5,6 +5,7 @@ "df_threshold": 1e-3, "max_orbitals": 32 }, + "algorithm_description": "Double factorized QPE resource estimates based on methodology of arXiv:2406.06335. Note that the truncation error is not included in the error bounds and that the SCF compute time is not included in the preprocessing time. Also note that unlike arXiv:2406.06335, the ground-state overlaps are not computed from DMRG but instead set to a nominal value.", "contact_info": [ { "name": "Max Radin", diff --git a/scripts/LRE_config_overlaps.json b/scripts/LRE_config_overlaps.json new file mode 100644 index 0000000..c6b9868 --- /dev/null +++ b/scripts/LRE_config_overlaps.json @@ -0,0 +1,16 @@ +{ + "solver_uuid": "f2d73e1f-3058-43c4-a634-b6c267c84ff1", + "algorithm_parameters": { + "overlap_csv": "overlaps.csv", + "df_threshold": 1e-3, + "max_orbitals": 32 + }, + "algorithm_description": "Double factorized QPE resource estimates based on methodology of arXiv:2406.06335. Note that the truncation error is not included in the error bounds and that the SCF compute time is not included in the preprocessing time. Ground-state overlap is taken to be that estimated for the dominant CSF as estimated by DMRG and that this DMRG runtime is not included in the classical compute costs.", + "contact_info": [ + { + "name": "Max Radin", + "email": "radin.max@gmail.com", + "institution": "L3Harris" + } + ] +} diff --git a/scripts/compute_all_LREs_script.py b/scripts/compute_all_LREs_script.py index 2e88426..9f04c04 100755 --- a/scripts/compute_all_LREs_script.py +++ b/scripts/compute_all_LREs_script.py @@ -22,12 +22,14 @@ import math import os import sys +from collections import defaultdict from datetime import UTC from importlib.metadata import version from typing import Any from urllib.parse import urlparse from uuid import uuid4 +import pandas as pd from pyLIQTR.utils.resource_analysis import estimate_resources from qb_gsee_benchmark.qre import get_df_qpe_circuit @@ -54,10 +56,32 @@ def get_lqre( num_hams = len(problem_instance["tasks"]) logging.info(f"contains {num_hams} associated Hamiltonians.") + if ( + "overlap" in config["algorithm_parameters"] + and "overlap_csv" in config["algorithm_parameters"] + ): + raise ValueError("Config cannot specify both 'overlap' and 'overlap_csv'.") + + if config["algorithm_parameters"].get("overlap_csv"): + overlap_df = pd.read_csv(config["algorithm_parameters"]["overlap_csv"]) + overlaps = { + row["task_uuid"]: row["overlap"] for index, row in overlap_df.iterrows() + } + else: + overlaps = defaultdict(lambda: config["algorithm_parameters"]["overlap"]) + solution_data: list[dict[str, Any]] = [] results: dict[str, Any] = {} for task in problem_instance["tasks"]: + if not overlaps.get(task["task_uuid"]): + logging.info( + f"Skipping task {task['task_uuid']} because no overlap was provided." + ) + continue + + logging.info(f"Analyzing task {task['task_uuid']}...") + num_supporting_files = len(task["supporting_files"]) logging.info(f"number of supporting files: {num_supporting_files}") @@ -114,12 +138,12 @@ def get_lqre( fci=fci, error_tolerance=error_tolerance, failure_tolerance=failure_tolerance, - square_overlap=config["algorithm_parameters"]["overlap"] ** 2, + square_overlap=overlaps[task["task_uuid"]] ** 2, df_threshold=config["algorithm_parameters"]["df_threshold"], ) circuit_generation_end_time = datetime.datetime.now() logging.info( - f"Circuit initialization time: {(circuit_generation_end_time - circuit_generation_end_time).total_seconds()} seconds." + f"Circuit initialization time: {(circuit_generation_end_time - circuit_generation_start_time).total_seconds()} seconds." ) logging.info(f"Estimating logical resources...") resource_estimation_start_time = datetime.datetime.now() @@ -171,7 +195,7 @@ def get_lqre( "solver_short_name": "DF QPE", "compute_hardware_type": "quantum_computer", "algorithm_details": { - "algorithm_description": "Double factorized QPE resource estimates based on methodology of arXiv:2406.06335. Note that the truncation error is not included in the error bounds and that the SCF compute time is not included in the preprocessing time. Also note that unlike arXiv:2406.06335, the ground-state overlaps are not computed from DMRG but instead set to a nominal value.", + "algorithm_description": config["algorithm_description"], "algorithm_parameters": config["algorithm_parameters"], }, "software_details": [ diff --git a/scripts/overlaps.csv b/scripts/overlaps.csv new file mode 100644 index 0000000..2e31d2d --- /dev/null +++ b/scripts/overlaps.csv @@ -0,0 +1,4 @@ +task_uuid,overlap +be3812d3-5975-4736-8a23-96d64e50e66a,0.7085974535652702 +472bbfb1-c081-4df6-b966-32ce1194ab8c,0.9774145158534091 +a41a284c-7baa-438e-9323-532091c7a78f,0.9985372277228635 From 514a1970b8b92a49ce170746d41160e890bd8ff3 Mon Sep 17 00:00:00 2001 From: Max Radin Date: Mon, 2 Dec 2024 14:49:08 -0800 Subject: [PATCH 2/2] Updating requirements --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 9048a01..db60479 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,6 +30,7 @@ install_requires = openfermionpyscf numpy paramiko + pandas [options.packages.find]