Skip to content

Commit

Permalink
fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Oct 6, 2023
1 parent f5ef382 commit 3d4f4b0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion qlasskit/ast2logic/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def __init__(self, ob, message=None):
class OutOfBoundException(Exception):
def __init__(self, size, i):
super().__init__(f"size is {size}: {i} accessed")



class UnboundException(Exception):
def __init__(self, symbol, env):
super().__init__(f"{symbol} in {env}")
Expand Down
2 changes: 1 addition & 1 deletion qlasskit/ast2logic/t_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import ast
from typing import List, Tuple

from ..typing import Arg, Args, Qint, Qint2, Qint4, Qint8, Qint12, Qint16 # noqa: F
from ..typing import Arg, Args, Qint, Qint2, Qint4, Qint8, Qint12, Qint16 # noqa: F
from . import exceptions
from .t_expression import TType

Expand Down
7 changes: 3 additions & 4 deletions qlasskit/ast2logic/t_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from typing_extensions import TypeAlias

from . import Env, exceptions
from ..typing import Qtype

TType: TypeAlias = object

Expand Down Expand Up @@ -123,12 +122,12 @@ def unfold(v_exps, op):
te_test = translate_expression(expr.test, env)
te_true = translate_expression(expr.body, env)
te_false = translate_expression(expr.orelse, env)

if te_test[0] != bool:
raise exceptions.TypeErrorException(te_test[0], bool)

if te_true[0] != te_false[0]:
raise exceptions.TypeErrorException(te_false[0], te_true[0])
raise exceptions.TypeErrorException(te_false[0], te_true[0])

return (
te_true[0],
Expand Down
8 changes: 4 additions & 4 deletions qlasskit/qlassf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Callable, List, Tuple, Union # noqa: F401

from . import compiler
from .ast2logic import translate_ast, flatten
from .ast2logic import flatten, translate_ast
from .typing import * # noqa: F403, F401
from .typing import Args, BoolExpList

Expand Down Expand Up @@ -61,14 +61,14 @@ def __add__(self, qf2) -> "QlassF":

def truth_table_header(self) -> List[str]:
"""Returns the list of string containing the truth table header"""
header = flatten(map(lambda a: a.bitvec, self.args))
header = flatten(list(map(lambda a: a.bitvec, self.args)))
header.extend([sym.name for (sym, retex) in self.expressions[-self.ret_size :]])
return header

def truth_table(self) -> List[List[bool]]:
"""Returns the truth table for the function using the sympy boolean for computing"""
truth = []
arg_bits = flatten(map(lambda a: a.bitvec, self.args))
arg_bits = flatten(list(map(lambda a: a.bitvec, self.args)))
bits = len(arg_bits)

if (bits + self.ret_size) > MAX_TRUTH_TABLE_SIZE:
Expand Down Expand Up @@ -123,7 +123,7 @@ def gate(self, framework="qiskit"):
@property
def input_size(self) -> int:
"""Return the size of the inputs (in bits)"""
return reduce(lambda a, b: a+len(b), self.args, 0)
return reduce(lambda a, b: a + len(b), self.args, 0)

@property
def num_qubits(self) -> int:
Expand Down
10 changes: 6 additions & 4 deletions qlasskit/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,45 @@ def to_bool(self):
# return self.value



class Qint(int, Qtype):
BIT_SIZE = 8

def __init__(self, value):
super().__init__()
self.value = value


class Qint2(Qint):
BIT_SIZE = 2

def __init__(self, value):
super().__init__(value)


class Qint4(Qint):
BIT_SIZE = 4

def __init__(self, value):
super().__init__(value)


class Qint8(Qint):
BIT_SIZE = 8

def __init__(self, value):
super().__init__(value)


class Qint12(Qint):
BIT_SIZE = 12

def __init__(self, value):
super().__init__(value)


class Qint16(Qint):
BIT_SIZE = 16

def __init__(self, value):
super().__init__(value)

Expand Down
2 changes: 1 addition & 1 deletion test/test_qlassf_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from qlasskit import QlassF, exceptions, qlassf

from .utils import compare_circuit_truth_table, COMPILATION_ENABLED
from .utils import COMPILATION_ENABLED, compare_circuit_truth_table

a, b, c, d = symbols("a,b,c,d")
_ret = Symbol("_ret")
Expand Down
2 changes: 1 addition & 1 deletion test/test_qlassf_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from qlasskit import QlassF, exceptions, qlassf

from .utils import compare_circuit_truth_table, COMPILATION_ENABLED
from .utils import COMPILATION_ENABLED, compare_circuit_truth_table

a, b, c, d = symbols("a,b,c,d")
_ret = Symbol("_ret")
Expand Down

0 comments on commit 3d4f4b0

Please sign in to comment.