mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 19:44:57 -05:00
feat: add option to print optimizer output
This commit is contained in:
@@ -374,11 +374,12 @@ class Compiler:
|
||||
if self.artifacts is not None:
|
||||
self.artifacts.add_mlir_to_compile(mlir)
|
||||
|
||||
if (
|
||||
self.configuration.verbose
|
||||
or self.configuration.show_graph
|
||||
or self.configuration.show_mlir
|
||||
):
|
||||
show_graph = self.configuration.verbose or self.configuration.show_graph
|
||||
show_mlir = self.configuration.verbose or self.configuration.show_mlir
|
||||
show_optimizer = self.configuration.verbose or self.configuration.show_optimizer
|
||||
|
||||
columns = 0
|
||||
if show_graph or show_mlir or show_optimizer:
|
||||
|
||||
graph = (
|
||||
self.graph.format()
|
||||
@@ -404,7 +405,7 @@ class Compiler:
|
||||
except OSError: # pragma: no cover
|
||||
columns = min(longest_line, 80)
|
||||
|
||||
if self.configuration.verbose or self.configuration.show_graph:
|
||||
if show_graph:
|
||||
print()
|
||||
|
||||
print("Computation Graph")
|
||||
@@ -414,13 +415,8 @@ class Compiler:
|
||||
|
||||
print()
|
||||
|
||||
if self.configuration.verbose or self.configuration.show_mlir:
|
||||
print(
|
||||
"\n"
|
||||
if not (self.configuration.verbose or self.configuration.show_graph)
|
||||
else "",
|
||||
end="",
|
||||
)
|
||||
if show_mlir:
|
||||
print("\n" if not show_graph else "", end="")
|
||||
|
||||
print("MLIR")
|
||||
print("-" * columns)
|
||||
@@ -429,6 +425,12 @@ class Compiler:
|
||||
|
||||
print()
|
||||
|
||||
if show_optimizer:
|
||||
print("\n" if not (show_graph or show_mlir) else "", end="")
|
||||
|
||||
print("Optimizer")
|
||||
print("-" * columns)
|
||||
|
||||
circuit = Circuit(self.graph, mlir, self.configuration)
|
||||
if not self.configuration.virtual:
|
||||
assert circuit.client.specs.client_parameters is not None
|
||||
@@ -436,6 +438,14 @@ class Compiler:
|
||||
self.artifacts.add_client_parameters(
|
||||
circuit.client.specs.client_parameters.serialize()
|
||||
)
|
||||
|
||||
if show_optimizer:
|
||||
if self.configuration.virtual:
|
||||
print("Virtual circuits doesn't have optimizer output.")
|
||||
|
||||
print("-" * columns)
|
||||
print()
|
||||
|
||||
return circuit
|
||||
|
||||
except Exception: # pragma: no cover
|
||||
|
||||
@@ -17,6 +17,7 @@ class Configuration:
|
||||
verbose: bool
|
||||
show_graph: bool
|
||||
show_mlir: bool
|
||||
show_optimizer: bool
|
||||
dump_artifacts_on_unexpected_failures: bool
|
||||
enable_unsafe_features: bool
|
||||
virtual: bool
|
||||
@@ -59,6 +60,7 @@ class Configuration:
|
||||
verbose: bool = False,
|
||||
show_graph: bool = False,
|
||||
show_mlir: bool = False,
|
||||
show_optimizer: bool = False,
|
||||
dump_artifacts_on_unexpected_failures: bool = True,
|
||||
enable_unsafe_features: bool = False,
|
||||
virtual: bool = False,
|
||||
@@ -73,6 +75,7 @@ class Configuration:
|
||||
self.verbose = verbose
|
||||
self.show_graph = show_graph
|
||||
self.show_mlir = show_mlir
|
||||
self.show_optimizer = show_optimizer
|
||||
self.dump_artifacts_on_unexpected_failures = dump_artifacts_on_unexpected_failures
|
||||
self.enable_unsafe_features = enable_unsafe_features
|
||||
self.virtual = virtual
|
||||
|
||||
@@ -87,6 +87,7 @@ class Server:
|
||||
options.set_dataflow_parallelize(configuration.dataflow_parallelize)
|
||||
options.set_auto_parallelize(configuration.auto_parallelize)
|
||||
options.set_p_error(configuration.p_error)
|
||||
options.set_display_optimizer_choice(configuration.verbose or configuration.show_optimizer)
|
||||
|
||||
if configuration.jit:
|
||||
|
||||
|
||||
@@ -66,10 +66,10 @@ def test_compiler_verbose_compile(helpers, capsys):
|
||||
return x + 42
|
||||
|
||||
inputset = range(10)
|
||||
function.compile(inputset, configuration, artifacts, show_graph=True, show_mlir=True)
|
||||
function.compile(inputset, configuration, artifacts, verbose=True)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == (
|
||||
assert captured.out.strip().startswith(
|
||||
f"""
|
||||
|
||||
Computation Graph
|
||||
@@ -80,7 +80,48 @@ Computation Graph
|
||||
MLIR
|
||||
--------------------------------------------------------------------------------
|
||||
{artifacts.mlir_to_compile}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Optimizer
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
""".strip()
|
||||
)
|
||||
|
||||
|
||||
def test_compiler_verbose_virtual_compile(helpers, capsys):
|
||||
"""
|
||||
Test `compile` method of `compiler` decorator with verbose flag.
|
||||
"""
|
||||
|
||||
configuration = helpers.configuration()
|
||||
artifacts = DebugArtifacts()
|
||||
|
||||
@compiler({"x": "encrypted"})
|
||||
def function(x):
|
||||
return x + 42
|
||||
|
||||
inputset = range(10)
|
||||
function.compile(inputset, configuration, artifacts, verbose=True, virtual=True)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == (
|
||||
f"""
|
||||
|
||||
Computation Graph
|
||||
------------------------------------------------
|
||||
{list(artifacts.textual_representations_of_graphs.values())[-1][-1]}
|
||||
------------------------------------------------
|
||||
|
||||
MLIR
|
||||
------------------------------------------------
|
||||
Virtual circuits doesn't have MLIR.
|
||||
------------------------------------------------
|
||||
|
||||
Optimizer
|
||||
------------------------------------------------
|
||||
Virtual circuits doesn't have optimizer output.
|
||||
------------------------------------------------
|
||||
|
||||
""".strip()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user