Skip to content

Instantly share code, notes, and snippets.

View SaraM92's full-sized avatar
🎯
Focusing

Sara Metwalli SaraM92

🎯
Focusing
View GitHub Profile
from collections import defaultdict
#merge two or more dicts using the collections module
def merge_dicts(*dicts):
mdict = defaultdict(list)
for d in dicts:
for key in d:
mdict[key].append(d[key])
return dict(mdict)
#Import needed libraries
from bs4 import BeautifulSoup as bs
import requests as rq
import pygal
from IPython.display import display, HTML
#Fetch HTML
url = 'https://en.wikipedia.org/wiki/List_of_countries_by_coffee_production'
#Extract HTMl tree
page = rq.get(url).text
soup = bs(page)
@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)
# 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
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
#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