Skip to content

Commit 3a31e9c

Browse files
committed
changed to ruff format
1 parent 2133b93 commit 3a31e9c

29 files changed

Lines changed: 116 additions & 108 deletions

examples/compare_enumeration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def gen_distance(non_terminals: int) -> CFG:
240240
syntax[f"cast{i}"] = f"s{i} -> s1"
241241
syntax[f"s{i}"] = f"s{i}"
242242
syntax[f"+{i}"] = f"s1 -> s{i} -> s{i}"
243-
syntax[f"*{i}"] = f"s{i-1} -> s{i} -> s{i+1} -> s{i}"
243+
syntax[f"*{i}"] = f"s{i - 1} -> s{i} -> s{i + 1} -> s{i}"
244244
return CFG.infinite(DSL(auto_type(syntax)), auto_type("s1->s1"), n_gram=1)
245245

246246

examples/pbe/convert_to_psl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
fd.write(f"\n{COMMENT_PREFIX} Function Synthesis\n")
6262
fd.write("(synth-fun f ")
6363
for j, arg in enumerate(task.type_request.arguments()):
64-
fd.write(f"(x{j+1} {arg}) ")
64+
fd.write(f"(x{j + 1} {arg}) ")
6565
fd.write(f"{task.type_request.returns()})\n")
6666

6767
fd.write(f"\n{COMMENT_PREFIX} PBE Examples\n")

