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

Implement AerDensityMatrix #1732

Merged
merged 7 commits into from
Feb 28, 2023
Merged

Conversation

derwind
Copy link
Contributor

@derwind derwind commented Feb 27, 2023

Summary

This is a PR to implement AerDensityMatrix, which is a fine-tuned version of #1676.

Details and comments

When this PR is approved, #1676 should be closed at the same time.

Copy link
Collaborator

@hhorii hhorii left a comment

Choose a reason for hiding this comment

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

To get consistent results of sample_memory(), seed() needs to be overwritten and self._aer_state needs to be used for this method.

a71f17f adds these function into AerStatevector.


self._result = None
self._configs = configs

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def seed(self, value=None):
"""Set the seed for the quantum state RNG."""
if value is None or isinstance(value, int):
self._aer_state.set_seed(value)
else:
raise AerError(f'This seed is not supported: type={value.__class__}, value={value}')

seed method is missing.

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 had overlooked this. So Terra's QuantumState.seed is called and the effect of the call to seed() in test_aer_densitymatrix.py is inadequate. OK, I will fix this as you suggested.

Comment on lines 181 to 184
aer_state = AerState(**self._aer_state.configuration())
aer_state.initialize(self._data, copy=False)
samples = aer_state.sample_memory(qubits, shots)
aer_state.close()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
aer_state = AerState(**self._aer_state.configuration())
aer_state.initialize(self._data, copy=False)
samples = aer_state.sample_memory(qubits, shots)
aer_state.close()
self._aer_state.close()
self._aer_state.renew()
self._aer_state.initialize(self._data, copy=False)
samples = self._aer_state.sample_memory(qubits, shots)
self._data = self._aer_state.move_to_ndarray()

To keep a random generator in AerState, sample_memory needs the same AerState instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I will correct it according to your suggestion and #1663.

@hhorii hhorii added this to the Aer 0.12.0 milestone Feb 28, 2023
Copy link
Collaborator

@hhorii hhorii left a comment

Choose a reason for hiding this comment

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

Now this looks good to me. Thank you for your contribution.

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

Successfully merging this pull request may close these issues.

2 participants