Skip to content

Commit

Permalink
add OracleGate class and its metaclass
Browse files Browse the repository at this point in the history
Provide customize_gate as user-function to customize QuantumGate and integrate into QuantumCircuit
  • Loading branch information
chensgit169 committed Aug 17, 2023
1 parent 7442786 commit ed59462
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/quafu/circuits/quantum_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def parameterized_gates(self):

@property
def num(self):
return np.sum([len(qreg) for qreg in self.qregs])
return sum([len(qreg) for qreg in self.qregs])

@property
def used_qubits(self) -> List:
Expand Down Expand Up @@ -428,10 +428,9 @@ def wrap_to_gate(self, name: str):
Wrap the circuit to a subclass of QuantumGate, create by metaclass.
"""
# TODO: error check
from instruction.qu_gate.quantum_gate import customize_gate
customized = customize_gate(cls_name=name.capitalize(),
sd_name=name,
qubit_num=self.qbit_num,
from quafu.elements.quantum_element.quantum_gate import customize_gate
customized = customize_gate(cls_name=name.lower(),
qubit_num=self.num,
gate_structure=self.gates)
return customized

Expand Down
14 changes: 14 additions & 0 deletions src/quafu/elements/quantum_element/quantum_gate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# (C) Copyright 2023 Beijing Academy of Quantum Information Sciences
#
# 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.

from abc import ABC, abstractmethod, ABCMeta
from typing import List, Union, Iterable

Expand Down

0 comments on commit ed59462

Please sign in to comment.