Coverage for /home/runner/work/tket/tket/pytket/pytket/backends/backend_exceptions.py: 64%

12 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-14 11:30 +0000

1# Copyright Quantinuum 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15from .resulthandle import ResultHandle 

16 

17 

18class CircuitNotValidError(Exception): 

19 """Raised when a submitted circuit does not satisfy all predicates""" 

20 

21 def __init__(self, message: str | int, failed_pred: str | None = None): 

22 if isinstance(message, int): 

23 message = ( 

24 "Circuit with index {0} in submitted does not satisfy " 

25 "{1} (try compiling with backend.get_compiled_circuits first)." 

26 ).format(message, failed_pred or "all predicates") 

27 super().__init__(message) 

28 

29 

30class CircuitNotRunError(Exception): 

31 """Raised when a result is retrieved corresponding to a handle that has not been 

32 executed""" 

33 

34 def __init__(self, handle: ResultHandle): 

35 super().__init__( 

36 f"Circuit corresponding to {handle!r} " 

37 "has not been run by this backend instance." 

38 ) 

39 

40 

41class InvalidResultType(Exception): 

42 """Raised when a BackendResult instance cannot produce the required result type.""" 

43 

44 def __init__(self, result_type: str): 

45 super().__init__(f"BackendResult cannot produce result of type {result_type}.")