Skip to content

Instantly share code, notes, and snippets.

@davidmerwin
Last active November 24, 2023 05:22
Show Gist options
  • Save davidmerwin/c835e409b05285be611817e0319f190b to your computer and use it in GitHub Desktop.
Save davidmerwin/c835e409b05285be611817e0319f190b to your computer and use it in GitHub Desktop.
This code sample defines a method called `_mixture_` in a class. The method returns a list of tuples, where each tuple contains the probability and unitary of a gate option. The probability is calculated as 1 divided by the number of gate options. The unitary of each gate option is obtained using the `cirq.unitary` function. The method then crea…

cirq_mixture

Preview:
# This code snippet defines a method named `_mixture_` in a class.
# The method returns a list of tuples, where each tuple contains the probability and unitary of a gate option.

def _mixture_(self):
    # Calculate the probability for each gate option
    probability = 1 / len(self.gate_options)
    
    # Get the unitary of each gate option using the cirq.unitary function
    unitaries = [cirq.unitary(g) for g in self.gate_options]
    
    # Create a list of tuples containing the probability and unitary for each gate option
    result = [(probability, u) for u in unitaries]
    
    # Return the list of tuples
    return result
Associated Context
Type Code Snippet ( .py )
Associated Tags cirq http://quantumai.google/cirq https://github.com/davidmerwin
Description 'No Description Provided'
Related Links http://quantumai.google/cirq
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=de384fa953
@davidmerwin
Copy link
Author

This code snippet defines a method named _mixture_ in a class.

The method returns a list of tuples, where each tuple contains the probability and unitary of a gate option.

def _mixture_(self):
    # Calculate the probability for each gate option
    probability = 1 / len(self.gate_options)
    
    # Get the unitary of each gate option using the cirq.unitary function
    unitaries = [cirq.unitary(g) for g in self.gate_options]
    
    # Create a list of tuples containing the probability and unitary for each gate option
    result = [(probability, u) for u in unitaries]
    
    # Return the list of tuples
    return result

Copy And SaveShareAsk Copilot

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

https://gist.github.com/davidmerwin/61818b9fd8f5217c2be0706be21cab59?permalink_comment_id=4771143#gistcomment-4771143

@davidmerwin
Copy link
Author

This code snippet defines a method named _mixture_ in a class.

The method returns a list of tuples, where each tuple contains the probability and unitary of a gate option.

def _mixture_(self):
    # Calculate the probability for each gate option
    probability = 1 / len(self.gate_options)
    
    # Get the unitary of each gate option using the cirq.unitary function
    unitaries = [cirq.unitary(g) for g in self.gate_options]
    
    # Create a list of tuples containing the probability and unitary for each gate option
    result = [(probability, u) for u in unitaries]
    
    # Return the list of tuples
    return result

https://gist.github.com/davidmerwin/61818b9fd8f5217c2be0706be21cab59?permalink_comment_id=4771143#gistcomment-4771143

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