-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: rturrado <[email protected]> Co-authored-by: Juan Boschero <[email protected]> Co-authored-by: Guy Puts <[email protected]> Co-authored-by: Guy Puts <[email protected]> Co-authored-by: Juan Carlos Boschero <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: rares1609 <[email protected]> Co-authored-by: Oancea <[email protected]>
- Loading branch information
1 parent
0d321ff
commit 0e311ee
Showing
24 changed files
with
711 additions
and
566 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Init file for the validator passes.""" | ||
|
||
from opensquirrel.passes.validator.general_validator import Validator | ||
from opensquirrel.passes.validator.native_gate_validator import NativeGateValidator | ||
|
||
__all__ = ["NativeGateValidator", "Validator"] |
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,10 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from opensquirrel.ir import IR | ||
|
||
|
||
class Validator(ABC): | ||
@abstractmethod | ||
def validate(self, ir: IR) -> None: | ||
"""Base validate method to be implemented by inheriting validator classes.""" | ||
raise NotImplementedError |
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,26 @@ | ||
from opensquirrel.ir import IR, Unitary | ||
from opensquirrel.passes.validator import Validator | ||
|
||
|
||
class NativeGateValidator(Validator): | ||
def __init__(self, native_gate_set: list[str]) -> None: | ||
self.native_gate_set = native_gate_set | ||
|
||
def validate(self, ir: IR) -> None: | ||
""" | ||
Check if all unitary gates in the circuit are part of the native gate set. | ||
Args: | ||
ir (IR): The intermediate representation of the circuit to be checked. | ||
Raises: | ||
ValueError: If any unitary gate in the circuit is not part of the native gate set. | ||
""" | ||
gates_not_in_native_gate_set = [ | ||
statement.name | ||
for statement in ir.statements | ||
if isinstance(statement, Unitary) and statement.name not in self.native_gate_set | ||
] | ||
if gates_not_in_native_gate_set: | ||
error_message = f"the following gates are not in the native gate set: {set(gates_not_in_native_gate_set)}" | ||
raise ValueError(error_message) |
Oops, something went wrong.