|
Maestro 0.2.5
Unified interface for quantum circuit simulation
|
Interface class for a quantum computing simulator state. More...
#include <State.h>
Inheritance diagram for Simulators::IState:
Collaboration diagram for Simulators::IState:Public Member Functions | |
| virtual | ~IState ()=default |
| Virtual destructor. | |
| virtual size_t | AllocateQubits (size_t num_qubits)=0 |
| Allocates qubits. | |
| virtual std::vector< double > | AllProbabilities ()=0 |
| Returns the probabilities of all possible outcomes. | |
| virtual std::complex< double > | Amplitude (Types::qubit_t outcome)=0 |
| Returns the amplitude of the specified state. | |
| virtual std::complex< double > | AmplitudeRaw (Types::qubit_t outcome)=0 |
| Gets the amplitude. | |
| virtual void | ApplyReset (const Types::qubits_vector &qubits)=0 |
| Performs a reset of the specified qubits. | |
| virtual void | Clear ()=0 |
| Clears the state. | |
| void | ClearObservers () |
| Clears all observers. | |
| virtual void | Configure (const char *key, const char *value)=0 |
| Configures the state. | |
| virtual double | ExpectationValue (const std::string &pauliString)=0 |
| Returns the expected value of a Pauli string. | |
| virtual void | Flush ()=0 |
| Flushes the applied operations. | |
| virtual std::string | GetConfiguration (const char *key) const =0 |
| Returns configuration value. | |
| virtual long long int | GetGatesCounter () const |
| Returns the gates counter. | |
| virtual bool | GetMultithreading () const =0 |
| Get the multithreading flag. | |
| virtual size_t | GetNumberOfQubits () const =0 |
| Returns the number of qubits. | |
| virtual SimulationType | GetSimulationType () const =0 |
| Returns the type of simulation. | |
| virtual SimulatorType | GetType () const =0 |
| Returns the type of simulator. | |
| virtual void | IncrementGatesCounter () |
| Increments the gates counter. | |
| virtual void | Initialize ()=0 |
| Initializes the state. | |
| virtual void | InitializeState (size_t num_qubits, AER::Vector< std::complex< double > > &litudes)=0 |
| Initializes the state. | |
| virtual void | InitializeState (size_t num_qubits, Eigen::VectorXcd &litudes)=0 |
| Initializes the state. | |
| virtual void | InitializeState (size_t num_qubits, std::vector< std::complex< double > > &litudes)=0 |
| Initializes the state. | |
| virtual bool | IsQcsim () const =0 |
| Returns if the simulator is a qcsim simulator. | |
| virtual size_t | Measure (const Types::qubits_vector &qubits)=0 |
| Performs a measurement on the specified qubits. | |
| virtual std::vector< bool > | MeasureMany (const Types::qubits_vector &qubits)=0 |
| Performs a measurement on the specified qubits. | |
| virtual Types::qubit_t | MeasureNoCollapse ()=0 |
| Measures all the qubits without collapsing the state. | |
| virtual std::vector< bool > | MeasureNoCollapseMany ()=0 |
| Measures all the qubits without collapsing the state. | |
| virtual std::vector< double > | Probabilities (const Types::qubits_vector &qubits)=0 |
| Returns the probabilities of the specified outcomes. | |
| virtual double | Probability (Types::qubit_t outcome)=0 |
| Returns the probability of the specified outcome. | |
| virtual std::complex< double > | ProjectOnZero ()=0 |
| Projects the state onto the zero state. | |
| void | RegisterObserver (const std::shared_ptr< ISimulatorObserver > &observer) |
| Registers an observer. | |
| virtual void | Reset ()=0 |
| Just resets the state to 0. | |
| virtual void | RestoreInternalDestructiveSavedState ()=0 |
| Restores the state from the internally saved state. | |
| virtual void | RestoreState ()=0 |
| Restores the state from the internally saved state. | |
| virtual std::unordered_map< Types::qubit_t, Types::qubit_t > | SampleCounts (const Types::qubits_vector &qubits, size_t shots=1000)=0 |
| Returns the counts of the outcomes of measurement of the specified qubits, for repeated measurements. | |
| virtual std::unordered_map< std::vector< bool >, Types::qubit_t > | SampleCountsMany (const Types::qubits_vector &qubits, size_t shots=1000)=0 |
| Returns the counts of the outcomes of measurement of the specified qubits, for repeated measurements. | |
| virtual void | SaveState ()=0 |
| Saves the state to internal storage. | |
| virtual void | SaveStateToInternalDestructive ()=0 |
| Saves the state to internal storage. | |
| virtual void | SetGatesCounter (long long int) |
| Sets the gates counter. | |
| virtual void | SetInitialQubitsMap (const std::vector< long long int > &initialMap) |
| Sets the initial qubits map, if possible. | |
| virtual void | SetLookaheadDepth (int) |
| Sets the lookahead depth for swap optimization. | |
| virtual void | SetLookaheadDepthWithHeuristic (int) |
| Sets the lookahead depth for swap optimization. | |
| virtual void | SetMultithreading (bool multithreading=true)=0 |
| Enable/disable multithreading. | |
| virtual void | SetUpcomingGates (const std::vector< std::shared_ptr< Circuits::IOperation< double > > > &) |
| Supplies upcoming gates for lookahead swap optimization. | |
| virtual void | SetUseOptimalMeetingPosition (bool) |
| Enables or disables optimal meeting position for MPS swaps. | |
| virtual bool | SupportsMPSSwapOptimization () const |
| Returns if the simulator supports MPS swap optimization. | |
| void | UnregisterObserver (const std::shared_ptr< ISimulatorObserver > &observer) |
| Unregisters an observer. | |
Protected Member Functions | |
| void | DontNotify () |
| Stops notifying observers. | |
| void | Notify () |
| Starts notifying observers. | |
| void | NotifyObservers (const Types::qubits_vector &affectedQubits) |
| Notifies observers. | |
Interface class for a quantum computing simulator state.
Use this interface if only the state of the simulator is required.
|
virtualdefault |
Virtual destructor.
Since this is a base class, the destructor should be virtual.
|
pure virtual |
Allocates qubits.
This function is called to allocate qubits.
| num_qubits | The number of qubits to allocate. |
Referenced by AllocateQubits().
|
pure virtual |
Returns the probabilities of all possible outcomes.
Use it to obtain the probabilities of all possible outcomes.
Referenced by AllProbabilities().
|
pure virtual |
Returns the amplitude of the specified state.
Use it to obtain the amplitude of the specified state.
| outcome | The outcome to obtain the amplitude for. |
Referenced by Amplitude().
|
pure virtual |
Gets the amplitude.
Gets the amplitude, from the internal storage if needed. This is needed only for the composite simulator, for an optimization for qiskit aer.
|
pure virtual |
Performs a reset of the specified qubits.
Measures the qubits and for those that are 1, applies X on them
| qubits | A vector with the qubits to be reset. |
|
pure virtual |
Clears the state.
Sets the number of allocated qubits to 0 and clears the state. After this qubits allocation is required then calling IState::AllocateQubits in order to use the simulator.
Referenced by ClearSimulator().
|
inline |
|
pure virtual |
Configures the state.
This function is called to configure the simulator. Currently only aer supports configuration, qcsim will gracefully ignore this.
| key | The key of the configuration option. |
| value | The value of the configuration. |
Referenced by ConfigureSimulator().
|
inlineprotected |
|
pure virtual |
Returns the expected value of a Pauli string.
Use it to obtain the expected value of a Pauli string. The Pauli string is a string of characters representing the Pauli operators, e.g. "XIZY". The length of the string should be less or equal to the number of qubits (if it's less, it's completed with I).
| pauliString | The Pauli string to obtain the expected value for. |
|
pure virtual |
Flushes the applied operations.
This function is called to flush the applied operations. qcsim applies them right away, so this has no effect on it, but qiskit aer does not.
Referenced by FlushSimulator().
|
pure virtual |
Returns configuration value.
This function is called get a configuration value.
| key | The key of the configuration value. |
Referenced by GetConfiguration().
|
inlinevirtual |
|
pure virtual |
Get the multithreading flag.
Returns the multithreading flag.
Referenced by GetMultithreading().
|
pure virtual |
Returns the number of qubits.
This function is called to obtain the number of the allocated qubits.
Referenced by GetNumberOfQubits().
|
pure virtual |
Returns the type of simulation.
Returns the type of simulation.
|
pure virtual |
Returns the type of simulator.
Returns the type of simulator.
|
inlinevirtual |
Increments the gates counter.
Usually does nothing, except for MPS simulators that support swap optimization. Increments the position in the circuit from where the execution should continue. Useful for classically controlled gates, for the case when the controlled gate is not executed.
|
pure virtual |
Initializes the state.
This function is called when the simulator is initialized. Call it after the qubits allocation.
Referenced by InitializeSimulator().
|
pure virtual |
Initializes the state.
This function is called when the simulator is initialized. Call it only on a non-initialized state. This is good only for a statevector simulator and should be used only by calling from a composite simulator.
| num_qubits | The number of qubits to initialize the state with. |
| amplitudes | A vector with the amplitudes to initialize the state with. |
|
pure virtual |
Initializes the state.
This function is called when the simulator is initialized. Call it only on a non-initialized state. This is good only for a statevector simulator and should be used only by calling from a composite simulator.
| num_qubits | The number of qubits to initialize the state with. |
| amplitudes | A vector with the amplitudes to initialize the state with. |
|
pure virtual |
Initializes the state.
This function is called when the simulator is initialized. Call it only on a non-initialized state. This is good only for a statevector simulator and should be used only by calling from a composite simulator.
| num_qubits | The number of qubits to initialize the state with. |
| amplitudes | A vector with the amplitudes to initialize the state with. |
|
pure virtual |
Returns if the simulator is a qcsim simulator.
Returns if the simulator is a qcsim simulator. This is just a helper function to ease things up: qcsim has different functionality exposed sometimes so it's good to know if we deal with qcsim or with qiskit aer.
Referenced by IsQcsim().
|
pure virtual |
Performs a measurement on the specified qubits.
Don't use it if the number of qubits is larger than the number of bits in the size_t type (usually 64), as the outcome will be undefined
| qubits | A vector with the qubits to be measured. |
|
pure virtual |
Performs a measurement on the specified qubits.
| qubits | A vector with the qubits to be measured. |
|
pure virtual |
Measures all the qubits without collapsing the state.
Measures all the qubits without collapsing the state, allowing to perform multiple shots. This is to be used only internally, only for the statevector simulators (or those based on them, as the composite ones). For the qiskit aer case, SaveStateToInternalDestructive is needed to be called before this. If one wants to use the simulator after such measurement(s), RestoreInternalDestructiveSavedState should be called at the end.
Don't use this for more qubits than the size of Types::qubit_t, as the result is packed in a limited number of bits (e.g. 64 bits for uint64_t)
|
pure virtual |
Measures all the qubits without collapsing the state.
Measures all the qubits without collapsing the state, allowing to perform multiple shots. This is to be used only internally, only for the statevector simulators (or those based on them, as the composite ones). For the qiskit aer case, SaveStateToInternalDestructive is needed to be called before this. If one wants to use the simulator after such measurement(s), RestoreInternalDestructiveSavedState should be called at the end.
Use this for more qubits than the size of Types::qubit_t
|
inlineprotected |
|
inlineprotected |
|
pure virtual |
Returns the probabilities of the specified outcomes.
Use it to obtain the probabilities of the specified outcomes.
| qubits | A vector with the qubits configuration outcomes. |
|
pure virtual |
Returns the probability of the specified outcome.
Use it to obtain the probability to obtain the specified outcome, if all qubits are measured.
| outcome | The outcome to obtain the probability for. |
Referenced by Probability().
|
pure virtual |
Projects the state onto the zero state.
Use it to project the state onto the zero state. For most simulator is the same as calling Amplitude(0), but for some simulators it can be optimized to be faster than calling Amplitude(0). This for now is done for qcsim mps and gpu mps.
|
inline |
Registers an observer.
Registers an observer that will be notified when the state changes.
| observer | A smart pointer to an observer. |
|
pure virtual |
Just resets the state to 0.
Does not destroy the internal state, just resets it to zero (as a 'reset' op on each qubit would do).
Referenced by ResetSimulator().
|
pure virtual |
Restores the state from the internally saved state.
Restores the state from the internally saved state, if needed. This does something only for qiskit aer.
Referenced by RestoreInternalDestructiveSavedState().
|
pure virtual |
Restores the state from the internally saved state.
Restores the state from the internally saved state, if needed. To be used in order to recover the state after doing measurements, for multiple shots executions. In the first phase, only qcsim will implement this.
Referenced by RestoreState().
|
pure virtual |
Returns the counts of the outcomes of measurement of the specified qubits, for repeated measurements.
Use it to obtain the counts of the outcomes of the specified qubits measurements. The state is not collapsed, so the measurement can be repeated 'shots' times.
Don't use it if the number of qubits is larger than the number of bits in the Types::qubit_t type (usually 64), as the outcome will be undefined.
| qubits | A vector with the qubits to be measured. |
| shots | The number of shots to perform. |
|
pure virtual |
Returns the counts of the outcomes of measurement of the specified qubits, for repeated measurements.
Use it to obtain the counts of the outcomes of the specified qubits measurements. The state is not collapsed, so the measurement can be repeated 'shots' times.
| qubits | A vector with the qubits to be measured. |
| shots | The number of shots to perform. |
|
pure virtual |
Saves the state to internal storage.
Saves the state to internal storage, if needed. Calling this will not destroy the internal state, unlike the 'Destructive' variant. To be used in order to recover the state after doing measurements, for multiple shots executions. In the first phase, only qcsim will implement this.
Referenced by SaveState().
|
pure virtual |
Saves the state to internal storage.
Saves the state to internal storage, if needed. Calling this should consider as the simulator is gone to uninitialized. Either do not use it except for getting amplitudes, or reinitialize the simulator after calling it. This is needed only for the composite simulator, for an optimization for qiskit aer.
Referenced by SaveStateToInternalDestructive().
|
inlinevirtual |
|
inlinevirtual |
Sets the initial qubits map, if possible.
This will do nothing for most simulators, but for the MPS simulator it will set the initial qubits if it supports it - that is, for qcsim and the gpu simulator it can set the mapping of the qubits to the positions in the chain, which can be used to optimize the swapping cost.
|
inlinevirtual |
Sets the lookahead depth for swap optimization.
Controls how many upcoming 2-qubit gates are considered when choosing the swap meeting position. 0 means no lookahead (immediate cost only). Only effective for MPS simulators. Requires upcoming gates to be supplied via SetUpcomingGates.
|
inlinevirtual |
Sets the lookahead depth for swap optimization.
Controls how many upcoming 2-qubit gates are considered when choosing the swap meeting position. 0 means no lookahead (immediate cost only). Only effective for MPS simulators. Requires upcoming gates to be supplied via SetUpcomingGates. This value sets a number of gates to lookahead without much cost increase.
|
pure virtual |
Enable/disable multithreading.
Enable/disable multithreading. Default is enabled.
| multithreading | A flag to indicate if multithreading should be enabled. |
Referenced by SetMultithreading().
|
inlinevirtual |
|
inlinevirtual |
|
inlinevirtual |
|
inline |
Unregisters an observer.
Unegisters an observer.
| observer | A smart pointer to an observer. |