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 Option #326

Open
ahmadrv opened this issue Dec 9, 2023 · 7 comments
Open

✨ Memory Option #326

ahmadrv opened this issue Dec 9, 2023 · 7 comments
Labels
feature New feature or request good first issue Good for newcomers python Pull requests that update Python code
Milestone

Comments

@ahmadrv
Copy link

ahmadrv commented Dec 9, 2023

What's the problem this feature will solve?

To whom it may concern,
First of all, I apologize if there are some misleading with the way I present the problem.

I was tying to simulate Simon's algorithm with the ddsim backend when I ran into a problem. I didn't know if it was a problem with the missing feature or the implementation I did.
This part is about calling the backend and getting the results:

backend = ddsim.DDSIMProvider().get_backend("qasm_simulator")
result = backend.run(transpiled_circuit, shots=num_shots, memory=True).result()

And here are the warning and error shown:

UserWarning: Option memory is not used by this backend
  result = backend.run(transpiled_circuit, shots=num_shots, memory=True).result()
Traceback (most recent call last):
  File "path/to/lib/python3.10/site-packages/qiskit/result/result.py", line 226, in get_memory
    memory = self.data(experiment)["memory"]
KeyError: 'memory'

Should the mentioned feature be implemented in the backend or am I doing something wrong?
Thanks in advance for your tips.

Describe the solution you'd like

If I understand correctly and the mentioned feature is added, the implementation of Simon's algorithm will be as easy as other Qiskit backends.

@burgholzer
Copy link
Member

Hey 👋🏻
Thanks for opening this issue!

Could you maybe elaborate a little more what kind of problem you are experiencing?
Maybe in addition: what do you expect the memory option to do?

I am fairly sure that our backends support that feature if I have the right thing in mind. We just might not be exposing it to the Qiskit backends. That would be an easy fix (that shouldn't change any behavior though).

@ahmadrv
Copy link
Author

ahmadrv commented Dec 10, 2023

Hey,
As I mentioned I was trying to simulate Simon's algorithm with various backends. In the implementation of the algorithm based on IBM Quantum Learning, we should collect the results to prepare the appropriate information for finding the secret string $s$. As we pass True for the memory flag in:

from qiskit_aer import AerSimulator

def simon_measurements(problem: QuantumCircuit, k: int):
    """
    Quantum part of Simon's algorithm. Given a `QuantumCircuit` that
    implements f, get `k` measurements to be post-processed later.
    """
    n = problem.num_qubits // 2

    qc = QuantumCircuit(2 * n, n)
    qc.h(range(n))
    qc.compose(problem, inplace=True)
    qc.h(range(n))
    qc.measure(range(n), range(n))

    result = AerSimulator().run(qc, shots=k, memory=True).result()
    return result.get_memory()

the results of the circuit will be collected. In my experience with ddsim.DDSIMProvider() with this implementation:

from mqt import ddsim

def simon_measurements(problem: QuantumCircuit, k: int):
    """
    Quantum part of Simon's algorithm. Given a `QuantumCircuit` that
    implements f, get `k` measurements to be post-processed later.
    """
    n = problem.num_qubits // 2

    qc = QuantumCircuit(2 * n, n)
    qc.h(range(n))
    qc.compose(problem, inplace=True)
    qc.h(range(n))
    qc.measure(range(n), range(n))

    result = ddsim.DDSIMProvider().get_backend("qasm_simulator").run(qc, shots=k, memory=True).result()
    return result.get_memory()

I couldn't collect the results in the same way and the mentioned error was raised.

@burgholzer
Copy link
Member

Thanks for the explanation!
In fact, we do not currently implement the feature that you can get the sequence of measurement results.
If I am not mistaken, that shouldn't be too hard to realize. I might find some time next week to add that feature!

If you are only interested in the measurement results and not their particular sequence, you can just use the result.get_counts() method (without the memory flag being set to avoid the warning).
That gives you a dictionary of measurement results and corresponding counts.
Maybe a suitable workaround for now.

@ahmadrv
Copy link
Author

ahmadrv commented Dec 10, 2023

It would be nice if the feature is added.
Thanks for the mentioned workaround and your time. 🙏🏻

@ahmadrv ahmadrv closed this as completed Dec 10, 2023
@burgholzer
Copy link
Member

You are welcome.

I'll keep this issue open for now to track the feature request. I'll close once the PR implementing the feature is merged.

@burgholzer burgholzer reopened this Dec 11, 2023
@ahmadrv
Copy link
Author

ahmadrv commented Jan 19, 2024

Hi @burgholzer ,

I wanted to ask if there was any news about adding the feature?

@burgholzer
Copy link
Member

Hi @burgholzer ,

I wanted to ask if there was any news about adding the feature?

Hey 👋🏼

This is definitely still on our radar. At the moment, there are just a couple more urgent things that need to be dealt with.

@burgholzer burgholzer added this to the DDSIM 2.0 milestone Feb 23, 2024
@burgholzer burgholzer added good first issue Good for newcomers python Pull requests that update Python code feature New feature or request labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request good first issue Good for newcomers python Pull requests that update Python code
Projects
Status: Todo
Status: Todo
Development

No branches or pull requests

2 participants