Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Cherry-Picked: Broken up QuantumSimulator into CommonNativeSimulator and QuantumSimulator #895

Merged
merged 2 commits into from
Jan 11, 2022

Conversation

kuzminrobin
Copy link
Contributor

Cherry-picked to main the feature-branch changes of these 2 PRs:

@swernli
Copy link
Collaborator

swernli commented Jan 10, 2022

@kuzminrobin What is the intent of this change? Does the additional layer of indirection make the infrastructure more compatible with the sparse simulator? The changes seem reasonable, it's just hard to tell from the files what this enables.

@swernli swernli self-assigned this Jan 11, 2022
@kuzminrobin
Copy link
Contributor Author

@swernli wrote:

@kuzminrobin What is the intent of this change? Does the additional layer of indirection make the infrastructure more compatible with the sparse simulator? The changes seem reasonable, it's just hard to tell from the files what this enables.

Brief extract from an email that I have written to Bettina and Cassandra:
I would like to cherry-pick from the feature branch feature/sparse-simulator to the main the change that extracts from the QuantumSimulator the part common for QuantumSimulator and SparseSimulator – CommonNativeSimulator (see this PR). It just seems more natural to simplify the Dump on top of that change, because some of the code fragments need to relocate from IQSharp to the class common for QuantumSimulator and SparseSimulator (rather than to QuantumSimulator).
Then I plan to re-do the Dump changes on the QuantumSimulator side (with improvements that move some code to CommonNativeSimulator).

@kuzminrobin
Copy link
Contributor Author

@swernli wrote:

@kuzminrobin What is the intent of this change? Does the additional layer of indirection make the infrastructure more compatible with the sparse simulator? The changes seem reasonable, it's just hard to tell from the files what this enables.

This is preparation for SparseSimulator, which has common part with QuantumSimulator. That common part is being extracted into a common parent - CommonNativeSimulator.

Copy link
Collaborator

@swernli swernli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional context!

/// <summary>
/// The max number used as qubit id so far.
/// </summary>
public long MaxId { get; private set; }

public override Qubit CreateQubitObject(long id)
{
Debug.Assert(id < 50, "Using a qubit id > 50. This is a full-state simulator! Validating ids uniquenes might start becoming slow.");
Debug.Assert(id < 50, "Using a qubit id > 50. This is a full-state simulator! Validating ids uniqueness might start becoming slow.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sparse simulator may handle more than 50 qubits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what should be the number here instead of 50?

Copy link
Contributor

@DmitryVasilevsky DmitryVasilevsky Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically there's no artificial limit. You may have millions of qubits as long as they are all in zero state. However, it's hard to imagine a meaningful program that would need that many all in the zero state. I believe there're tests that check functionality of the simulator with a few thousand qubits. But the point is - the check for full state simulator and sparse simulator should be substantially different. And the limit for sparse simulator should probably be around a few thousand.

if (targets == null) throw new ArgumentNullException(nameof(targets), "Trying to perform an intrinsic operation on a null Qubit array.");
if (targets.Length == 0) throw new ArgumentNullException(nameof(targets), "Trying to perform an intrinsic operation on an empty Qubit array.");

bool[] used = new bool[((QSimQubitManager)QubitManager).MaxId];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in a few other places. For the full state simulator the maximum number of qubits were small. Sparse simulator can handle quite a few more in certain circumstances. It may not be always desirable to allocate array with the size of the number of qubits. I would consider array for a full state simulator and use HashSet for the sparse simulator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't touch the SparseSimulator for a few months and I don't remember exactly its difference from the QuantumSimulator. And before I get back to the SparseSimulator I also need to resolve the Dump functionality issue. So paying significant attention to the SparseSim at this stage seems to me less efficient than if I move forward now. I will get back to SparseSim later any way, and that's when I plan to finalize the changes.
If there are no critical objections, I would prefer to move forward with this PR at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK leaving this as is, especially given that sparse simulator won't be used on more than a few thousand qubits. Maybe we should note this somewhere - comments or work item.

@kuzminrobin kuzminrobin merged commit b7668ca into main Jan 11, 2022
@kuzminrobin kuzminrobin deleted the kuzminrobin/extractComnNatvSim branch January 11, 2022 19:37
@kuzminrobin kuzminrobin mentioned this pull request Jan 26, 2022
17 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants