Skip to content

Std.Core.GetConfig#3486

Open
fedimser wants to merge 28 commits into
mainfrom
fedimser/config-map-3
Open

Std.Core.GetConfig#3486
fedimser wants to merge 28 commits into
mainfrom
fedimser/config-map-3

Conversation

@fedimser

@fedimser fedimser commented Jul 18, 2026

Copy link
Copy Markdown
Contributor
  • Store key-value configuration map in compiler state (actually, in PassContext).
  • Add Std.Core.GetConfig to access config value stored inside compiler state (actually it's stored in PassContext.
    • It must be in Std.Core so we can refer to it in HIR pass.
  • Add HIR transformation pass ConfigInline to relaceGetConfig(key, default) with a literal
    • If key is found, replaces call with found value.
    • Otherwise replaces with default.
    • Only supports 4 types (string, int, bool, double).
    • Error if stored or default value has type other than these 4 types, or when stored value has different type than default. This guarantees, for example, that GetConfig("key", 1) will not be replaced with a String value if config has {'key": "1"}.
    • Also require that both key and default value are literals.
  • Add Python API to set config:
    • Config must be set by passing Python dict to Context constructor. if not passed, assumed empty dict.
    • Deliberately not supported in qsharp.init.
    • Once Context is created, it's immutable. To use different config value, new Context must be created. This makes it valid for GetConfig to be a function, not operation.
    • This is propagated from Python to Rust by calling Interpreter.set_config_value for each value. This still allows to mutate config when using Rust API directly (or when using Python API and using undocumented private methods). This can be strengthened by changing Interpreter to take FxHashMap<Rc<str>, Value> as constructor argument. This will require updating few more files than the current solution.
  • Tests:
    • Unit tests for rule.
    • Interpreter tests (in compiler/qsc/src/interpret/tests.rs) using simulator, including tests for all possible errors.
    • One QIR generator test to make sure the GetConfig is inlined in QIR. This single test takes 3 seconds to run. However, We we have 24 qirgen tests, each taking 3-6 seconds to run - meaning qirgen tests are slow.

Questions:

  • Should I change API of Interpreter (in Rust) to take the config map in constructor?
  • Should I fold QIRgen test into one of existing QIRgen tests or +3 seconds increase in test time is ok? I owuld like to have at least one test checking GetConfig with QIR.

Example:

import qdk
context = qdk.Context(qsharp_config={"experiment_name": "baseline", "shots": 1000})
assert context.eval('Std.Core.GetConfig("experiment_name", "")') == "baseline"
assert context.eval('Std.Core.GetConfig("shots", 100)') == 1000
assert context.eval('Std.Core.GetConfig("noise_level", 0.01)') == 0.01

Comment thread source/compiler/qsc/src/interpret/tests.rs Fixed
Comment thread source/compiler/qsc_passes/src/config_inline/tests.rs Fixed
Comment thread source/qdk_package/tests/test_context.py Fixed
@fedimser fedimser changed the title [Draft] Std.Core.GetConfig Std.Core.GetConfig Jul 18, 2026
@fedimser
fedimser marked this pull request as ready for review July 18, 2026 03:17
@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for 04414f1

Test This Branch On Main Difference
compile core + standard lib 26677907 bytes 26677875 bytes 32 bytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants