Skip to content

Instantly share code, notes, and snippets.

View SaraM92's full-sized avatar
🎯
Focusing

Sara Metwalli SaraM92

🎯
Focusing
View GitHub Profile
@SaraM92
SaraM92 / devices.py
Last active February 27, 2023 08:09
# set up device
rigetti = AwsDevice("arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-2")
# create a clean circuit with no result type attached.(This is because some result types are only supported when shots=0)
bell = Circuit().h(0).cnot(0, 1)
# add the Z \otimes Z expectation value
bell.expectation(Observable.Z() @ Observable.Z(), target=[0,1])
# run circuit
# print all (the usual suspects) available gates currently available within SDK
gate_set = [attr for attr in dir(Gate) if attr[0] in string.ascii_uppercase]
print('Gate set supported by SDK:\n', gate_set)
print('\n')
# the Rigetti device
device = AwsDevice('arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-2')
supported_gates = device.properties.action['braket.ir.jaqcd.program'].supportedOperations
# print the supported gate set
print('Gate set supported by the Rigetti device:\n', supported_gates)
#Import needed libraries
import pennylane as qml
from pennylane import numpy as np
dev = qml.device("default.qubit", wires=2, shots=100)
#Create circuit
@qml.qnode(dev)
def circuit():
qml.Hadamard(wires=0)
#Import needed libraries
import strangeworks
import strangeworks.cirq
import cirq
#Define needed qubits
q0 = cirq.NamedQubit('q0')
q1 = cirq.NamedQubit('q1')
#Create circuit
# general imports
import numpy as np
import matplotlib.pyplot as plt
# magic word for producing visualizations in notebook
%matplotlib inline
import string
import time
# AWS imports: Import Braket SDK modules
from braket.circuits import Circuit, Gate, Instruction, circuit, Observable
#Import needed libraries
from qiskit import QuantumRegister, ClassicalRegister
from qiskit import QuantumCircuit, execute
#Define the qubits and classical bit
q = QuantumRegister(2,'q')
c = ClassicalRegister(2,'c')
#Create a circuit
circuit = QuantumCircuit(q,c)
import csv
csv_mapping_list = []
with open("/path/to/data.csv") as my_data:
csv_reader = csv.reader(my_data, delimiter=",")
line_count = 0
for line in csv_reader:
if line_count == 0:
header = line
else:
row_dict = {key: value for key, value in zip(header, line)}
#Checking if a file exists in two ways
#1- Using the OS module
import os
exists = os.path.isfile('/path/to/file')
#2- Use the pathlib module for a better performance
from pathlib import Path
config = Path('/path/to/file')
if config.is_file():
pass
#Formatting strings with f string.
str_val = 'books'
num_val = 15
print(f'{num_val} {str_val}') # 15 books
print(f'{num_val % 2 = }') # 1
print(f'{str_val!r}') # books
#Dealing with floats
price_val = 5.18362
print(f'{price_val:.2f}') # 5.18
addresses = ["123 Elm Street", "531 Oak Street", "678 Maple Street"]
street = "Elm Street"
#The top 2 methods to check if street in any of the items in the addresses list
#1- Using the find method
for address in addresses:
if address.find(street) >= 0:
print(address)
#2- Using the "in" keyword