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

Add instructions to set simulator state #1163

Merged
merged 5 commits into from
Mar 26, 2021

Conversation

chriseclectic
Copy link
Member

@chriseclectic chriseclectic commented Feb 26, 2021

Summary

Add instructions for setting the simulator state to a custom value.

Note: performance for these instructions for large numbers of qubits will be quite bad since the instruction is being serialized via JSON which is very inefficient for matrices and vectors.

TODO:

  • Tests
  • Release note

Details and comments

Adds instructions for setting the simulator state for statevector, density matrix, unitary, and stabilizer methods. These are simulator directive instructions so cannot be unrolled to gates like initialize instructions. They also must be applied to all qubits in a circuit, unlike initialize.

Example

from qiskit import QuantumCircuit, execute
import qiskit.quantum_info as qi
from qiskit.providers.aer import QasmSimulator

nq = 2
rho = qi.random_density_matrix(2 ** nq)

qc = QuantumCircuit(nq)
qc.set_density_matrix(rho)
qc.save_density_matrix()

qiskit.execute(qc, QasmSimulator()).result().data(0)

For follow up PRs

  • Chunk state classes
  • Set matrix product state
  • Set extended stabilizer state

@chriseclectic chriseclectic added the Changelog: New Feature Include in the Added section of the changelog label Feb 26, 2021
@chriseclectic chriseclectic added this to the Aer 0.8 milestone Feb 26, 2021
@chriseclectic chriseclectic force-pushed the set-state branch 2 times, most recently from 587239a to fb2321f Compare March 24, 2021 21:29
@chriseclectic chriseclectic changed the title [WIP] Add instructions to set simulator state Add instructions to set simulator state Mar 24, 2021
Current support is for statevector, density matrix, unitary, superop, stabilizer
Move default_qubits to separate file

Move instructions to subfolders

Add set instructions to backends
Copy link
Contributor

@vvilpas vvilpas 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. I only have a small doubt regarding a switch block.

@@ -580,6 +580,9 @@ void State<statevec_t>::apply_ops(const std::vector<Operations::Op> &ops,
else if(op.name == "end_register_blocking"){
BaseState::qreg_.leave_register_blocking();
}
case OpType::set_statevec:
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we missing a break statement for the sim_op case?

@chriseclectic chriseclectic merged commit 25a6d91 into Qiskit:master Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the Added section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants