I am trying to run parallel code in python utilizing ipyparallel package.
import ipyparallel as ipp
# create client & view
rc = ipp.Client()
dv = rc[:]
v = rc.load_balanced_view()
def my(i):
import numpy as np
aa[:,:,i]=np.dot(uanom_L[:,:,i-I_a:i+I_a+1],lcoz_a)
bb[:,:,i]=np.dot(uanom_L[:,:,i-I_b:i+I_b+1],lcoz_b)
print(i)
return aa,bb
aaa=v.map(my,np.arange(I_a,c-I_a))
aaa.get()
Yet, I got the following error,
[3:apply]: No traceback available
[2:apply]: No traceback available
[1:apply]: No traceback available
[0:apply]: No traceback available
8773 more exceptions ...
Any ideas
Thanks
Related
The following code throws an error. Based on some issues that I read on qiskit github, it seems that it has something do with run configs vs. compile configs but I could not find any other info that will help me resolve this issue.
from qiskit import QuantumCircuit, IBMQ, execute
from qiskit import BasicAer as Aer
from qiskit.providers.aer import noise
ckt = QuantumCircuit(2, 2)
ckt.h(0)
ckt.cx(0, 1)
ckt.measure(0, 0)
ckt.measure(1, 1)
qsim = Aer.get_backend("qasm_simulator")
IBMQ.load_account()
provider = IBMQ.get_provider(hub="ibm-q")
qc = provider.get_backend("ibmqx2")
props = qc.properties()
coupling_map = qc.configuration().coupling_map
noise_model = noise.device.basic_device_noise_model(props)
job = execute(
ckt,
qsim,
noise_model=noise_model,
coupling_map=coupling_map,
basis_gates=noise_model.basis_gates
)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-2f987d65d1f7> in <module>
25 noise_model=noise_model,
26 coupling_map=coupling_map,
---> 27 basis_gates=noise_model.basis_gates
28 )
~/.venvs/qk/lib/python3.7/site-packages/qiskit/execute.py in execute(experiments, backend, basis_gates, coupling_map, backend_properties, initial_layout, seed_transpiler, optimization_level, pass_manager, qobj_id, qobj_header, shots, memory, max_credits, seed_simulator, default_qubit_los, default_meas_los, schedule_los, meas_level, meas_return, memory_slots, memory_slot_size, rep_time, parameter_binds, **run_config)
220
221 # executing the circuits on the backend and returning the job
--> 222 return backend.run(qobj, **run_config)
TypeError: run() got an unexpected keyword argument 'noise_model'
Env:
macOS 10.14.6
Python 3.7.3
qiskit 0.12.0
The error is coming up because you are using BasicAer to retrieve the simulator backend. I do not think this will work with the BasicAer provider. You should be using the Aer provider.
from qiskit import Aer
qsim = Aer.get_backend('qasm_simulator')
If you just change your import statement from
from qiskit import BasicAer as Aer
to
from qiskit import Aer
then your code should work
I am writing a simple program to check how multiprocessing works in Python 3. And I am testing with code that is similar to what is available in Python 3.6 documentation.
However when running the code I am facing an ImportError and not able to move forward.
I have also observed some confusing outputs.
When executing the code in PYthon IDE, it does not throw an error.
from multiprocessing import Process
However, if i execute it on Linux prompt, it throws an error.
My complete code is
from multiprocessing import Process
def worker():
print("working")
if __name__ == '__main__':
jobs = []
p = Process(target=worker)
jobs.append(p)
p.start()
print(jobs)
Traceback (most recent call last):
File "C:/Users/AASRITHA/PycharmProjects/untitled/multiprocessing.py", line 1, in <module>
from multiprocessing import Process
File "C:\Users\AASRITHA\PycharmProjects\untitled\multiprocessing.py", line 1, in <module>
from multiprocessing import Process
ImportError: cannot import name 'Process'
I'm trying to import statistics module in python. It's giving me an error message when i execute the program.
Here is my code:
from statistics import mean
import numpy as np
import matplotlib.pyplot as plt
xs = np.array([1,2,3,4,5,6,7,8])
ys = np.array([2,8,5,0,5,7,3,6])
def best_fit_line(xs ,ys):
m = ( ((mean(xs)* mean(ys))- mean(xs*ys)) /
(mean(xs)*mean(xs))-(mean(xs*xs)))
return m
m = best_fit_line(xs,ys)
The error message:
Traceback (most recent call last):
File "/home/kudzai/Documents/Machine Learning/LinearRegAlg.py", line 1, in <module>
from statistics import mean
ImportError: No module named statistics
The statistics module was added in Python 3.4. Perhaps you're using an older Python version.
If you can't upgrade for whatever reason, you can also just use numpy's mean function: np.mean(xs) etc. For numpy arrays, it's probably faster too.
I am trying to run following python code from c++(embedding python).
import sys
import os
import time
import win32com.client
from com.dtmilano.android.viewclient import ViewClient
import re
import pythoncom
import thread
os.popen('adb devices')
CANalyzer = None
measurement = None
def can_start(config_path):
global CANalyzer,measurement
CANalyzer = win32com.client.Dispatch('CANalyzer.Application')
CANalyzer.Visible = 1
measurement = CANalyzer.Measurement
CANalyzer.Open(config_path)
measurement.Start()
com_marshall_stream = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,CANalyzer)
return com_marshall_stream
When i try to call can_start function, i am getting python type error . Error traceback is mentioned below.
"type 'exceptions.TypeError'. an integer is required. traceback object at 0x039A198"
The function is executing if i directly ran it from the python and also it is executing in my pc, where the code was developed. But later when i transferred to another laptop, i am experiencing this problem.
I have two scripts sources.py and nest.py. They are something like this
sources.py
import numpy as np
from nest import *
def make_source():
#rest of the code
def detect():
Nest = nest()
Nest.fit()
if __name__=='main':
detect()
nest.py
import numpy as np
from sources import *
class nest(object):
def _init_(self):
self.source = make_source()
def fit(self):
#rest of the code
When I run the script like python sources.py It works fine.
But in the Ipython notebook environment if I do the following
In [1]: from sources import *
In [2]: detect()
I am getting the following error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-5-e9c378341590> in <module>()
----> detect()
C:\sources.pyc in detect()
--> 7 Nest = nest()
C:\nest.pyc in _init_()
--> 7 self.source = make_source()
NameError: global name 'make_source' is not defined
I am confused about why this is occurring. Can you give me an insight on how it is different in both cases and how to solve this ?
The thing is that there is a difference between
import something
and
from something import *
concerning namespaces.
If you have recursive imports its better to never do "from something import *" or "import something as someotherthing"
You get a full explanation here:
Circular (or cyclic) imports in Python