Skip to content

Instantly share code, notes, and snippets.

View davidmerwin's full-sized avatar
🏠
Working from home

David Jeffrey Merwin davidmerwin

🏠
Working from home
View GitHub Profile

TypeScript Snippet

Preview:
// Calculating the step size for each iteration
const stepSize = topmostChordPos / circlesPerHalf;

// Loop from topmostChordPos down to 0
for (let i = topmostChordPos; i > 0; i -= stepSize) {
  // Adding current position (positive and negative) to the chordYPositions array
 chordYPositions.push(i);

TypeScript Snippet

Preview:
constructor(
    initial_num_moments: number,
    symbols: SymbolInformation[],
    padding_factor = 1
  ) {
    super();
 this.padding_factor = padding_factor;

TypeScript Snippet

Preview:
it('adds the correct number of GridQubit objects with overlapping rows', () => {
  // Create a new instance of GridCircuit with 'moments' and an array of symbols.
  const circuit = new GridCircuit(moments, [
    symbols[0],
    symbols[1],
    symbols[5],
 ]);

Python Snippet

Preview:
# Revised code snippet: Calculate PauliString expectation value from state vector

```python
def expectation_from_state_vector(self, state_vector: np.ndarray, qubit_map: Mapping[TKey, int]) -> float:
    """
    Evaluate the expectation value of this PauliString given a state vector.

TypeScript Snippet

Preview:
// Notes:
// 1. The code snippet appears to be a constructor for a class that sets up a BlochSphereScene.
// 2. The constructor has default values for the fov, aspect, near, and far parameters.
// 3. The constructor initializes and sets up the camera, renderer, and controls for the scene.

public constructor() {
  const fov = 75; // Field of view
@davidmerwin
davidmerwin / cirq_mixture.md
Last active November 24, 2023 05:22
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)
 

Python Snippet

Preview:
# Function to multiply two pauli-string-likes together
def multiply_pauli_strings(self, other: 'cirq.PAULI_STRING_LIKE') -> 'cirq.PauliString':
    """
    Multiplies two pauli-string-likes together.
    
    The result is not mutable.
 """
@davidmerwin
davidmerwin / TypeScript Snippet.md
Last active November 24, 2023 03:50
cirq It is importing two items, Symbol3D and SymbolInformation, from a module named types which is located in the same directory as the current file. Here's a brief explanation of these elements: 1. import: This keyword is used to import functions, objects or values from other files or modules into the current file. 2. { Symbol3D, SymbolInformat…

TypeScript Snippet

Preview:
// Importing Symbol3D and SymbolInformation from the './types' module

import { Symbol3D, SymbolInformation } from './types';
Associated Context
Type Code Snippet ( .ts )

Python Snippet

Preview:
import pytest
import cirq


def test_constructor_flexibility():
    # Create two LineQubits
    a, b = cirq.LineQubit.range(2)

TypeScript Snippet

Preview:
// Set up controls for the app
private setUpControls() {
  // Enable damping for smoother camera movement
  this.controls.enableDamping = true;

  // Set the damping factor for the controls
 this.controls.dampingFactor = 0.05;