-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from GenericP3rson/functional_reformatting
Reformatting Functionals
- Loading branch information
Showing
60 changed files
with
5,250 additions
and
4,715 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import functools | ||
import torch | ||
import numpy as np | ||
|
||
from typing import Callable, Union, Optional, List, Dict, TYPE_CHECKING | ||
from ..macro import C_DTYPE, F_DTYPE, ABC, ABC_ARRAY, INV_SQRT2 | ||
from ..util.utils import pauli_eigs, diag | ||
from torchpack.utils.logging import logger | ||
from torchquantum.util import normalize_statevector | ||
|
||
from .gate_wrapper import gate_wrapper, apply_unitary_einsum, apply_unitary_bmm | ||
|
||
if TYPE_CHECKING: | ||
from torchquantum.device import QuantumDevice | ||
else: | ||
QuantumDevice = None | ||
|
||
_ecr_mat_dict = { | ||
"ecr": INV_SQRT2 | ||
* torch.tensor( | ||
[[0, 0, 1, 1j], [0, 0, 1j, 1], [1, -1j, 0, 0], [-1j, 1, 0, 0]], dtype=C_DTYPE | ||
), | ||
} | ||
|
||
|
||
def ecr( | ||
q_device, | ||
wires, | ||
params=None, | ||
n_wires=None, | ||
static=False, | ||
parent_graph=None, | ||
inverse=False, | ||
comp_method="bmm", | ||
): | ||
"""Perform the echoed cross-resonance gate. | ||
https://qiskit.org/documentation/stubs/qiskit.circuit.library.ECRGate.html | ||
Args: | ||
q_device (tq.QuantumDevice): The QuantumDevice. | ||
wires (Union[List[int], int]): Which qubit(s) to apply the gate. | ||
params (torch.Tensor, optional): Parameters (if any) of the gate. | ||
Default to None. | ||
n_wires (int, optional): Number of qubits the gate is applied to. | ||
Default to None. | ||
static (bool, optional): Whether use static mode computation. | ||
Default to False. | ||
parent_graph (tq.QuantumGraph, optional): Parent QuantumGraph of | ||
current operation. Default to None. | ||
inverse (bool, optional): Whether inverse the gate. Default to False. | ||
comp_method (bool, optional): Use 'bmm' or 'einsum' method to perform | ||
matrix vector multiplication. Default to 'bmm'. | ||
Returns: | ||
None. | ||
""" | ||
name = "ecr" | ||
mat = _ecr_mat_dict[name] | ||
gate_wrapper( | ||
name=name, | ||
mat=mat, | ||
method=comp_method, | ||
q_device=q_device, | ||
wires=wires, | ||
params=params, | ||
n_wires=n_wires, | ||
static=static, | ||
parent_graph=parent_graph, | ||
inverse=inverse, | ||
) | ||
|
||
|
||
echoedcrossresonance = ecr |
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
Oops, something went wrong.