Skip to content

Instantly share code, notes, and snippets.

@davidmerwin
Last active November 24, 2023 07:30
Show Gist options
  • Save davidmerwin/2c15fdb780580fc0d7d322703dea2b40 to your computer and use it in GitHub Desktop.
Save davidmerwin/2c15fdb780580fc0d7d322703dea2b40 to your computer and use it in GitHub Desktop.

Python Snippet

Preview:
# Import necessary libraries
from typing import List, Tuple
import numpy as np

class XPowGate:
    # Initialize class attribute
    _eigencomponents = {}

    def _eigen_components(self) -> List[Tuple[float, np.ndarray]]:
        # Check if eigen components for the given dimension exists
        if self._dimension not in XPowGate._eigencomponents:
            components = []
            root = 1j ** (4 / self._dimension)

            # Loop through each dimension
            for i in range(self._dimension):
                half_turns = i * 2 / self._dimension
                v = np.array([root ** (i * j) / self._dimension for j in range(self._dimension)])
                m = np.array([np.roll(v, j) for j in range(self._dimension)])

                # Append the tuple of half_turns and matrix to the list of components
                components.append((half_turns, m))
            
            # Save the components for the given dimension
            XPowGate._eigencomponents[self._dimension] = components
        
        # Return the eigen components for the given dimension
        return XPowGate._eigencomponents[self._dimension]
Associated Context
Type Code Snippet ( .py )
Associated Tags cirq https://github.com/davidmerwin
Description 'No Description Provided'
Related Links https://github.com/davidmerwin
Related People David Merwin, CIRQ, David Jeffrey Merwin
Sensitive Information No Sensitive Information Detected
Shareable Link https://davidmerwin.pieces.cloud/?p=c39d4d9f48
@davidmerwin
Copy link
Author


# Import necessary libraries
from typing import List, Tuple
import numpy as np

class XPowGate:
    # Initialize class attribute
    _eigencomponents = {}

    def _eigen_components(self) -> List[Tuple[float, np.ndarray]]:
        # Check if eigen components for the given dimension exists
        if self._dimension not in XPowGate._eigencomponents:
            components = []
            root = 1j ** (4 / self._dimension)

            # Loop through each dimension
            for i in range(self._dimension):
                half_turns = i * 2 / self._dimension
                v = np.array([root ** (i * j) / self._dimension for j in range(self._dimension)])
                m = np.array([np.roll(v, j) for j in range(self._dimension)])

                # Append the tuple of half_turns and matrix to the list of components
                components.append((half_turns, m))

            # Save the components for the given dimension
            XPowGate._eigencomponents[self._dimension] = components

        # Return the eigen components for the given dimension
        return XPowGate._eigencomponents[self._dimension]
    
    

https://gist.github.com/2c15fdb780580fc0d7d322703dea2b40

https://cdn.mathpix.com/snip/images/9aBALUhM0a49py-QpXpunvXJjbFlAC-w-IB6CaRsEiI.original.fullsize.png

https://davidmerwin.pieces.cloud/?p=c39d4d9f48

https://cdn.mathpix.com/snip/images/9aBALUhM0a49py-QpXpunvXJjbFlAC-w-IB6CaRsEiI.original.fullsize.png

@davidmerwin1992 @davidmerwin1992 @CirqBot

@davidmerwin
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment