diff --git a/.cz.toml b/.cz.toml index 0bcb6f8..3e85a17 100644 --- a/.cz.toml +++ b/.cz.toml @@ -1,7 +1,7 @@ [tool.commitizen] name = "cz_customize" tag_format = "v$version" -version = "7.7.0" +version = "7.7.1" version_scheme = "semver" version_files = [ "pyproject.toml:version", diff --git a/CHANGELOG.md b/CHANGELOG.md index da60980..a86d5a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 7.7.1 (2026-04-23) + + +### Fixed + +- Make max_batch_cost optional with default none, and a float. + + ## 7.7.0 (2026-04-17) diff --git a/pyproject.toml b/pyproject.toml index bbec869..161f202 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "quantinuum-schemas" -version = "7.7.0" +version = "7.7.1" description = "Shared data models for Quantinuum." authors = [ {name = "Matthew Burke", email = "matthew.burke@quantinuum.com"}, diff --git a/quantinuum_schemas/models/backend_config.py b/quantinuum_schemas/models/backend_config.py index 618873c..4d05225 100644 --- a/quantinuum_schemas/models/backend_config.py +++ b/quantinuum_schemas/models/backend_config.py @@ -212,6 +212,7 @@ class Batchable(Protocol): batch_id: UUID | None attempt_batching: bool + max_batch_cost: float | None targets_hardware_device: Callable[..., bool] @@ -242,6 +243,17 @@ def warn_if_backend_doesnt_support_batching(self: BatchableT) -> BatchableT: ) return self + @model_validator(mode="after") + def warn_if_max_batch_cost_is_unset(self: BatchableT) -> BatchableT: + """Warns if attempt_batching is true and batch_max_hqc is unset""" + + if self.attempt_batching and self.max_batch_cost is None: + warnings.warn( + "max_batch_cost is unset. Your organisation's value will be used instead.", + RuntimeWarning, + ) + return self + class QuantinuumConfig(BaseBackendConfig, BatchingValidationMixin): """Runs circuits on Quantinuum's quantum devices and simulators. @@ -287,7 +299,7 @@ class QuantinuumConfig(BaseBackendConfig, BatchingValidationMixin): noisy_simulation: bool = True target_2qb_gate: Optional[str] = None user_group: Optional[str] = None - max_batch_cost: int = 2000 + max_batch_cost: Optional[float] = None compiler_options: Optional[QuantinuumCompilerOptions] = None no_opt: bool = True allow_2q_gate_rebase: bool = False @@ -523,7 +535,7 @@ class HeliosConfig(BaseBackendConfig, BatchingValidationMixin): attempt_batching: bool = False batch_id: Optional[UUID] = None - max_batch_cost: float = 2000.0 + max_batch_cost: Optional[float] = None options: QuantinuumOptions | None = None diff --git a/tests/models/test_backend_config.py b/tests/models/test_backend_config.py index 70710ee..05b4002 100644 --- a/tests/models/test_backend_config.py +++ b/tests/models/test_backend_config.py @@ -186,19 +186,32 @@ def test_attempt_batching_against_simulators() -> None: system_name="Helios-1E", emulator_config=HeliosEmulatorConfig(), attempt_batching=True, + max_batch_cost=2000.0, + ) + HeliosConfig( + system_name="Helios-1SC", attempt_batching=True, max_batch_cost=2000.0 + ) + QuantinuumConfig( + device_name="H2-1E", attempt_batching=True, max_batch_cost=2000.0 + ) + QuantinuumConfig( + device_name="H1-Emulator", attempt_batching=True, max_batch_cost=2000.0 + ) + QuantinuumConfig( + device_name="H2-1SC", attempt_batching=True, max_batch_cost=2000.0 ) - HeliosConfig(system_name="Helios-1SC", attempt_batching=True) - QuantinuumConfig(device_name="H2-1E", attempt_batching=True) - QuantinuumConfig(device_name="H1-Emulator", attempt_batching=True) - QuantinuumConfig(device_name="H2-1SC", attempt_batching=True) assert len(record) == 5, record assert all([error_string in str(i.message) for i in record]), record with warnings.catch_warnings(record=True) as captured_warnings: # test valid configs don't throw warning. - HeliosConfig(system_name="Helios-1", attempt_batching=True) - QuantinuumConfig(device_name="H2-2", attempt_batching=True) + HeliosConfig( + system_name="Helios-1", attempt_batching=True, max_batch_cost=2000.0 + ) + QuantinuumConfig( + device_name="H2-2", attempt_batching=True, max_batch_cost=2000.0 + ) # if attempt batching is false, no warning is throw HeliosConfig(system_name="Helios-1E", emulator_config=HeliosEmulatorConfig()) HeliosConfig(system_name="Helios-1SC") @@ -206,3 +219,27 @@ def test_attempt_batching_against_simulators() -> None: QuantinuumConfig(device_name="H1-Emulator") QuantinuumConfig(device_name="H2-1SC") assert not captured_warnings + + +def test_match_batch_cost_warns_if_needed() -> None: + """Test warning if attempt_batching is True and max_batch_cost is unset.""" + error_string = ( + "max_batch_cost is unset. Your organisation's value will be used instead." + ) + with pytest.warns(RuntimeWarning) as record: + # test warning if max_batch_cost is unset. + HeliosConfig(system_name="Helios-1", attempt_batching=True) + QuantinuumConfig(device_name="H2-2", attempt_batching=True) + + assert len(record) == 2, record + assert all([error_string in str(i.message) for i in record]), record + + with warnings.catch_warnings(record=True) as captured_warnings: + # test warning isn't thrown when max_batch_cost is set. + HeliosConfig( + system_name="Helios-1", attempt_batching=True, max_batch_cost=2000.0 + ) + QuantinuumConfig( + device_name="H2-2", attempt_batching=True, max_batch_cost=2000.0 + ) + assert not captured_warnings diff --git a/uv.lock b/uv.lock index e149865..a476558 100644 --- a/uv.lock +++ b/uv.lock @@ -833,7 +833,7 @@ wheels = [ [[package]] name = "quantinuum-schemas" -version = "7.7.0" +version = "7.7.1" source = { editable = "." } dependencies = [ { name = "orjson" },