From a9bbf90f9bf91d095ca4dc0625daf39e62a9e8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Abad=20L=C3=B3pez?= <109400222+GuillermoAbadLopez@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:54:19 +0100 Subject: [PATCH] Take optimize parameter in cascade up, to the user calls --- src/qililab/digital/circuit_transpiler.py | 2 +- src/qililab/execute_circuit.py | 3 +++ src/qililab/platform/platform.py | 8 ++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/qililab/digital/circuit_transpiler.py b/src/qililab/digital/circuit_transpiler.py index f8cb7f48a..b3b379877 100644 --- a/src/qililab/digital/circuit_transpiler.py +++ b/src/qililab/digital/circuit_transpiler.py @@ -102,7 +102,7 @@ def transpile_circuits( router (Router | type[Router] | tuple[type[Router], dict], optional): `Router` instance, or subclass `type[Router]` to use, with optionally, its kwargs dict (other than connectivity), both in a tuple. Defaults to `Sabre`. routing_iterations (int, optional): Number of times to repeat the routing pipeline, to get the best stochastic result. Defaults to 10. - optimize (bool, optional): whether to optimize the transpilation. Defaults to True. + optimize (bool, optional): whether to optimize the circuit and/or transpilation. Defaults to True. Returns: tuple[list[PulseSchedule],list[dict[str, int]]]: list of pulse schedules and list of the final layouts of the qubits, in each circuit {"qI": J}. diff --git a/src/qililab/execute_circuit.py b/src/qililab/execute_circuit.py index f050826f7..cd28855b2 100644 --- a/src/qililab/execute_circuit.py +++ b/src/qililab/execute_circuit.py @@ -31,6 +31,7 @@ def execute( placer: Placer | type[Placer] | tuple[type[Placer], dict] | None = None, router: Router | type[Router] | tuple[type[Router], dict] | None = None, routing_iterations: int = 10, + optimize: bool = True, ) -> Result | list[Result]: """Executes a Qibo circuit (or a list of circuits) with qililab and returns the results. @@ -47,6 +48,7 @@ def execute( router (Router | type[Router] | tuple[type[Router], dict], optional): `Router` instance, or subclass `type[Router]` to use,` with optionally, its kwargs dict (other than connectivity), both in a tuple. Defaults to `Sabre`. routing_iterations (int, optional): Number of times to repeat the routing pipeline, to keep the best stochastic result. Defaults to 10. + optimize (bool, optional): whether to optimize the circuit and/or transpilation. Defaults to True. Returns: Result | list[Result]: :class:`Result` class (or list of :class:`Result` classes) containing the results of the @@ -96,6 +98,7 @@ def execute( placer=placer, router=router, routing_iterations=routing_iterations, + optimize=optimize, ) for circuit in tqdm(program, total=len(program)) ] diff --git a/src/qililab/platform/platform.py b/src/qililab/platform/platform.py index 9d7b5d0d4..92f513bd3 100644 --- a/src/qililab/platform/platform.py +++ b/src/qililab/platform/platform.py @@ -905,6 +905,7 @@ def execute( placer: Placer | type[Placer] | tuple[type[Placer], dict] | None = None, router: Router | type[Router] | tuple[type[Router], dict] | None = None, routing_iterations: int = 10, + optimize: bool = True, ) -> Result | QbloxResult: """Compiles and executes a circuit or a pulse schedule, using the platform instruments. @@ -924,6 +925,7 @@ def execute( router (Router | type[Router] | tuple[type[Router], dict], optional): `Router` instance, or subclass `type[Router]` to use, with optionally, its kwargs dict (other than connectivity), both in a tuple. Defaults to `Sabre`. routing_iterations (int, optional): Number of times to repeat the routing pipeline, to keep the best stochastic result. Defaults to 10. + optimize (bool, optional): whether to optimize the circuit and/or transpilation. Defaults to True. Returns: Result: Result obtained from the execution. This corresponds to a numpy array that depending on the @@ -936,7 +938,7 @@ def execute( """ # Compile pulse schedule programs, final_layout = self.compile( - program, num_avg, repetition_duration, num_bins, placer, router, routing_iterations + program, num_avg, repetition_duration, num_bins, placer, router, routing_iterations, optimize ) # Upload pulse schedule @@ -1032,6 +1034,7 @@ def compile( placer: Placer | type[Placer] | tuple[type[Placer], dict] | None = None, router: Router | type[Router] | tuple[type[Router], dict] | None = None, routing_iterations: int = 10, + optimize: bool = True, ) -> tuple[dict[str, list[QpySequence]], dict[str, int] | None]: """Compiles the circuit / pulse schedule into a set of assembly programs, to be uploaded into the awg buses. @@ -1050,6 +1053,7 @@ def compile( router (Router | type[Router] | tuple[type[Router], dict], optional): `Router` instance, or subclass `type[Router]` to use, with optionally, its kwargs dict (other than connectivity), both in a tuple. Defaults to `Sabre`. routing_iterations (int, optional): Number of times to repeat the routing pipeline, to keep the best stochastic result. Defaults to 10. + optimize (bool, optional): whether to optimize the circuit and/or transpilation. Defaults to True. Returns: tuple[dict, dict[str, int]]: Tuple containing the dictionary of compiled assembly programs (The key is the bus alias (``str``), and the value is the assembly compilation (``list``)) and the final layout of the qubits in the circuit {"qX":Y}. @@ -1065,7 +1069,7 @@ def compile( transpiler = CircuitTranspiler(digital_compilation_settings=self.digital_compilation_settings) transpiled_circuits, final_layouts = transpiler.transpile_circuits( - [program], placer, router, routing_iterations + [program], placer, router, routing_iterations, optimize ) pulse_schedule, final_layout = transpiled_circuits[0], final_layouts[0]