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

Cannot convert Results from QLM emulator to Pulser Samples #1

Open
HaroldErbin opened this issue Nov 18, 2024 · 4 comments
Open

Cannot convert Results from QLM emulator to Pulser Samples #1

HaroldErbin opened this issue Nov 18, 2024 · 4 comments

Comments

@HaroldErbin
Copy link

The interface seems to be inconsistent between the qutip and QLM emulators. I am running some code on the QLM40 machine at TGCC, and also locally with qutip, but I get an error when trying to convert myqlm results to pulser samples.

Here is the overall job submission:

from pulser_myqlm.ising_aqpu import IsingAQPU
from qlmaas import qpus

sequence = ...

nbshots = 0
qpu = qpus.AnalogQPU()
job = IsingAQPU.convert_sequence_to_job(sequence, nbshots=nbshots)
aqpu = IsingAQPU.from_sequence(sequence, qpu=qpu)
results = aqpu.submit(job)
samples = IsingAQPU.convert_result_to_samples(results)

The last line returns an error:

Meta data must be a dictionary with n_samples and n_qubits defined.

because results.meta_data is

{'final_norm': '0.999835', 'simulation_time': '0.854693', 'single_job': 'True'}

The results have lost tracks of the number of qubits.

On the other hand, setting

nbshots = 2000
qpu = None

yields results with results.meta_data such that

{'n_samples': '2000', 'n_qubits': '3'}

I am not sure why n_qubits is not stored in meta_data since it's clearly available in the sequence. On the other hand, I understand that having nbshots = 0 (as required when running on the QLM40) is problematic.

I think that it would have been nice if IsingAQPU.convert_result_to_samples was made to work also for QLM emulation.

@a-corni
Copy link
Collaborator

a-corni commented Nov 22, 2024

Hi Harold,

Thanks for your detailed issue. We purposely chose not to modify the meta_data of myQLM Results obtained using a MyQLM Emulator for it to contain the minimal information to turn it into a Pulser Result, because the meta_data contained in this object depends on the emulator and we don't want to overwrite information, and because it has never been made clear what are the keys each emulator provides in their mata_data.

Concretely, the fact that nbshots=0 in AnalogQPU was the first impass we encountered. We would have to implement a sampling of the probability distribution we get, which is not the purpose of a simulation made using AnalogQPU (nor the purpose of convert_result_to_samples in my opinion).

However, it does not seem unfeasible to have a sample_myqlm_results method if that's of use ?

@HaroldErbin
Copy link
Author

HaroldErbin commented Nov 26, 2024

Hi Antoine,

Thanks for your comments. These are indeed the conclusions I had reached. I don't know how important it would be to have this feature: my motivation was to have a pipeline as close as possible with the QLM and the future Pasqal machine at TGCC. My understanding is that the latter would yield myQLM results which can be converted to Pulser samples. However, for testing purpose, I can as well do:

samples = {
            str(sample.state): int(sample.probability * len(results))
            for sample in results
        }

And for computations of observables, one can work directly with the probabilities.

Concretely, the fact that nbshots=0 in AnalogQPU was the first impass we encountered.

I was discussing with people at Eviden, and they told me that users can ask to get shots, but by default data is aggregated, which yields probabilities:

> job = IsingAQPU.convert_sequence_to_job(sequence, nbshots=0)
> job.aggregate_data
True

Maybe there is a way to ask myQLM to return non-aggregated data? In this case, you don't have to modify meta_data, you can just recover the samples and count them, and get the number of qubits in another way (res.qregs[0] ?).

Edit: it seems AnalogQPU cannot return samples indeed, the choice of aggregating or not seems to be only for digital emulators.

@a-corni
Copy link
Collaborator

a-corni commented Nov 27, 2024

For your testing, I suggest you use the multinomial distribution to sample the probability distribution obtained and stored in the myQLM Result object. This is what we do in Pulser https://github.com/pasqal-io/Pulser/blob/develop/pulser-core/pulser/result.py#L73.
I did not know about this aggregate option. As your edit says, it also seems to me that AnalogQPU cannot return samples indeed.

However, it seems to me there is enough material in the MyQLM Result class to have a function "get_pulser_result_from_myqlm_result", that would return you a Pulser Result from a MyQLM one. With the Pulser Result class, you will be able to use the method "get_samples" to get the samples (see above).

@HaroldErbin
Copy link
Author

Thanks for the additional comments. I will have a look at all this later and may propose a PR if this seems useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants