-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,885 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
compilers/concrete-compiler/compiler/lib/Bindings/Python/concrete/compiler/server_circuit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. | ||
# See https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt for license information. | ||
|
||
"""ServerCircuit.""" | ||
|
||
# pylint: disable=no-name-in-module,import-error | ||
from mlir._mlir_libs._concretelang._compiler import ( | ||
ServerCircuit as _ServerCircuit, | ||
) | ||
|
||
# pylint: enable=no-name-in-module,import-error | ||
from .wrapper import WrapperCpp | ||
from .public_arguments import PublicArguments | ||
from .public_result import PublicResult | ||
from .evaluation_keys import EvaluationKeys | ||
|
||
|
||
class ServerCircuit(WrapperCpp): | ||
"""ServerCircuit references a circuit that can be called for execution and simulation.""" | ||
|
||
def __init__(self, server_circuit: _ServerCircuit): | ||
"""Wrap the native Cpp object. | ||
Args: | ||
server_circuit (_ServerCircuit): object to wrap | ||
Raises: | ||
TypeError: if server_circuit is not of type _ServerCircuit | ||
""" | ||
if not isinstance(server_circuit, _ServerCircuit): | ||
raise TypeError( | ||
f"server_circuit must be of type _ServerCircuit, not {type(server_circuit)}" | ||
) | ||
super().__init__(server_circuit) | ||
|
||
def call( | ||
self, | ||
public_arguments: PublicArguments, | ||
evaluation_keys: EvaluationKeys, | ||
) -> PublicResult: | ||
"""Executes the circuit on the public arguments. | ||
Args: | ||
public_arguments (PublicArguments): public arguments to execute on | ||
execution_keys (EvaluationKeys): evaluation keys to use for execution. | ||
Raises: | ||
TypeError: if public_arguments is not of type PublicArguments, or if evaluation_keys is not of type EvaluationKeys | ||
Returns: | ||
PublicResult: A public result object containing the results. | ||
""" | ||
if not isinstance(public_arguments, PublicArguments): | ||
raise TypeError( | ||
f"public_arguments must be of type PublicArguments, not " | ||
f"{type(public_arguments)}" | ||
) | ||
if not isinstance(evaluation_keys, EvaluationKeys): | ||
raise TypeError( | ||
f"simulation must be of type EvaluationKeys, not " f"{type(evaluation_keys)}" | ||
) | ||
return PublicResult.wrap( | ||
self.cpp().call( | ||
public_arguments.cpp(), evaluation_keys.cpp() | ||
) | ||
) | ||
|
||
def simulate( | ||
self, | ||
public_arguments: PublicArguments, | ||
) -> PublicResult: | ||
"""Simulates the circuit on the public arguments. | ||
Args: | ||
public_arguments (PublicArguments): public arguments to execute on | ||
Raises: | ||
TypeError: if public_arguments is not of type PublicArguments | ||
Returns: | ||
PublicResult: A public result object containing the results. | ||
""" | ||
if not isinstance(public_arguments, PublicArguments): | ||
raise TypeError( | ||
f"public_arguments must be of type PublicArguments, not " | ||
f"{type(public_arguments)}" | ||
) | ||
return PublicResult.wrap( | ||
self.cpp().simulate( | ||
public_arguments.cpp() | ||
) | ||
) |
84 changes: 84 additions & 0 deletions
84
compilers/concrete-compiler/compiler/lib/Bindings/Python/concrete/compiler/server_program.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. | ||
# See https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt for license information. | ||
|
||
"""ServerProgram.""" | ||
|
||
# pylint: disable=no-name-in-module,import-error | ||
from mlir._mlir_libs._concretelang._compiler import ( | ||
ServerProgram as _ServerProgram, | ||
) | ||
|
||
# pylint: enable=no-name-in-module,import-error | ||
from .wrapper import WrapperCpp | ||
from .library_support import LibrarySupport | ||
from .server_circuit import ServerCircuit | ||
|
||
|
||
class ServerProgram(WrapperCpp): | ||
"""ServerProgram references compiled circuit objects.""" | ||
|
||
def __init__(self, server_program: _ServerProgram): | ||
"""Wrap the native Cpp object. | ||
Args: | ||
server_program (_ServerProgram): object to wrap | ||
Raises: | ||
TypeError: if server_program is not of type _ServerProgram | ||
""" | ||
if not isinstance(server_program, _ServerProgram): | ||
raise TypeError( | ||
f"server_program must be of type _ServerProgram, not {type(server_program)}" | ||
) | ||
super().__init__(server_program) | ||
|
||
def load( | ||
library_support: LibrarySupport, | ||
simulation: bool, | ||
) -> "ServerProgram": | ||
"""Loads the server program from a library support. | ||
Args: | ||
library_support (LibrarySupport): library support | ||
simulation (bool): use simulation for execution | ||
Raises: | ||
TypeError: if library_support is not of type LibrarySupport, or if simulation is not of type bool | ||
Returns: | ||
ServerProgram: A server program object containing references to circuits for calls. | ||
""" | ||
if not isinstance(library_support, LibrarySupport): | ||
raise TypeError( | ||
f"library_support must be of type LibrarySupport, not " | ||
f"{type(library_support)}" | ||
) | ||
if not isinstance(simulation, bool): | ||
raise TypeError( | ||
f"simulation must be of type bool, not " f"{type(simulation)}" | ||
) | ||
return ServerProgram.wrap( | ||
_ServerProgram.load( | ||
library_support.cpp(), simulation | ||
) | ||
) | ||
|
||
|
||
def get_server_circuit(self, circuit_name: str) -> ServerCircuit: | ||
"""Returns a given circuit if it is part of the program. | ||
Args: | ||
circuit_name (str): name of the circuit to retrieve. | ||
Raises: | ||
TypeError: if circuit_name is not of type str | ||
RuntimeError: if the circuit is not part of the program | ||
""" | ||
if not isinstance(circuit_name, str): | ||
raise TypeError( | ||
f"circuit_name must be of type str, not {type(circuit_name)}" | ||
) | ||
|
||
return ServerCircuit.wrap( | ||
self.cpp().get_server_circuit(circuit_name) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.