From 0d07e3bff2d3cd84112ec484edac8f3245ee0aa7 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Mon, 24 Jun 2024 18:06:03 +0200 Subject: [PATCH] Option to load custom RE parameters in DF chemistry sample. --- samples/estimation/df-chemistry/README.md | 14 ++++--- samples/estimation/df-chemistry/chemistry.py | 39 +++++++++++++++----- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/samples/estimation/df-chemistry/README.md b/samples/estimation/df-chemistry/README.md index 04f120f7b8..604b2adb7f 100644 --- a/samples/estimation/df-chemistry/README.md +++ b/samples/estimation/df-chemistry/README.md @@ -1,10 +1,10 @@ # Resource Estimation for Double-factorized Chemistry -In this sample we evaluate the physical resource estimates of using the so-called double-factorized qubitization algorithm described in [[Phys. Rev. Research 3, 033055 (2021)](https://doi.org/10.1103/PhysRevResearch.3.033055)] to calculate the energy of a user provided Hamiltonian to chemical accuracy of 1 mHa. +In this sample we evaluate the physical resource estimates of using the so-called double-factorized qubitization algorithm described in [[Phys. Rev. Research 3, 033055 (2021)](https://doi.org/10.1103/PhysRevResearch.3.033055)] to calculate the energy of a user provided Hamiltonian to chemical accuracy of 1 mHa. The Hamiltonian is provided as an FCIDUMP file that is available on your machine or can be downloaded via an HTTPS URL. -``` +```text usage: chemistry.py [-h] [-f FCIDUMPFILE] Double-factorized chemistry sample @@ -13,20 +13,24 @@ options: -h, --help show this help message and exit -f FCIDUMPFILE, --fcidumpfile FCIDUMPFILE Path to the FCIDUMP file describing the Hamiltonian + -p [PARAMSFILE ...], --paramsfile [PARAMSFILE ...] + Optional parameter files to use for estimation ``` For example, the following command will download the FCIDUMP file `n2-10e-8o` to the working folder and run resource estimation for it: -``` +```shell chemistry.py -f https://aka.ms/fcidump/n2-10e-8o ``` After that, you can pass the path to the downloaded file to the script instead: -``` +```shell chemistry.py -f n2-10e-8o ``` +By default, physical resources are estimates for a Majorana based qubit with 10⁻⁶ error rates (`qubit_maj_ns_e6`), a Floquet code QEC scheme. The error budget is set to 0.01 to reach the required chemical accuracy of 1 mHa. The `-p` program argument can be used to load other resource estimation parameters, specified in JSON files. The JSON files can either contain a JSON object for one configuration, or an array of JSON objects for multiple configurations. Make sure to set the error budget to 0.01 to guarantee the correct chemical accuracy. + You can choose some of the following URLs to download example files: | URL | Instance name | Description | @@ -37,4 +41,4 @@ You can choose some of the following URLs to download example files: | https://aka.ms/fcidump/fe2s2-10e-40o | fe2s2-10e-40o | 10 electron, 40 orbital active space of [2Fe, 2S] cluster that is shown in [this paper](https://www.nature.com/articles/nchem.2041) | | https://aka.ms/fcidump/polyyne-24e-24o | polyyne-24e-24o | 24 electron, 24 orbital active space of the polyyne molecule | -The numbers for the XVIII-cas4-fb-64e-56o instance roughly match the numbers in the paper [Assessing requirements for scaling quantum computers to real-world impact](https://aka.ms/AQ/RE/Paper), as we incorporated a few improvements in the implementation of the double-factorized chemistry algorithm as compared to the version used when the paper was published. \ No newline at end of file +The numbers for the XVIII-cas4-fb-64e-56o instance roughly match the numbers in the paper [Assessing requirements for scaling quantum computers to real-world impact](https://aka.ms/AQ/RE/Paper), as we incorporated a few improvements in the implementation of the double-factorized chemistry algorithm as compared to the version used when the paper was published. diff --git a/samples/estimation/df-chemistry/chemistry.py b/samples/estimation/df-chemistry/chemistry.py index a1a063676c..e421781332 100644 --- a/samples/estimation/df-chemistry/chemistry.py +++ b/samples/estimation/df-chemistry/chemistry.py @@ -1,5 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +import json import math import numpy as np import numpy.typing as npt @@ -445,6 +446,12 @@ def ndarray2d_to_string(arr): default="https://aka.ms/fcidump/n2-10e-8o", help="Path to the FCIDUMP file describing the Hamiltonian", ) +parser.add_argument( + "-p", + "--paramsfile", + nargs="*", + help="Optional parameter files to use for estimation", +) args = parser.parse_args() # ----- Read the FCIDUMP file and get resource estimates from Q# algorithm ----- @@ -479,14 +486,27 @@ def ndarray2d_to_string(arr): "Microsoft.Quantum.Applications.Chemistry.DoubleFactorizedChemistryParameters(0.001,))" ) -# Get resource estimates -res = qsharp.estimate( - qsharp_string, - params={ +# Collect resource estimation parameters +if args.paramsfile is None: + params = { "errorBudget": 0.01, "qubitParams": {"name": "qubit_maj_ns_e6"}, "qecScheme": {"name": "floquet_code"}, - }, + } +else: + params = [] + for paramsfile in args.paramsfile: + with open(paramsfile) as f: + data = json.load(f) + if isinstance(data, dict): + params.append(data) + else: + params += data + +# Get resource estimates +res = qsharp.estimate( + qsharp_string, + params=params, ) # Store estimates in json file @@ -494,8 +514,9 @@ def ndarray2d_to_string(arr): f.write(res.json) # Print high-level resource estimation results -print(f"Algorithm runtime: {res['physicalCountsFormatted']['runtime']}") -print( - f"Number of physical qubits required: {res['physicalCountsFormatted']['physicalQubits']}" -) +if "physicalCountsFormatted" in res: + print(f"Algorithm runtime: {res['physicalCountsFormatted']['runtime']}") + print( + f"Number of physical qubits required: {res['physicalCountsFormatted']['physicalQubits']}" + ) print("For more detailed resource counts, see file resource_estimate.json")