Skip to content

Commit

Permalink
Raise DeprecationWarning if TketOptimizations.GlobalisePhasedX is set. (
Browse files Browse the repository at this point in the history
#7)

* Raise DeprecationWarning if TketOptimizations.GlobalisePhasedX is set.
  • Loading branch information
keriksson-rosenqvist authored Jan 7, 2025
1 parent dbfcb83 commit 249067a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions compiler_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import inspect
import re
import sys
import warnings
from enum import Enum, Flag, IntEnum, auto
from typing import List, Optional

Expand Down Expand Up @@ -352,6 +353,19 @@ def minimum(self):
self.tket_optimizations = TketOptimizations.DefaultMappingPass
return self

def __setattr__(self, attr, value):
if (
isinstance(value, TketOptimizations)
and TketOptimizations.GlobalisePhasedX in value
):
warnings.warn(
"Tket flag TketOptimizations.GlobalisePhasedX has been "
"deprecated and will be removed in the next version.",
DeprecationWarning,
stacklevel=2,
)
super().__setattr__(attr, value)

def __contains__(self, item):
if isinstance(item, TketOptimizations) and item in self.tket_optimizations:
return True
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "compiler-config"
version = "0.1.0"
version = "0.1.1"
description = ""
authors = ["jamie <[email protected]>"]
readme = "README.md"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
QiskitOptimizations,
QuantumResultsFormat,
ResultsFormatting,
Tket,
TketOptimizations,
)

Expand Down Expand Up @@ -171,3 +172,14 @@ def test_json_version_compatibility_full(version):
)
assert deserialised_conf.optimizations.qiskit_optimizations == QiskitOptimizations.Empty
assert deserialised_conf.optimizations.tket_optimizations == TketOptimizations.One


@pytest.mark.parametrize("flag", [to for to in TketOptimizations])
def test_tket_flags(flag):
tket = None
if flag == TketOptimizations.GlobalisePhasedX:
with pytest.warns(DeprecationWarning):
tket = Tket(tket_optimization=flag)
else:
tket = Tket(tket_optimization=flag)
assert flag in tket

0 comments on commit 249067a

Please sign in to comment.