Instruction Library (qiskit_aer.library
)¶
This library contains custom qiskit QuantumCircuit
Instruction
subclasses that can be used
with the Aer circuit simulator backends.
Setting a Custom Simulator State¶
The following instruction classes can be used to set the specific simulator methods to a custom state. Note that these instructions are only valid when applied to all qubits in a circuit. Applying to a subset of qubits will raise an exception during execution.
Instruction Classes¶

Set the statevector state of the simulator 

Set density matrix state of the simulator 

Set the Clifford stabilizer state of the simulator 

Set superop state of the simulator 

Set unitary state of the simulator 

Set the matrix product state of the simulator 
QuantumCircuit Methods¶
The set instructions can also be added to circuits by using the
following QuantumCircuit
methods which are patched when importing Aer.

Set the statevector state of the simulator. 

Set the density matrix state of the simulator. 

Set the Clifford stabilizer state of the simulator. 

Set the state state of the simulator. 

Set the superop state of the simulator. 

Set the matrix product state of the simulator. 
Saving Simulator Data¶
Simulator State Save Instruction Classes¶
The following instructions can be used to save the state of the simulator
into the returned result object. The SaveState
instruction will
automatically select the format based on the simulation method (eg.
SaveStatevector
for statevector method, SaveDensityMatrix
for density matrix method etc.).

Save simulator state 

Save statevector 

Save statevector as ketform dictionary. 

Save a reduced density matrix. 

Save matrix product state instruction 

Save Clifford instruction 

Save Stabilizer instruction 

Save a SuperOp matrix. 

Save Unitary 
참고
The SaveDensityMatrix
instruction can be used to save the
reduced densit matrix of a subset of qubits for supported simulation
methods, however all other save state instructions must be applied
to all qubits in a run circuit.
참고
The StatevectorSimulator
(and
UnitarySimulator
) backend automatically
append every run circuit with the a SaveStatevector`()
(SaveUnitary`()
) instruction using the default label. Hence adding
any additional save instructions of that type will require specifying a
custom label for those instructions.
Simulator Derived Data Save Instruction Classes¶
The following classes can be used to directly save data derived from the simulator state to the returned result object. One some are compatible with certain simulation methods.
For convenience the save instructions can be accessed using
custom QuantumCircuit
methods

Save expectation value of an operator. 

Save expectation value and variance of an operator. 

Save measurement outcome probabilities vector. 

Save measurement outcome probabilities dict. 

Save complex statevector amplitudes. 

Save squared statevector amplitudes (probabilities). 
참고
When saving pershot data by using the pershot=True
kwarg
in the above instructions, the resulting list may only contain
a single value rather than the number of shots. This
happens when a run circuit supports measurement sampling because
it is either
An ideal simulation with all measurements at the end.
2. A noisy simulation using the density matrix method with all measurements at the end.
In both these cases only a single shot is actually simulated and measurement samples for all shots are calculated from the final state.
QuantumCircuit Methods¶
The save instructions can also be added to circuits by using the
following QuantumCircuit
methods which are patched when importing Aer.
참고
Each save method has a default label for accessing from the circuit result data, however duplicate labels in results will result in an exception being raised. If you use more than 1 instance of a specific save instruction you must set a custom label for the additional instructions.

Save complex statevector amplitudes. 

Save squared statevector amplitudes (probabilities). 

Save the current stabilizer simulator quantum state as a Clifford. 

Save the current simulator quantum state as a density matrix. 

Save the expectation value of a Hermitian operator. 

Save the expectation value of a Hermitian operator. 

Save the current simulator quantum state as a matrix product state. 

Save measurement outcome probabilities vector. 

Save measurement outcome probabilities vector. 

Save the current stabilizer simulator quantum state as a StabilizerState. 

Save the current simulator quantum state. 

Save the current simulator quantum state as a statevector. 

Save the current simulator quantum state as a statevector as a dict. 

Save the current state of the superop simulator. 

Save the current state of the unitary simulator. 
Method Compatibility¶
The following table summarizes which instructions are compatible with which simulation methods
Instruction 
Automatic 
Statevector 
Density Matrix 
MPS 
Stabilizer 
Ext. Stabilizer 
Unitary 
SuperOp 

✔ 
✔ 
✘ 
✔ 
✘ 
✘ 
✘ 
✘ 

✔ 
✔ 
✔ 
✔ 
✔ 
✘ 
✘ 
✘ 

✔ 
✘ 
✘ 
✘ 
✔ 
✘ 
✘ 
✘ 

✔ 
✔ 
✔ 
✔ 
✘ 
✘ 
✘ 
✘ 

✔ 
✔ 
✔ 
✔ 
✔ 
✘ 
✘ 
✘ 

✔ 
✔ 
✔ 
✔ 
✔ 
✘ 
✘ 
✘ 

✘ 
✘ 
✘ 
✔ 
✘ 
✘ 
✘ 
✘ 

✔ 
✔ 
✔ 
✔ 
✔ 
✘ 
✘ 
✘ 

✔ 
✔ 
✔ 
✔ 
✔ 
✘ 
✘ 
✘ 

✔ 
✘ 
✘ 
✘ 
✔ 
✘ 
✘ 
✘ 

✔ 
✔ 
✔ 
✔ 
✔ 
✔ 
✔ 
✔ 

✔ 
✔ 
✘ 
✔ 
✘ 
✔ 
✘ 
✘ 

✔ 
✔ 
✘ 
✘ 
✘ 
✘ 
✘ 
✘ 

✘ 
✘ 
✘ 
✘ 
✘ 
✘ 
✘ 
✔ 

✘ 
✘ 
✘ 
✘ 
✘ 
✘ 
✔ 
✘ 

✔ 
✘ 
✔ 
✘ 
✘ 
✘ 
✘ 
✘ 

✔ 
✘ 
✘ 
✘ 
✔ 
✘ 
✘ 
✘ 

✔ 
✔ 
✘ 
✘ 
✘ 
✘ 
✘ 
✘ 

✘ 
✘ 
✘ 
✘ 
✘ 
✘ 
✔ 
✘ 
