I am working on a program for Qiskit, but I am getting a strange error (one that I have not gotten in the past) when I try to simulate a circuit. Here is a minimal example producing the error:
from qiskit.circuit import QuantumCircuit
from qiskit import Aer,transpile
c = QuantumCircuit(2)
simulator = Aer.get_backend('qasm_simulator')
c = transpile(c, simulator)
result = simulator.run(c).result()
plot_histogram(counts, title='Counts')
The error I get is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-89904ecd5f8e> in <module>()
5 simulator = Aer.get_backend('qasm_simulator')
6 c = transpile(c, simulator)
----> 7 result = simulator.run(c).result()
8 plot_histogram(counts, title='Counts')
/Users/d/anaconda3/envs/qiskit/lib/python3.7/site-packages/qiskit/providers/aer/backends/aerbackend.py in run(self, qobj, backend_options, validate, **run_options)
146 # Add backend options to the Job qobj
147 qobj = self._format_qobj(
--> 148 qobj, backend_options=backend_options, **run_options)
149
150 # Optional validation
/Users/d/anaconda3/envs/qiskit/lib/python3.7/site-packages/qiskit/providers/aer/backends/aerbackend.py in _format_qobj(self, qobj, backend_options, **run_options)
353 """Return execution sim config dict from backend options."""
354 # Add options to qobj config overriding any existing fields
--> 355 config = qobj.config
356
357 # Add options
AttributeError: 'QuantumCircuit' object has no attribute 'config'
Does anyone know what is causing this error?
Thank you!
I believe you need to assemble the transpiled circuit in a qobj before running it :
from qiskit.compiler import assemble
my_qobj = assemble(c)
result = simulator.run(my_qobj).result()
By the way, without any measure, the plot_histogram(result.get_counts()) will return an error as well.
There is also a special platform the Quantum Computing, https://quantumcomputing.stackexchange.com, feel free to post any other questions about QC&co there :)
Related
I have the following lines of code
from haystack.document_stores import InMemoryDocumentStore, SQLDocumentStore
from haystack.nodes import TextConverter, PDFToTextConverter,PreProcessor
from haystack.utils import clean_wiki_text, convert_files_to_docs, fetch_archive_from_http, print_answers
doc_dir = "C:\\Users\\abcd\\Downloads\\PDF Files\\"
docs = convert_files_to_docs(dir_path=doc_dir, clean_func=None, split_paragraphs=True
preprocessor = PreProcessor(
clean_empty_lines=True,
clean_whitespace=True,
clean_header_footer=True,
split_by="passage",
split_length=2)
doc = preprocessor.process(docs)
When i try to run it, i get the following error message
NotImplementedError Traceback (most recent call last)
c:\Users\abcd\Downloads\solr9.ipynb Cell 27 in <cell line: 23>()
16 print(type(docs))
17 preprocessor = PreProcessor(
18 clean_empty_lines=True,
19 clean_whitespace=True,
20 clean_header_footer=True,
21 split_by="passage",
22 split_length=2)
---> 23 doc = preprocessor.process(docs)
File ~\AppData\Roaming\Python\Python39\site-packages\haystack\nodes\preprocessor\preprocessor.py:167, in PreProcessor.process(self, documents, clean_whitespace, clean_header_footer, clean_empty_lines, remove_substrings, split_by, split_length, split_overlap, split_respect_sentence_boundary, id_hash_keys)
165 ret = self._process_single(document=documents, id_hash_keys=id_hash_keys, **kwargs) # type: ignore
166 elif isinstance(documents, list):
--> 167 ret = self._process_batch(documents=list(documents), id_hash_keys=id_hash_keys, **kwargs)
168 else:
169 raise Exception("documents provided to PreProcessor.prepreprocess() is not of type list nor Document")
File ~\AppData\Roaming\Python\Python39\site-packages\haystack\nodes\preprocessor\preprocessor.py:225, in PreProcessor._process_batch(self, documents, id_hash_keys, **kwargs)
222 def _process_batch(
223 self, documents: List[Union[dict, Document]], id_hash_keys: Optional[List[str]] = None, **kwargs
224 ) -> List[Document]:
--> 225 nested_docs = [
226 self._process_single(d, id_hash_keys=id_hash_keys, **kwargs)
...
--> 324 raise NotImplementedError("'split_respect_sentence_boundary=True' is only compatible with split_by='word'.")
326 if type(document.content) is not str:
327 logger.error("Document content is not of type str. Nothing to split.")
NotImplementedError: 'split_respect_sentence_boundary=True' is only compatible with split_by='word'.
I don't even have split_respect_sentence_boundary=True as my argument and also i don't have split_by='word' rather i have it set as split_by="passage".
This is the same error if i try changing it to split_by="sentence".
Do let me know if i am missing out anything here.
Tried using split_by="sentence" but getting same error.
As you can see in the PreProcessor API docs, the default value for split_respect_sentence_boundary is True.
In order to make your code work, you should specify split_respect_sentence_boundary=False:
preprocessor = PreProcessor(
clean_empty_lines=True,
clean_whitespace=True,
clean_header_footer=True,
split_by="passage",
split_length=2,
split_respect_sentence_boundary=False)
I agree that this behavior is not intuitive.
Currently, this node is undergoing a major refactoring.
I'm attempting to follow this tutorial and am getting the following error. I'm working in jupyter notebook with python 3. I am trying to build a recommendation engine using Azure tools and the Microsoft doc I attached.
TypeError: init() takes 2 positional arguments but 3 were given
I have attached an image of code from jupyter notebook to demonstrate proper formatting
I've tried solutions to roll back my Azure Python SDK using Pip. I run pip install --upgrade azureml-sdk and all looks good. Thanks very much for any and all help!
The code appears below:
print(workspace_name)
ws = Workspace.create(
name=workspace_name,
subscription_id=subscription_id,
resource_group=resource_group,
location=location,
exist_ok=True
)
The full error appears below:
'''
TypeError Traceback (most recent call last)
<ipython-input-11-25e04e55f419> in <module>
5 resource_group=resource_group,
6 location=location,
----> 7 exist_ok=True
8 )
~\.conda\envs\reco_pyspark\lib\site-packages\azureml\core\workspace.py in create(name, auth, subscription_id, resource_group, location, create_resource_group, sku, friendly_name, storage_account, key_vault, app_insights, container_registry, cmk_keyvault, resource_cmk_uri, hbi_workspace, default_cpu_compute_target, default_gpu_compute_target, private_endpoint_config, private_endpoint_auto_approval, exist_ok, show_output)
437
438 if location:
--> 439 available_locations = _available_workspace_locations(subscription_id, auth)
440 available_locations = [x.lower().replace(' ', '') for x in available_locations]
441 location = location.lower().replace(' ', '')
~\.conda\envs\reco_pyspark\lib\site-packages\azureml\core\workspace.py in _available_workspace_locations(subscription_id, auth)
1556 if not auth:
1557 auth = InteractiveLoginAuthentication()
-> 1558 return _commands.available_workspace_locations(auth, subscription_id)
~\.conda\envs\reco_pyspark\lib\site-packages\azureml\_project\_commands.py in available_workspace_locations(auth, subscription_id)
334 :rtype: list[str]
335 """
--> 336 response = auth._get_service_client(ResourceManagementClient, subscription_id).providers.get(
337 "Microsoft.MachineLearningServices")
338 for resource_type in response.resource_types:
~\.conda\envs\reco_pyspark\lib\site-packages\azureml\core\authentication.py in _get_service_client(self, client_class, subscription_id, subscription_bound, base_url)
150 return _get_service_client_using_arm_token(self, client_class, subscription_id,
151 subscription_bound=subscription_bound,
--> 152 base_url=base_url)
153
154 def signed_session(self, session=None):
~\.conda\envs\reco_pyspark\lib\site-packages\azureml\core\authentication.py in _get_service_client_using_arm_token(auth, client_class, subscription_id, subscription_bound, base_url)
1620 else:
1621 # converting subscription_id, which is string, to string because of weird python 2.7 errors.
-> 1622 client = client_class(adal_auth_object, str(subscription_id), base_url=base_url)
1623 return client
1624
TypeError: __init__() takes 2 positional arguments but 3 were given
'''
Have you tried using the Workspace.from_config() and the config.json method? Check out this doc page on how the set up your environment.
After creating ALS model object,using pyspark.
Sample code example:
from pyspark.ml.evaluation import RegressionEvaluator
from pyspark.ml.recommendation import ALS
from pyspark.sql import Row
lines = spark.read.text("data/mllib/als/sample_movielens_ratings.txt").rdd
parts = lines.map(lambda row: row.value.split("::"))
ratingsRDD = parts.map(lambda p: Row(userId=int(p[0]), movieId=int(p[1]),
rating=float(p[2]), timestamp=long(p[3])))
ratings = spark.createDataFrame(ratingsRDD)
(rating_data, test) = ratings.randomSplit([0.8, 0.2])
# Build the recommendation model using ALS on the training data
# Note we set cold start strategy to 'drop' to ensure we don't get NaN evaluation metrics
als = ALS(maxIter=5, regParam=0.01, userCol="userId", itemCol="movieId", ratingCol="rating",
coldStartStrategy="drop")
als_model = als_spec.fit(rating_data)
here i am just creating ALS model and making cloudepickel.
if we are using fit then also need to do transform?
I am trying pickel the my als_model object using the below code :
with open(os.path.join(model_path, 'als-als-model.pkl'), 'w') as out:
cloudpickle.dump(als_model, out)
I am getting error like below:
File "/usr/local/spark/python/lib/py4j-0.10.6-src.zip/py4j/protocol.py", line 324, in get_return_value
format(target_id, ".", name, value))
Py4JError: An error occurred while calling o224.__getnewargs__. Trace:
py4j.Py4JException: Method __getnewargs__([]) does not exist
#011at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
#011at
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-124-8c94f4ee0de9> in <module>()
1
----> 2 tree.fit(data_location)
~/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py in fit(self, inputs, wait, logs, job_name)
152 self.latest_training_job = _TrainingJob.start_new(self, inputs)
153 if wait:
--> 154 self.latest_training_job.wait(logs=logs)
155 else:
156 raise NotImplemented('Asynchronous fit not available')
I know there are so man questions asking of "AttributeError"
But i couldn't solve my problem.
It seems to be a problem with os, because it works well on my friend's computer that uses mac, which causes problems on my computer using windows.
import pandas as pd
import numpy as np
import konlpy
from konlpy.tag import Twitter
import nltk
from gensim import models
import re
import requests
import pickle
with open('labeled_data.pkl', 'rb') as data:
data_refd = pickle.load(data)
data_refd.shape
So far this is my code, and of course 'labeled_data.pkl' is in my home directory.
And I got the following error.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-df61982f39de> in <module>()
1 with open('labeled_data.pkl', 'rb') as data:
----> 2 data_refd = pickle.load(data)
3 data_refd.shape()
C:\Users\ji\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in <module>()
104
105
--> 106 class Index(IndexOpsMixin, PandasObject):
107 """
108 Immutable ndarray implementing an ordered, sliceable set. The basic object
C:\Users\ji\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in Index()
177
178 # String Methods
--> 179 str = accessor.AccessorProperty(strings.StringMethods)
180
181 def __new__(cls, data=None, dtype=None, copy=False, name=None,
C:\Users\ji\Anaconda3\lib\site-packages\pandas\core\accessor.py in __init__(self, accessor_cls, construct_accessor)
45 self.accessor_cls = accessor_cls
46 self.construct_accessor = (construct_accessor or
---> 47 accessor_cls._make_accessor)
48 self.__doc__ = accessor_cls.__doc__
49
AttributeError: type object 'StringMethods' has no attribute '_make_accessor'
I do not know what the problem is. I would appreciate your help.
I'm trying to reproduce the result of the example file provided by Prof. Zhao using Enthought Canopy:
http://www.shengdongzhao.com/shen_blog/how-to-automatically-create-powerpoint-slides-using-python/
I seem to be having the same problem that others are having (and seem to still be having) which you can see in the comments below the linked blog post. I realize prof. Zhao mentions that the error could be due to the environment not being set correctly. I thought it might have something to do with environment variables not being pointed to correctly. I tried the the first answer at the following but it seems like it prevents canopy from even opening (doing something wrong I am)
How to add to the pythonpath in windows 7?
So what I'm left doing is: I open his scripts in Canopy and then I run MSO.py and then MSPPT.py and then MSPPTUtil.py. Then, when I run CreateSlideExamples.py (with photo.JPG's directory updated) I only get a single power-point slide with the table
The console is littered with the following list of errors:
%run C:/Users/dirkh_000/AppData/Local/Temp/Temp1_MSPPT.zip/MSO.py
%run "C:/Users/dirkh_000/Documents/Python scripts/Auto pp example/MSPPT.py"
%run "C:/Users/dirkh_000/Documents/Python scripts/Auto pp example/MSPPTUtil.py"
%run "C:/Users/dirkh_000/Documents/Python scripts/Auto pp example/CreateSlideExamples.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\Users\dirkh_000\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.1.1975.win-x86_64\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
195 else:
196 filename = fname
--> 197 exec compile(scripttext, filename, 'exec') in glob, loc
198 else:
199 def execfile(fname, *where):
C:\Users\dirkh_000\Documents\Python scripts\Auto pp example\CreateSlideExamples.py in <module>()
40
41 # step 3: show the slide
---> 42 presentation.create_show()
43
44 # Now you can save the slide somewhere
C:\Users\dirkh_000\Documents\Python scripts\Auto pp example\MSPPTUtil.pyc in create_show(self, visible)
45 if visible:
46 slide.select() #bring slide to front
---> 47 slide.format_slide()
48 def save_as(self, file_name):
49 self.presentation.SaveAs(file_name)
C:\Users\dirkh_000\Documents\Python scripts\Auto pp example\MSPPTUtil.pyc in format_slide(self)
64 self.slide.Select()
65 def format_slide(self):
---> 66 self.format_content()
67 self.format_title()
68 def format_title(self):
C:\Users\dirkh_000\Documents\Python scripts\Auto pp example\MSPPTUtil.pyc in format_content(self)
252 if self.title:
253 #add title
--> 254 title_range = slide.Shapes[0].TextFrame.TextRange
255 title_range.Text = self.title
256 title_range.Font.Bold = True
C:\Users\dirkh_000\AppData\Local\Enthought\Canopy\User\lib\site-packages\win32com\client\__init__.pyc in __getattr__(self, attr)
463 args=self._prop_map_get_.get(attr)
464 if args is None:
--> 465 raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
466 return self._ApplyTypes_(*args)
467
AttributeError: '<win32com.gen_py.Microsoft PowerPoint 15.0 Object Library.Shapes instance at 0x164276808>' object has no attribute '__getitem__'
Any help is appreciated. I'm running windows 8.1, powerpoint 2013.