-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow quantum gates inside sympy expressions
- Loading branch information
Showing
11 changed files
with
156 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ | |
Qint16, | ||
Qlist, | ||
) | ||
from .boolquant import Q # noqa: F401 |
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,36 @@ | ||
from copy import deepcopy | ||
from sympy import Function | ||
from sympy.logic.boolalg import Boolean | ||
|
||
|
||
class QuantumBooleanGate(Function, Boolean): | ||
def build(name: str): | ||
return type(name, (QuantumBooleanGate,), { }) | ||
|
||
|
||
class Q: | ||
"""An identity wrapper for python""" | ||
|
||
def H(*args): | ||
return args | ||
|
||
def Z(*args): | ||
return args | ||
|
||
def Y(*args): | ||
return args | ||
|
||
def X(*args): | ||
return args | ||
|
||
def T(*args): | ||
return args | ||
|
||
def S(*args): | ||
return args | ||
|
||
def CX(*args): | ||
return args | ||
|
||
def MCX(*args): | ||
return args |
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,42 @@ | ||
# Copyright 2023 Davide Gessa | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
from parameterized import parameterized_class | ||
|
||
from qlasskit import QlassF, exceptions, qlassf | ||
|
||
from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, qiskit_measure_and_count | ||
|
||
|
||
class TestQlassfHybridQuantum(unittest.TestCase): | ||
def test_h(self): | ||
f = "def test(a: bool) -> bool:\n\treturn Q.H(a)" | ||
qf = qlassf(f, to_compile=COMPILATION_ENABLED, uncompute=False) | ||
count = qiskit_measure_and_count(qf.circuit().export(), 128) | ||
[self.assertEqual(x in count, True) for x in ["0", "1"]] | ||
|
||
def test_h_multi(self): | ||
f = "def test(a: Qint2) -> Qint2:\n\treturn Q.H(a)" | ||
qf = qlassf(f, to_compile=COMPILATION_ENABLED, uncompute=False) | ||
count = qiskit_measure_and_count(qf.circuit().export(), 128) | ||
[self.assertEqual(x in count, True) for x in ["00", "11", "01", "11"]] | ||
|
||
def test_bell(self): | ||
f = "def test(a: bool, b: bool) -> bool:\n\treturn Q.CX(Q.H(a), b)" | ||
qf = qlassf(f, to_compile=COMPILATION_ENABLED, uncompute=False) | ||
count = qiskit_measure_and_count(qf.circuit().export(), 1024) | ||
[self.assertEqual(x in count, True) for x in ["00", "11"]] | ||
self.assertEqual(len(count.keys()), 2) |