Skip to content

[Feature request] Configuration map accessible from Q# code #3271

Description

@fedimser

Is your feature request related to a problem? Please describe.

There are multiple cases when this would be helpful:

  1. [Feature Request] [Std.ResourceEstimation] Introduce IsEstimating and Loop helpers #3109 - knowing whether we are inside resource estimator.
  2. In discussion on Manual Memory-Compute qubits #3204 it was suggested that it would be good to be able to enable manual memory-compute from Python.
  3. This repository https://github.com/microsoft/QuantumEllipticCurves defines some parameters that specify what metric to optimize and the uses them like this: https://github.com/microsoft/QuantumEllipticCurves/blob/dbf4836afaf7a9fab813cbc0970e65af85a6f93a/MicrosoftQuantumCrypto/Basics.qs#L173 .
    • This is a common pattern in resource estimation research - we would like to have one algorithm implementation but be able to optimize it for different metrics using different building blocks.

Describe the solution you'd like

All these can be addressed by having a configuration (dictionary keyed by strings) that will be available to Q# code.

Suggested Python syntax (for evaluate, run, logical_counts etc):

ctx = qdk.Context()
ctx.set_config("use_memory_qubits", True)
ctx.set_config("minimize_depth", True)
ctx.set_config("minimize_t_count", False)
ctx.eval(...)

Suggested Q# intrinsics to access the config:

function GetConfigInt(key: name): Int;
function GetConfigDouble(key: name): Double;
function GetConfigBool(key: name): Bool;
function GetConfigString(key: name): String;

Then, for example, this code can be rewritten as:

if (GetConfigBool("minimize_depth")){
    ApplyLowDepthAnd(control1, control2, target);
} else {
    ApplyAnd(control1, control2, target);
}

And this can be used to know whether we are in resource estimator or not. We will introduce some "system configs" that are always available (and forbid users to override them). For example, "is_resource_estimating" will be bool config that will be set to true for RE backend and to False for other backends.

This can be implemented in Rust (in Interpreter or in each backend) by keeping map<String, Value> where Value is defined as enum Value {Int(i64), Float(f64), Bool(bool), String(String)}. If value is not set, default value is returned.

Describe alternatives you've considered

The alternative is to pass configuration as operation arguments: define struct Config and add all configuration there. Then pass it as first or last arguments from entry point to all methods that need this. This is somewhat ugly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions