Skip to content

Std.Core.ConfigValue#3486

Merged
fedimser merged 48 commits into
mainfrom
fedimser/config-map-3
Jul 21, 2026
Merged

Std.Core.ConfigValue#3486
fedimser merged 48 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.ConfigValue 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 relaceConfigValue(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 ConfigValue("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:
    • The config must be set by passing Python dict to Context constructor. If not passed, empty dict is used.
    • 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 passing dict to Interpreter::new.
    • It's impossible to mutate config after Context is created using Python API.
  • 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.

Example:

import qdk
context = qdk.Context(qsharp_config={"experiment_name": "baseline", "shots": 1000})
assert context.eval('Std.Core.ConfigValue("experiment_name", "")') == "baseline"
assert context.eval('Std.Core.ConfigValue("shots", 100)') == 1000
assert context.eval('Std.Core.ConfigValue("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
@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for 6460e06

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for b6938c5

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for 349f986

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for 3e9dd86

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for 8f888d1

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for e135c5a

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for af2a7c3

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for b78e9c7

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@fedimser
fedimser requested a review from swernli July 20, 2026 23:05
@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for 3bc62ee

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@github-actions

Copy link
Copy Markdown

Change in memory usage detected by benchmark.

Memory Report for 9a4afbc

Test This Branch On Main Difference
compile core + standard lib 26680955 bytes 26680923 bytes 32 bytes

@fedimser
fedimser added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit d123f37 Jul 21, 2026
13 checks passed
@fedimser
fedimser deleted the fedimser/config-map-3 branch July 21, 2026 04:11
@fedimser fedimser changed the title Std.Core.GetConfig Std.Core.ConfigValue Jul 21, 2026
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.

3 participants