21#ifndef _SIMULATOR_STATE_H_
22#define _SIMULATOR_STATE_H_
26#include <unordered_map>
27#include <unordered_set>
31#include "framework/linalg/vector.hpp"
37template <
typename Time>
class IOperation;
134 size_t num_qubits, std::vector<std::complex<double>> &litudes) = 0;
150 size_t num_qubits, AER::Vector<std::complex<double>> &litudes) = 0;
166 Eigen::VectorXcd &litudes) = 0;
194 const std::vector<long long int> &initialMap) {}
272 virtual void Configure(
const char *key,
const char *value) = 0;
419 virtual std::unordered_map<Types::qubit_t, Types::qubit_t>
SampleCounts(
460 observers.insert(observer);
472 observers.erase(observer);
638 void Notify() { notifyObservers =
true; }
648 if (!notifyObservers)
return;
650 for (
auto &observer : observers) {
651 observer->Update(affectedQubits);
656 std::unordered_set<std::shared_ptr<ISimulatorObserver>>
658 bool notifyObservers =
Interface class for a quantum computing simulator state.
virtual void ApplyReset(const Types::qubits_vector &qubits)=0
Performs a reset of the specified qubits.
virtual bool IsQcsim() const =0
Returns if the simulator is a qcsim simulator.
virtual void SaveStateToInternalDestructive()=0
Saves the state to internal storage.
void Notify()
Starts notifying observers.
virtual std::vector< double > Probabilities(const Types::qubits_vector &qubits)=0
Returns the probabilities of the specified outcomes.
virtual void SetInitialQubitsMap(const std::vector< long long int > &initialMap)
Sets the initial qubits map, if possible.
virtual void SetUpcomingGates(const std::vector< std::shared_ptr< Circuits::IOperation< double > > > &)
Supplies upcoming gates for lookahead swap optimization.
void UnregisterObserver(const std::shared_ptr< ISimulatorObserver > &observer)
Unregisters an observer.
virtual void RestoreState()=0
Restores the state from the internally saved state.
virtual void SaveState()=0
Saves the state to internal storage.
virtual std::complex< double > ProjectOnZero()=0
Projects the state onto the zero state.
virtual double Probability(Types::qubit_t outcome)=0
Returns the probability of the specified outcome.
virtual void Initialize()=0
Initializes the state.
virtual size_t AllocateQubits(size_t num_qubits)=0
Allocates qubits.
void DontNotify()
Stops notifying observers.
virtual void InitializeState(size_t num_qubits, std::vector< std::complex< double > > &litudes)=0
Initializes the state.
virtual std::vector< double > AllProbabilities()=0
Returns the probabilities of all possible outcomes.
virtual void InitializeState(size_t num_qubits, AER::Vector< std::complex< double > > &litudes)=0
Initializes the state.
virtual SimulationType GetSimulationType() const =0
Returns the type of simulation.
virtual std::vector< bool > MeasureMany(const Types::qubits_vector &qubits)=0
Performs a measurement on the specified qubits.
virtual long long int GetGatesCounter() const
Returns the gates counter.
void RegisterObserver(const std::shared_ptr< ISimulatorObserver > &observer)
Registers an observer.
virtual void RestoreInternalDestructiveSavedState()=0
Restores the state from the internally saved state.
virtual void SetMultithreading(bool multithreading=true)=0
Enable/disable multithreading.
virtual void SetGatesCounter(long long int)
Sets the gates counter.
virtual double ExpectationValue(const std::string &pauliString)=0
Returns the expected value of a Pauli string.
virtual std::complex< double > Amplitude(Types::qubit_t outcome)=0
Returns the amplitude of the specified state.
virtual size_t GetNumberOfQubits() const =0
Returns the number of qubits.
virtual SimulatorType GetType() const =0
Returns the type of simulator.
virtual std::complex< double > AmplitudeRaw(Types::qubit_t outcome)=0
Gets the amplitude.
virtual void SetUseOptimalMeetingPosition(bool)
Enables or disables optimal meeting position for MPS swaps.
virtual void Flush()=0
Flushes the applied operations.
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 Configure(const char *key, const char *value)=0
Configures the state.
virtual void Clear()=0
Clears the state.
void ClearObservers()
Clears all observers.
void NotifyObservers(const Types::qubits_vector &affectedQubits)
Notifies observers.
virtual void SetLookaheadDepth(int)
Sets the lookahead depth for swap optimization.
virtual bool GetMultithreading() const =0
Get the multithreading flag.
virtual void SetLookaheadDepthWithHeuristic(int)
Sets the lookahead depth for swap optimization.
virtual size_t Measure(const Types::qubits_vector &qubits)=0
Performs a measurement on the specified qubits.
virtual std::vector< bool > MeasureNoCollapseMany()=0
Measures all the qubits without collapsing the state.
virtual ~IState()=default
Virtual destructor.
virtual void IncrementGatesCounter()
Increments the gates counter.
virtual void InitializeState(size_t num_qubits, Eigen::VectorXcd &litudes)=0
Initializes the state.
virtual bool SupportsMPSSwapOptimization() const
Returns if the simulator supports MPS swap optimization.
virtual void Reset()=0
Just resets the state to 0.
virtual std::string GetConfiguration(const char *key) const =0
Returns configuration value.
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 Types::qubit_t MeasureNoCollapse()=0
Measures all the qubits without collapsing the state.
SimulationType
The type of simulation.
@ kExtendedStabilizer
Extended stabilizer simulation type.
@ kOther
other simulation type, could occur for the aer simulator, which also has density matrix,...
@ kStatevector
statevector simulation type
@ kMatrixProductState
matrix product state simulation type
@ kStabilizer
Clifford gates simulation type.
@ kPauliPropagator
Pauli propagator simulation type.
@ kTensorNetwork
Tensor network simulation type.
SimulatorType
The type of simulator.
@ kCompositeQCSim
composite qcsim simulator type
@ kQCSim
qcsim simulator type
@ kQiskitAer
qiskit aer simulator type
@ kQuestSim
quest simulator type
@ kCompositeQiskitAer
composite qiskit aer simulator type
@ kGpuSim
gpu simulator type
uint_fast64_t qubit_t
The type of a qubit.
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.