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

Conversation

@kuzminrobin
Copy link
Contributor

@kuzminrobin kuzminrobin commented Jan 12, 2022

Simplified the Dump functionality for QuantumSimulator and the functionality use in IQSharp.
This is a part of the set of 3 PRs:
Q#RT side,
IQ#,
Katas.

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

/azp help

@azure-pipelines
Copy link

Supported commands
  • help:
    • Get descriptions, examples and documentation about supported commands
    • Example: help "command_name"
  • list:
    • List all pipelines for this repository using a comment.
    • Example: "list"
  • run:
    • Run all pipelines or specific pipelines for this repository using a comment. Use this command by itself to trigger all related pipelines, or specify specific pipelines to run.
    • Example: "run" or "run pipeline_name, pipeline_name, pipeline_name"
  • where:
    • Report back the Azure DevOps orgs that are related to this repository and org
    • Example: "where"

See additional documentation.

Copy link
Contributor

@cgranade cgranade left a comment

Choose a reason for hiding this comment

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

Looks good to me! Had a last few comments, mostly about duplicated functionality in the string output for displayable states, but I think this is getting pretty close. Please let me know how I can help!

/// <see cref="Microsoft.Quantum.Simulation.Simulators.CommonNativeSimulator.StateDumper.Dump" />.
/// </remarks>
[JsonProperty("amplitudes")]
public Complex[]? Amplitudes { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

No suggested action at the moment, but when adding the sparse simulator, this will need to be generalized to a dictionary from indices to amplitudes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to a dictionary.

_count = qubits == null
? this.Simulator.QubitManager.AllocatedQubitsCount
: qubits.Length;
_data = new Complex[1 << ((int)_count)]; // If 0 qubits are allocated then the array has
Copy link
Contributor

Choose a reason for hiding this comment

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

No suggested action at the moment, but this will likely need to be changed to a dictionary ass well once the sparse simulator is added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to a dictionary.

Copy link
Contributor

@cgranade cgranade left a comment

Choose a reason for hiding this comment

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

Sorry, accidentally hit comment instead of approve.

Copy link
Contributor

@cgranade cgranade left a comment

Choose a reason for hiding this comment

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

Ah, you went on and modified DisplayableState to use a dictionary already! That should make adding in the sparse simulator much easier — your most recent changes should be precisely the logic needed to handle an incomplete sequence of callback calls.

Left a couple last comments about adapting some of SignificantAmplitudes to the new property, but otherwise looks good to me.

(
truncateSmallAmplitudes
? Amplitudes
.Select(idx_amplitude => idx_amplitude)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this line may not be needed now that Amplitudes is a dictionary?

Suggested change
.Select(idx_amplitude => idx_amplitude)

In any case, idx_amplitude is a KeyValuePair with the new definition of Amplitudes, such that it's no longer an index:

image

[nit / code style: the name idx_amplitude is in snake_case but should be in camelCase.]

.Where(item =>
System.Math.Pow(item.Value.Magnitude, 2.0) >= truncationThreshold
)
: Amplitudes.Select(idx_amplitude => idx_amplitude)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly here, the call to Select that was previously used to attach indices shouldn't be needed any more:

Suggested change
: Amplitudes.Select(idx_amplitude => idx_amplitude)
: Amplitudes

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