2 Copyright 2020 Peter Rakyta, Ph.D. 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 8 http://www.apache.org/licenses/LICENSE-2.0 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see http://www.gnu.org/licenses/. 25 """Tests for the inheritance structure of the CH gate in the Squander package""" 27 @pytest.mark.parametrize(
"gate_class", [
47 Test that gates properly inherits from the base Gate class. 50 from squander
import Gate
52 control_gates = [
"CH",
"CNOT",
"CRY",
"CZ",
"SYC"]
53 multi_qubit_gates = [
"CSWAP"]
55 module = importlib.import_module(
'squander')
56 gate_cls = getattr(module, gate_class)
58 assert issubclass(gate_cls, Gate)
61 if gate_class
in control_gates:
62 gate_ins = gate_cls(3, 0, 1)
63 elif gate_class
in multi_qubit_gates:
64 gate_ins = gate_cls(3,[0,1],[2])
66 gate_ins = gate_cls(3, 0)
68 assert isinstance(gate_ins, Gate)
70 @pytest.mark.parametrize(
"gate_class", [
90 Test that gate inherits methods from the base Gate class. 93 from squander
import Gate
95 control_gates = [
"CH",
"CNOT",
"CRY",
"CZ",
"SYC"]
96 multi_qubit_gates = [
"CSWAP"]
98 module = importlib.import_module(
'squander')
99 gate_cls = getattr(module, gate_class)
103 base_methods = [name
for name, obj
in inspect.getmembers(base_gate)
104 if (callable(obj)
and not name.startswith(
'_'))]
106 if gate_class
in control_gates:
107 gate_ins = gate_cls(3, 0, 1)
108 elif gate_class
in multi_qubit_gates:
109 gate_ins = gate_cls(3,[1,0],[2])
111 gate_ins = gate_cls(3, 0)
113 for method_name
in base_methods:
114 assert hasattr(gate_ins, method_name), f
"{gate_class} is missing method {method_name}" 117 assert gate_ins.get_Target_Qbit() == 0
118 if gate_class
in control_gates:
119 assert gate_ins.get_Control_Qbit() == 1
120 elif gate_class
in multi_qubit_gates:
121 assert gate_ins.get_Target_Qbits() == [0,1]
122 name = gate_ins.get_Name()
123 assert isinstance(name, str)
def test_gate_inheritance(self, gate_class)
def test_gate_methods(self, gate_class)
Base class for the representation of general gate operations.