Skip to content

Commit

Permalink
Add missing bloq_counts and t_complexity for some basic gates.
Browse files Browse the repository at this point in the history
More basic gates.

More.
  • Loading branch information
fdmalone committed Sep 22, 2023
1 parent 9bb70e7 commit 6088bf3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
11 changes: 10 additions & 1 deletion qualtran/bloqs/basic_gates/cnot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@

import itertools
from functools import cached_property
from typing import Any, Dict, Tuple, TYPE_CHECKING
from typing import Any, Dict, Optional, Set, Tuple, TYPE_CHECKING

import numpy as np
import quimb.tensor as qtn
from attrs import frozen
from cirq_ft import TComplexity

from qualtran import Bloq, Signature, Soquet, SoquetT
from qualtran.bloqs.util_bloqs import ArbitraryClifford
from qualtran.drawing import Circle, ModPlus, WireSymbol
from qualtran.resource_counting import SympySymbolAllocator

if TYPE_CHECKING:
import cirq
Expand Down Expand Up @@ -97,3 +100,9 @@ def wire_symbol(self, soq: 'Soquet') -> 'WireSymbol':
elif soq.reg.name == 'target':
return ModPlus()
raise ValueError(f'Bad wire symbol soquet: {soq}')

def t_complexity(self):
return TComplexity(clifford=1)

def bloq_counts(self, ssa: Optional['SympySymbolAllocator'] = None) -> Set[Tuple[int, Bloq]]:
return {(1, ArbitraryClifford(n=1))}
11 changes: 10 additions & 1 deletion qualtran/bloqs/basic_gates/hadamard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
# limitations under the License.

from functools import cached_property
from typing import Dict, Tuple, TYPE_CHECKING
from typing import Dict, Optional, Set, Tuple, TYPE_CHECKING

import numpy as np
from attrs import frozen
from cirq_ft import TComplexity

from qualtran import Bloq, Signature, SoquetT
from qualtran.bloqs.util_bloqs import ArbitraryClifford
from qualtran.resource_counting import SympySymbolAllocator

if TYPE_CHECKING:
import cirq
Expand Down Expand Up @@ -74,3 +77,9 @@ def as_cirq_op(

(q,) = q
return cirq.H(q), {'q': np.array([q])}

def t_complexity(self):
return TComplexity(clifford=1)

def bloq_counts(self, ssa: Optional['SympySymbolAllocator'] = None) -> Set[Tuple[int, Bloq]]:
return {(1, ArbitraryClifford(n=1))}
5 changes: 5 additions & 0 deletions qualtran/bloqs/basic_gates/toffoli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
from typing import Dict, Optional, Set, Tuple, TYPE_CHECKING, Union

from attrs import frozen
from cirq_ft import TComplexity

from qualtran import Bloq, Register, Signature
from qualtran.bloqs.basic_gates import TGate
from qualtran.resource_counting import SympySymbolAllocator

if TYPE_CHECKING:
import cirq
Expand Down Expand Up @@ -66,3 +68,6 @@ def as_cirq_op(

(trg,) = target
return cirq.CCNOT(*ctrl[:, 0], trg), {'ctrl': ctrl, 'target': target}

def t_complexity(self):
return TComplexity(t=4)
11 changes: 10 additions & 1 deletion qualtran/bloqs/basic_gates/x_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
# limitations under the License.

from functools import cached_property
from typing import Dict, Tuple, TYPE_CHECKING, Union
from typing import Dict, Optional, Set, Tuple, TYPE_CHECKING, Union

import numpy as np
import quimb.tensor as qtn
from attrs import frozen
from cirq_ft import TComplexity

from qualtran import Bloq, Register, Side, Signature, SoquetT
from qualtran.bloqs.util_bloqs import ArbitraryClifford
from qualtran.resource_counting import SympySymbolAllocator

if TYPE_CHECKING:
import cirq
Expand Down Expand Up @@ -177,3 +180,9 @@ def as_cirq_op(

(q,) = q
return cirq.X(q), {'q': [q]}

def t_complexity(self):
return TComplexity(clifford=1)

def bloq_counts(self, ssa: Optional['SympySymbolAllocator'] = None) -> Set[Tuple[int, Bloq]]:
return {(1, ArbitraryClifford(n=1))}
11 changes: 10 additions & 1 deletion qualtran/bloqs/basic_gates/y_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
# limitations under the License.

from functools import cached_property
from typing import Dict, Tuple, TYPE_CHECKING
from typing import Dict, Optional, Set, Tuple, TYPE_CHECKING

import numpy as np
import quimb.tensor as qtn
from attrs import frozen
from cirq_ft import TComplexity

from qualtran import Bloq, Signature, SoquetT
from qualtran.bloqs.util_bloqs import ArbitraryClifford
from qualtran.resource_counting import SympySymbolAllocator

if TYPE_CHECKING:
import cirq
Expand Down Expand Up @@ -62,3 +65,9 @@ def as_cirq_op(

(q,) = q
return cirq.Y(q), {'q': [q]}

def t_complexity(self):
return TComplexity(clifford=1)

def bloq_counts(self, ssa: Optional['SympySymbolAllocator'] = None) -> Set[Tuple[int, Bloq]]:
return {(1, ArbitraryClifford(n=1))}

0 comments on commit 6088bf3

Please sign in to comment.