examples/pbe/dataset_generator_unique.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def generate_samples_for(
292292
pbar.n = nb_examples * abs(threshold)
293293
pbar.refresh()
294294
pbar.set_postfix_str(
295-
f"{len(equiv_classes)}->{best_score} | {best_score/len(programs):.0%}"
295+
f"{len(equiv_classes)}->{best_score} | {best_score / len(programs):.0%}"
296296
)
297297
pbar.update(1)
298298
nb_tested += 1

examples/pbe/dsl_equation_generator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ def check_program(
218218
is_list_constant = True
219219
my_outputs = []
220220
candidates = set(all_sol.keys())
221-
is_identity = [len(program.used_variables()) == 1 for _ in program.type.arguments()]
221+
is_identity = [
222+
set([i]) == arg.used_variables() for i, arg in enumerate(program.arguments)
223+
]
222224
for i, inp in enumerate(inputs):
223225
out = our_eval(program, inp)
224226
# Update candidates
@@ -280,6 +282,9 @@ def check_symmetries() -> None:
280282
if current_prog in programs_done:
281283
continue
282284
programs_done.add(current_prog)
285+
used = current_prog.used_variables()
286+
if len(used) == 1 and 0 not in used:
287+
continue
283288
is_constant, is_identity, candidates, my_outputs = check_program(
284289
current_prog, inputs, all_sol
285290
)
@@ -313,6 +318,9 @@ def check_equivalent() -> None:
313318
for done, program in enumerate(get_enumerator(cfg)):
314319
if program in programs_done:
315320
continue
321+
used = program.used_variables()
322+
if len(used) == 1 and 0 not in used:
323+
continue
316324
is_constant, is_identity, candidates, my_outputs = check_program(
317325
program, inputs, all_sol
318326
)
@@ -349,7 +357,7 @@ def update_filter(
349357
builder = equivalence_classes_to_filters(commutatives, classes, dsl)
350358
if verbose:
351359
print(
352-
f"\tfound {F.YELLOW}{builder.stats['constraints.successes']}{F.RESET} ({F.YELLOW}{builder.stats['constraints.successes']/builder.stats['constraints.total']:.1%}{F.RESET}) constraints"
360+
f"\tfound {F.YELLOW}{builder.stats['constraints.successes']}{F.RESET} ({F.YELLOW}{builder.stats['constraints.successes'] / builder.stats['constraints.total']:.1%}{F.RESET}) constraints"
353361
)
354362
return (lambda t: builder.get_filter(t, set())), builder.stats
355363

examples/pbe/evaluate_deprecated.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@
147147
# ================================
148148

149149

150-
def load_dsl_and_dataset() -> (
151-
Tuple[Dataset[PBE], DSL, DSLEvaluatorWithConstant, List[int], str, List[str]]
152-
):
150+
def load_dsl_and_dataset() -> Tuple[
151+
Dataset[PBE], DSL, DSLEvaluatorWithConstant, List[int], str, List[str]
152+
]:
153153
dsl_module = load_DSL(dsl_name)
154154
dsl, evaluator, lexicon = dsl_module.dsl, dsl_module.evaluator, dsl_module.lexicon
155155
constraints = []

examples/pbe/karel/equivalence_classes_to_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def equivalence_classes_to_filters(
365365
added += builder.add_equivalence_class(this_class)
366366
if progress:
367367
pbar.set_postfix_str(
368-
f"{F.CYAN}{added}{F.RESET}/{total} constraints ({F.GREEN}{added/total:.1%}{F.RESET})"
368+
f"{F.CYAN}{added}{F.RESET}/{total} constraints ({F.GREEN}{added / total:.1%}{F.RESET})"
369369
)
370370
builder.compress()
371371

@@ -454,7 +454,7 @@ def derivable_program_to_code(
454454
f"found {F.CYAN}{stats['constraints.successes']}{F.RESET} ({F.GREEN}{stats['constraints.successes'] / stats['constraints.total']:.1%}{F.RESET}) constraints"
455455
)
456456
print(
457-
f"reduced size to {F.GREEN}{stats['dfta.size.final']/stats['dfta.size.initial']:.1%}{F.RESET} of original size"
457+
f"reduced size to {F.GREEN}{stats['dfta.size.final'] / stats['dfta.size.initial']:.1%}{F.RESET} of original size"
458458
)
459459
with open(output_file, "w") as fd:
460460
fd.write(builder.to_code(commented=comment))

examples/pbe/model_prediction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@
8686
# ================================
8787

8888

89-
def load_dsl_and_dataset() -> (
90-
Tuple[Dataset[PBE], DSL, List[int], str, List[str], Set[Type]]
91-
):
89+
def load_dsl_and_dataset() -> Tuple[
90+
Dataset[PBE], DSL, List[int], str, List[str], Set[Type]
91+
]:
9292
dsl_module = load_DSL(dsl_name)
9393
dsl, lexicon = dsl_module.dsl, dsl_module.lexicon
9494
constant_types: Set[Type] = set()

examples/pbe/quantum_circuits/quantum_tasks_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def circuit_to_program(circuit: qk.QuantumCircuit, dsl: DSL, tr: Type) -> Progra
183183
for qbit in inst.qubits:
184184
index, registers = circuit.find_bit(qbit)
185185
register, idx_in_reg = registers[0]
186-
program += f" {register.size-index - 1}"
186+
program += f" {register.size - index - 1}"
187187
program += ")"
188188
return dsl.parse_program(program.replace("Cx", "CNOT"), tr)
189189

examples/pbe/solve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@
180180
# ================================
181181

182182

183-
def load_dsl_and_dataset() -> (
184-
Tuple[Dataset[PBE], DSL, DSLEvaluator, List[str], Set[Type]]
185-
):
183+
def load_dsl_and_dataset() -> Tuple[
184+
Dataset[PBE], DSL, DSLEvaluator, List[str], Set[Type]
185+
]:
186186
dsl_module = load_DSL(dsl_name)
187187
dsl, evaluator = dsl_module.dsl, dsl_module.evaluator
188188
# ================================

examples/pbe/transduction/knowledge_graph/kg_path_finder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __make_query_path__(distance: int, id: int, tabs: int = 1) -> str:
1010
path = __make_query_path__(distance - 1, id, tabs) + "\n"
1111
path += (
1212
"\t" * tabs
13-
) + f"?o_{id}_{distance-1} ?p{distance} ?o_{id}_{distance} ."
13+
) + f"?o_{id}_{distance - 1} ?p{distance} ?o_{id}_{distance} ."
1414
return path
1515

1616

@@ -52,7 +52,7 @@ def build_count_paths_query(start: str, path: List[str]) -> str:
5252
sparql_request += " WHERE {\n"
5353
sparql_request += f"\tw:{__format__(start)} w:{path[0]} ?e0 ."
5454
for i in range(1, len(path) - 1):
55-
sparql_request += f"\t?e{i-1} w:{path[i]} ?e{i} ."
55+
sparql_request += f"\t?e{i - 1} w:{path[i]} ?e{i} ."
5656
sparql_request += f"\t?e{len(path) - 1} w:{path[-1]} ?dst"
5757
sparql_request += "\n}"
5858
return sparql_request

0 commit comments

Comments
 (0)