Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory = True argument in function execute is not working. #59

Closed
deveshq opened this issue Aug 23, 2022 · 2 comments · Fixed by #68
Closed

memory = True argument in function execute is not working. #59

deveshq opened this issue Aug 23, 2022 · 2 comments · Fixed by #68
Labels
bug Something isn't working enhancement New feature or request on hold On hold for some reason

Comments

@deveshq
Copy link

deveshq commented Aug 23, 2022

The problem

The argument memory = True in the execute function is not working, hence per-shot measurement result is not accessible.

Steps to reproduce the problem

  1. Create a circuit in qiskit and define a backend fromaws_braket_provider.
  2. Run the job using execute function with memory = True.
  3. Extract the memory using result.get_memory() method.

Example:

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
qc.measure_all()

ionq = aws_provider.get_backend('IonQ Device')
tqc = transpile(qc, backend = ionq)

job = execute(tqc, backend = ionq, shots = 1024, memory = True)
result = job.result()
counts = result.get_counts()
memory = result.get_memory()

What is the current behavior?

Try to extract memory gives the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [19], in <cell line: 3>()
      1 result = job.result()
      2 counts = result.get_counts()
----> 3 memory = result.get_memory()

File ~/anaconda3/envs/qlab/lib/python3.10/site-packages/qiskit/result/result.py:229, in Result.get_memory(self, experiment)
    226 memory = self.data(experiment)["memory"]
    228 if meas_level == MeasLevel.CLASSIFIED:
--> 229     return postprocess.format_level_2_memory(memory, header)
    230 elif meas_level == MeasLevel.KERNELED:
    231     return postprocess.format_level_1_memory(memory)

File ~/anaconda3/envs/qlab/lib/python3.10/site-packages/qiskit/result/postprocess.py:151, in format_level_2_memory(memory, header)
    149 memory_list = []
    150 for shot_memory in memory:
--> 151     memory_list.append(format_counts_memory(shot_memory, header))
    152 return memory_list

File ~/anaconda3/envs/qlab/lib/python3.10/site-packages/qiskit/result/postprocess.py:65, in format_counts_memory(shot_memory, header)
     46 def format_counts_memory(shot_memory, header=None):
     47     """
     48     Format a single bitstring (memory) from a single shot experiment.
     49 
   (...)
     63         dict: a formatted memory
     64     """
---> 65     if shot_memory.startswith("0x"):
     66         shot_memory = _hex_to_bin(shot_memory)
     67     if header:

AttributeError: 'numpy.ndarray' object has no attribute 'startswith'

What is the expected behavior?

The result.get_memory() should return a list of measurement result of each shot.

A work around

This answer on stackexchange suggest a way around which works well for simulators from AWSBraketProvider, but for IonQ Device it is not useful.

@IceKhan13
Copy link
Member

Hi @deveshq!

I saw slack discussion in partners-ionq, so citing here Coleman Collins response:

I can confirm that IonQ does not expose this to Braket
or via our direct API/direct qiskit integration, actually — it's on the roadmap but is one of those "surprisingly hard due to some very early days assumptions on our part" type features, so no exact date;  known to be high-priority for certain types of experiments (ed

Let's keep this issue open. Once IonQ will support memory, we will get back to it.

Let us know if we can help somehow

@IceKhan13 IceKhan13 added on hold On hold for some reason bug Something isn't working enhancement New feature or request labels Aug 26, 2022
@Morcu
Copy link
Collaborator

Morcu commented Aug 30, 2022

Related with #53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request on hold On hold for some reason
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants