Maestro 0.2.5
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Simulators::ISimulator Class Referenceabstract

Interface class for a quantum computing simulator. More...

#include <Simulator.h>

+ Inheritance diagram for Simulators::ISimulator:
+ Collaboration diagram for Simulators::ISimulator:

Public Member Functions

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 ApplyCCX (Types::qubit_t qubit0, Types::qubit_t qubit1, Types::qubit_t qubit2)=0
 Applies a controlled controlled not gate to the qubits.
 
virtual void ApplyCH (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
 Applies a CH gate to the qubits.
 
virtual void ApplyCP (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double lambda)=0
 Applies a CP gate to the qubits.
 
virtual void ApplyCRx (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
 Applies a CRx gate to the qubits.
 
virtual void ApplyCRy (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
 Applies a CRy gate to the qubits.
 
virtual void ApplyCRz (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
 Applies a CRz gate to the qubits.
 
virtual void ApplyCSwap (Types::qubit_t ctrl_qubit, Types::qubit_t qubit0, Types::qubit_t qubit1)=0
 Applies a controlled swap gate to the qubits.
 
virtual void ApplyCSx (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
 Applies a CSx gate to the qubits.
 
virtual void ApplyCSxDAG (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
 Applies a CSx dagger gate to the qubits.
 
virtual void ApplyCU (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta, double phi, double lambda, double gamma)=0
 Applies a controlled U gate to the qubits.
 
virtual void ApplyCX (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
 Applies a CX gate to the qubits.
 
virtual void ApplyCY (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
 Applies a CY gate to the qubits.
 
virtual void ApplyCZ (Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
 Applies a CZ gate to the qubits.
 
virtual void ApplyH (Types::qubit_t qubit)=0
 Applies a Hadamard gate to the qubit.
 
virtual void ApplyK (Types::qubit_t qubit)=0
 Applies a K gate to the qubit.
 
virtual void ApplyNop ()=0
 Applies a nop.
 
virtual void ApplyP (Types::qubit_t qubit, double lambda)=0
 Applies a phase shift gate to the qubit.
 
virtual void ApplyReset (const Types::qubits_vector &qubits)=0
 Performs a reset of the specified qubits.
 
virtual void ApplyRx (Types::qubit_t qubit, double theta)=0
 Applies a Rx gate to the qubit.
 
virtual void ApplyRy (Types::qubit_t qubit, double theta)=0
 Applies a Ry gate to the qubit.
 
virtual void ApplyRz (Types::qubit_t qubit, double theta)=0
 Applies a Rz gate to the qubit.
 
virtual void ApplyS (Types::qubit_t qubit)=0
 Applies a S gate to the qubit.
 
virtual void ApplySDG (Types::qubit_t qubit)=0
 Applies a S dagger gate to the qubit.
 
virtual void ApplySwap (Types::qubit_t qubit0, Types::qubit_t qubit1)=0
 Applies a swap gate to the qubits.
 
virtual void ApplySx (Types::qubit_t qubit)=0
 Applies a Sx gate to the qubit.
 
virtual void ApplySxDAG (Types::qubit_t qubit)=0
 Applies a Sx dagger gate to the qubit.
 
virtual void ApplyT (Types::qubit_t qubit)=0
 Applies a T gate to the qubit.
 
virtual void ApplyTDG (Types::qubit_t qubit)=0
 Applies a T dagger gate to the qubit.
 
virtual void ApplyU (Types::qubit_t qubit, double theta, double phi, double lambda, double gamma)=0
 Applies a U gate to the qubit.
 
virtual void ApplyX (Types::qubit_t qubit)=0
 Applies a not gate to the qubit.
 
virtual void ApplyY (Types::qubit_t qubit)=0
 Applies a Y gate to the qubit.
 
virtual void ApplyZ (Types::qubit_t qubit)=0
 Applies a Z gate to the qubit.
 
virtual void Clear ()=0
 Clears the state.
 
void ClearObservers ()
 Clears all observers.
 
virtual std::unique_ptr< ISimulatorClone ()=0
 Clones the simulator.
 
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.
 
std::shared_ptr< ISimulatorgetptr ()
 Get a shared pointer to this object.
 
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 > > &amplitudes)=0
 Initializes the state.
 
virtual void InitializeState (size_t num_qubits, Eigen::VectorXcd &amplitudes)=0
 Initializes the state.
 
virtual void InitializeState (size_t num_qubits, std::vector< std::complex< double > > &amplitudes)=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_tSampleCounts (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_tSampleCountsMany (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.
 

Detailed Description

Interface class for a quantum computing simulator.

This is the interface that exposes the functionality of the quantum computing simulators. Use them wrapped in shared pointers.

See also
IState
AerSimulator
QCSimSimulator

Definition at line 33 of file Simulator.h.

Member Function Documentation

◆ AllocateQubits()

virtual size_t Simulators::IState::AllocateQubits ( size_t  num_qubits)
pure virtualinherited

Allocates qubits.

This function is called to allocate qubits.

Parameters
num_qubitsThe number of qubits to allocate.
Returns
The index of the first qubit allocated.

Referenced by AllocateQubits().

◆ AllProbabilities()

virtual std::vector< double > Simulators::IState::AllProbabilities ( )
pure virtualinherited

Returns the probabilities of all possible outcomes.

Use it to obtain the probabilities of all possible outcomes.

See also
IState::Probability
IState::Amplitude
IState::Probabilities
Returns
A vector with the probabilities of all possible outcomes.

Referenced by AllProbabilities().

◆ Amplitude()

virtual std::complex< double > Simulators::IState::Amplitude ( Types::qubit_t  outcome)
pure virtualinherited

Returns the amplitude of the specified state.

Use it to obtain the amplitude of the specified state.

See also
IState::Probability
IState::Probabilities
Parameters
outcomeThe outcome to obtain the amplitude for.
Returns
The amplitude of the specified outcome.

Referenced by Amplitude().

◆ AmplitudeRaw()

virtual std::complex< double > Simulators::IState::AmplitudeRaw ( Types::qubit_t  outcome)
pure virtualinherited

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.

◆ ApplyCCX()

virtual void Simulators::ISimulator::ApplyCCX ( Types::qubit_t  qubit0,
Types::qubit_t  qubit1,
Types::qubit_t  qubit2 
)
pure virtual

Applies a controlled controlled not gate to the qubits.

Applies a controlled controlled not gate to the specified qubits

Parameters
qubit0The first control qubit
qubit1The second control qubit
qubit2The target qubit

Referenced by ApplyCCX().

◆ ApplyCH()

virtual void Simulators::ISimulator::ApplyCH ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit 
)
pure virtual

Applies a CH gate to the qubits.

Applies a controlled Hadamard gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit

Referenced by ApplyCH().

◆ ApplyCP()

virtual void Simulators::ISimulator::ApplyCP ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit,
double  lambda 
)
pure virtual

Applies a CP gate to the qubits.

Applies a controlled phase gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit
lambdaThe phase shift angle.

Referenced by ApplyCP().

◆ ApplyCRx()

virtual void Simulators::ISimulator::ApplyCRx ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit,
double  theta 
)
pure virtual

Applies a CRx gate to the qubits.

Applies a controlled x rotation gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit
thetaThe rotation angle.

Referenced by ApplyCRx().

◆ ApplyCRy()

virtual void Simulators::ISimulator::ApplyCRy ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit,
double  theta 
)
pure virtual

Applies a CRy gate to the qubits.

Applies a controlled y rotation gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit
thetaThe rotation angle.

Referenced by ApplyCRy().

◆ ApplyCRz()

virtual void Simulators::ISimulator::ApplyCRz ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit,
double  theta 
)
pure virtual

Applies a CRz gate to the qubits.

Applies a controlled z rotation gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit
thetaThe rotation angle.

Referenced by ApplyCRz().

◆ ApplyCSwap()

virtual void Simulators::ISimulator::ApplyCSwap ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  qubit0,
Types::qubit_t  qubit1 
)
pure virtual

Applies a controlled swap gate to the qubits.

Applies a controlled swap gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
qubit0The first qubit
qubit1The second qubit

Referenced by ApplyCSwap().

◆ ApplyCSx()

virtual void Simulators::ISimulator::ApplyCSx ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit 
)
pure virtual

Applies a CSx gate to the qubits.

Applies a controlled squared root not gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit

Referenced by ApplyCSX().

◆ ApplyCSxDAG()

virtual void Simulators::ISimulator::ApplyCSxDAG ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit 
)
pure virtual

Applies a CSx dagger gate to the qubits.

Applies a controlled squared root not dagger gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit

Referenced by ApplyCSXDG().

◆ ApplyCU()

virtual void Simulators::ISimulator::ApplyCU ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit,
double  theta,
double  phi,
double  lambda,
double  gamma 
)
pure virtual

Applies a controlled U gate to the qubits.

Applies a controlled U gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit
thetaTheta parameter for the U gate
phiPhi parameter for the U gate
lambdaLambda parameter for the U gate
gammaGamma parameter for the U gate

Referenced by ApplyCU().

◆ ApplyCX()

virtual void Simulators::ISimulator::ApplyCX ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit 
)
pure virtual

Applies a CX gate to the qubits.

Applies a controlled X gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit

Referenced by ApplyCX().

◆ ApplyCY()

virtual void Simulators::ISimulator::ApplyCY ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit 
)
pure virtual

Applies a CY gate to the qubits.

Applies a controlled Y gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit

Referenced by ApplyCY().

◆ ApplyCZ()

virtual void Simulators::ISimulator::ApplyCZ ( Types::qubit_t  ctrl_qubit,
Types::qubit_t  tgt_qubit 
)
pure virtual

Applies a CZ gate to the qubits.

Applies a controlled Z gate to the specified qubits

Parameters
ctrl_qubitThe control qubit
tgt_qubitThe target qubit

Referenced by ApplyCZ().

◆ ApplyH()

virtual void Simulators::ISimulator::ApplyH ( Types::qubit_t  qubit)
pure virtual

Applies a Hadamard gate to the qubit.

Applies a Hadamard gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplyH().

◆ ApplyK()

virtual void Simulators::ISimulator::ApplyK ( Types::qubit_t  qubit)
pure virtual

Applies a K gate to the qubit.

Applies a K (Hy) gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplyK().

◆ ApplyNop()

virtual void Simulators::ISimulator::ApplyNop ( )
pure virtual

Applies a nop.

Applies a nop (no operation). Typically does (almost) nothing. Equivalent to an identity. For qiskit aer it will send the 'nop' to the qiskit aer simulator.

◆ ApplyP()

virtual void Simulators::ISimulator::ApplyP ( Types::qubit_t  qubit,
double  lambda 
)
pure virtual

Applies a phase shift gate to the qubit.

Applies a specified phase shift gate to the qubit

Parameters
qubitThe qubit to apply the gate to.
lambdaThe phase shift angle.

Referenced by ApplyP().

◆ ApplyReset()

virtual void Simulators::IState::ApplyReset ( const Types::qubits_vector qubits)
pure virtualinherited

Performs a reset of the specified qubits.

Measures the qubits and for those that are 1, applies X on them

Parameters
qubitsA vector with the qubits to be reset.

◆ ApplyRx()

virtual void Simulators::ISimulator::ApplyRx ( Types::qubit_t  qubit,
double  theta 
)
pure virtual

Applies a Rx gate to the qubit.

Applies an x rotation gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.
thetaThe rotation angle.

Referenced by ApplyRx().

◆ ApplyRy()

virtual void Simulators::ISimulator::ApplyRy ( Types::qubit_t  qubit,
double  theta 
)
pure virtual

Applies a Ry gate to the qubit.

Applies a y rotation gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.
thetaThe rotation angle.

Referenced by ApplyRy().

◆ ApplyRz()

virtual void Simulators::ISimulator::ApplyRz ( Types::qubit_t  qubit,
double  theta 
)
pure virtual

Applies a Rz gate to the qubit.

Applies a z rotation gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.
thetaThe rotation angle.

Referenced by ApplyRz().

◆ ApplyS()

virtual void Simulators::ISimulator::ApplyS ( Types::qubit_t  qubit)
pure virtual

Applies a S gate to the qubit.

Applies a S gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplyS().

◆ ApplySDG()

virtual void Simulators::ISimulator::ApplySDG ( Types::qubit_t  qubit)
pure virtual

Applies a S dagger gate to the qubit.

Applies a S dagger gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplySDG().

◆ ApplySwap()

virtual void Simulators::ISimulator::ApplySwap ( Types::qubit_t  qubit0,
Types::qubit_t  qubit1 
)
pure virtual

Applies a swap gate to the qubits.

Applies a swap gate to the specified qubits

Parameters
qubit0The first qubit
qubit1The second qubit

Referenced by ApplySwap().

◆ ApplySx()

virtual void Simulators::ISimulator::ApplySx ( Types::qubit_t  qubit)
pure virtual

Applies a Sx gate to the qubit.

Applies a Sx gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplySX().

◆ ApplySxDAG()

virtual void Simulators::ISimulator::ApplySxDAG ( Types::qubit_t  qubit)
pure virtual

Applies a Sx dagger gate to the qubit.

Applies a Sx dagger gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplySXDG().

◆ ApplyT()

virtual void Simulators::ISimulator::ApplyT ( Types::qubit_t  qubit)
pure virtual

Applies a T gate to the qubit.

Applies a T gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplyT().

◆ ApplyTDG()

virtual void Simulators::ISimulator::ApplyTDG ( Types::qubit_t  qubit)
pure virtual

Applies a T dagger gate to the qubit.

Applies a T dagger gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplyTDG().

◆ ApplyU()

virtual void Simulators::ISimulator::ApplyU ( Types::qubit_t  qubit,
double  theta,
double  phi,
double  lambda,
double  gamma 
)
pure virtual

Applies a U gate to the qubit.

Applies a U gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.
thetaThe first parameter.
phiThe second parameter.
lambdaThe third parameter.
gammaThe fourth parameter.

Referenced by ApplyU().

◆ ApplyX()

virtual void Simulators::ISimulator::ApplyX ( Types::qubit_t  qubit)
pure virtual

Applies a not gate to the qubit.

Applies a not (X) gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplyX().

◆ ApplyY()

virtual void Simulators::ISimulator::ApplyY ( Types::qubit_t  qubit)
pure virtual

Applies a Y gate to the qubit.

Applies a not (Y) gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplyY().

◆ ApplyZ()

virtual void Simulators::ISimulator::ApplyZ ( Types::qubit_t  qubit)
pure virtual

Applies a Z gate to the qubit.

Applies a not (Z) gate to the specified qubit

Parameters
qubitThe qubit to apply the gate to.

Referenced by ApplyZ().

◆ Clear()

virtual void Simulators::IState::Clear ( )
pure virtualinherited

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().

◆ ClearObservers()

void Simulators::IState::ClearObservers ( )
inlineinherited

Clears all observers.

Clears all observers.

Definition at line 480 of file State.h.

◆ Clone()

virtual std::unique_ptr< ISimulator > Simulators::ISimulator::Clone ( )
pure virtual

Clones the simulator.

Clones the simulator, including the state, the configuration and the internally saved state, if any. Does not copy the observers. Should be used mainly internally, to optimise multiple shots execution, copying the state from the simulator used for timing.

Returns
A unique pointer to the cloned simulator.

◆ Configure()

virtual void Simulators::IState::Configure ( const char *  key,
const char *  value 
)
pure virtualinherited

Configures the state.

This function is called to configure the simulator. Currently only aer supports configuration, qcsim will gracefully ignore this.

Parameters
keyThe key of the configuration option.
valueThe value of the configuration.

Referenced by ConfigureSimulator().

◆ DontNotify()

void Simulators::IState::DontNotify ( )
inlineprotectedinherited

Stops notifying observers.

Use it to stop notifying observers until Notify is called.

Definition at line 631 of file State.h.

◆ ExpectationValue()

virtual double Simulators::IState::ExpectationValue ( const std::string &  pauliString)
pure virtualinherited

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).

Parameters
pauliStringThe Pauli string to obtain the expected value for.
Returns
The expected value of the specified Pauli string.

◆ Flush()

virtual void Simulators::IState::Flush ( )
pure virtualinherited

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().

◆ GetConfiguration()

virtual std::string Simulators::IState::GetConfiguration ( const char *  key) const
pure virtualinherited

Returns configuration value.

This function is called get a configuration value.

Parameters
keyThe key of the configuration value.
Returns
The configuration value as a string.

Referenced by GetConfiguration().

◆ GetGatesCounter()

virtual long long int Simulators::IState::GetGatesCounter ( ) const
inlinevirtualinherited

Returns the gates counter.

Usually does nothing, except for MPS simulators that support swap optimization.

Returns
The number of gates executed in the circuit.

Definition at line 244 of file State.h.

◆ GetMultithreading()

virtual bool Simulators::IState::GetMultithreading ( ) const
pure virtualinherited

Get the multithreading flag.

Returns the multithreading flag.

Returns
The multithreading flag.

Referenced by GetMultithreading().

◆ GetNumberOfQubits()

virtual size_t Simulators::IState::GetNumberOfQubits ( ) const
pure virtualinherited

Returns the number of qubits.

This function is called to obtain the number of the allocated qubits.

Returns
The number of qubits.

Referenced by GetNumberOfQubits().

◆ getptr()

std::shared_ptr< ISimulator > Simulators::ISimulator::getptr ( )
inline

Get a shared pointer to this object.

Returns a shared pointer to this object. The object needs to be already wrapped in a shared pointer.

Returns
A shared pointer to this object.

Definition at line 346 of file Simulator.h.

◆ GetSimulationType()

virtual SimulationType Simulators::IState::GetSimulationType ( ) const
pure virtualinherited

Returns the type of simulation.

Returns the type of simulation.

Returns
The type of simulation.
See also
SimulationType

◆ GetType()

virtual SimulatorType Simulators::IState::GetType ( ) const
pure virtualinherited

Returns the type of simulator.

Returns the type of simulator.

Returns
The type of simulator.
See also
SimulatorType

◆ IncrementGatesCounter()

virtual void Simulators::IState::IncrementGatesCounter ( )
inlinevirtualinherited

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.

Definition at line 261 of file State.h.

◆ Initialize()

virtual void Simulators::IState::Initialize ( )
pure virtualinherited

Initializes the state.

This function is called when the simulator is initialized. Call it after the qubits allocation.

See also
IState::AllocateQubits

Referenced by InitializeSimulator().

◆ InitializeState() [1/3]

virtual void Simulators::IState::InitializeState ( size_t  num_qubits,
AER::Vector< std::complex< double > > &  amplitudes 
)
pure virtualinherited

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.

Parameters
num_qubitsThe number of qubits to initialize the state with.
amplitudesA vector with the amplitudes to initialize the state with.

◆ InitializeState() [2/3]

virtual void Simulators::IState::InitializeState ( size_t  num_qubits,
Eigen::VectorXcd &  amplitudes 
)
pure virtualinherited

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.

Parameters
num_qubitsThe number of qubits to initialize the state with.
amplitudesA vector with the amplitudes to initialize the state with.

◆ InitializeState() [3/3]

virtual void Simulators::IState::InitializeState ( size_t  num_qubits,
std::vector< std::complex< double > > &  amplitudes 
)
pure virtualinherited

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.

Parameters
num_qubitsThe number of qubits to initialize the state with.
amplitudesA vector with the amplitudes to initialize the state with.

◆ IsQcsim()

virtual bool Simulators::IState::IsQcsim ( ) const
pure virtualinherited

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.

Returns
True if the simulator is a qcsim simulator, false otherwise.

Referenced by IsQcsim().

◆ Measure()

virtual size_t Simulators::IState::Measure ( const Types::qubits_vector qubits)
pure virtualinherited

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

Parameters
qubitsA vector with the qubits to be measured.
Returns
The outcome of the measurements, the first qubit result is the least significant bit.

◆ MeasureMany()

virtual std::vector< bool > Simulators::IState::MeasureMany ( const Types::qubits_vector qubits)
pure virtualinherited

Performs a measurement on the specified qubits.

Parameters
qubitsA vector with the qubits to be measured.
Returns
The outcome of the measurements

◆ MeasureNoCollapse()

virtual Types::qubit_t Simulators::IState::MeasureNoCollapse ( )
pure virtualinherited

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)

Returns
The result of the measurements, the first qubit result is the least significant bit.

◆ MeasureNoCollapseMany()

virtual std::vector< bool > Simulators::IState::MeasureNoCollapseMany ( )
pure virtualinherited

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

Returns
The result of the measurements

◆ Notify()

void Simulators::IState::Notify ( )
inlineprotectedinherited

Starts notifying observers.

Use it to allow notifying observers.

Definition at line 638 of file State.h.

◆ NotifyObservers()

void Simulators::IState::NotifyObservers ( const Types::qubits_vector affectedQubits)
inlineprotectedinherited

Notifies observers.

Called when the state changes, to notify observers about it.

Parameters
affectedQubitsA vector with the qubits that were affected by the change.

Definition at line 647 of file State.h.

◆ Probabilities()

virtual std::vector< double > Simulators::IState::Probabilities ( const Types::qubits_vector qubits)
pure virtualinherited

Returns the probabilities of the specified outcomes.

Use it to obtain the probabilities of the specified outcomes.

See also
IState::Probability
IState::Amplitude
Parameters
qubitsA vector with the qubits configuration outcomes.
Returns
A vector with the probabilities for the specified qubit configurations.

◆ Probability()

virtual double Simulators::IState::Probability ( Types::qubit_t  outcome)
pure virtualinherited

Returns the probability of the specified outcome.

Use it to obtain the probability to obtain the specified outcome, if all qubits are measured.

See also
IState::Amplitude
IState::Probabilities
Parameters
outcomeThe outcome to obtain the probability for.
Returns
The probability of the specified outcome.

Referenced by Probability().

◆ ProjectOnZero()

virtual std::complex< double > Simulators::IState::ProjectOnZero ( )
pure virtualinherited

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.

See also
IState::Amplitude
IState::Probability
Returns
The inner product result as a complex number.

◆ RegisterObserver()

void Simulators::IState::RegisterObserver ( const std::shared_ptr< ISimulatorObserver > &  observer)
inlineinherited

Registers an observer.

Registers an observer that will be notified when the state changes.

See also
ISimulatorObserver
Parameters
observerA smart pointer to an observer.

Definition at line 459 of file State.h.

◆ Reset()

virtual void Simulators::IState::Reset ( )
pure virtualinherited

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().

◆ RestoreInternalDestructiveSavedState()

virtual void Simulators::IState::RestoreInternalDestructiveSavedState ( )
pure virtualinherited

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().

◆ RestoreState()

virtual void Simulators::IState::RestoreState ( )
pure virtualinherited

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().

◆ SampleCounts()

virtual std::unordered_map< Types::qubit_t, Types::qubit_t > Simulators::IState::SampleCounts ( const Types::qubits_vector qubits,
size_t  shots = 1000 
)
pure virtualinherited

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.

Parameters
qubitsA vector with the qubits to be measured.
shotsThe number of shots to perform.
Returns
A map with the counts for the otcomes of measurements of the specified qubits.

◆ SampleCountsMany()

virtual std::unordered_map< std::vector< bool >, Types::qubit_t > Simulators::IState::SampleCountsMany ( const Types::qubits_vector qubits,
size_t  shots = 1000 
)
pure virtualinherited

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.

Parameters
qubitsA vector with the qubits to be measured.
shotsThe number of shots to perform.
Returns
A map with the counts for the otcomes of measurements of the specified qubits.

◆ SaveState()

virtual void Simulators::IState::SaveState ( )
pure virtualinherited

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().

◆ SaveStateToInternalDestructive()

virtual void Simulators::IState::SaveStateToInternalDestructive ( )
pure virtualinherited

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().

◆ SetGatesCounter()

virtual void Simulators::IState::SetGatesCounter ( long long int  )
inlinevirtualinherited

Sets the gates counter.

Usually does nothing, except for MPS simulators that support swap optimization.

Parameters
counterThe position in the circuit from where the execution should continue.

Definition at line 253 of file State.h.

◆ SetInitialQubitsMap()

virtual void Simulators::IState::SetInitialQubitsMap ( const std::vector< long long int > &  initialMap)
inlinevirtualinherited

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.

Definition at line 193 of file State.h.

◆ SetLookaheadDepth()

virtual void Simulators::IState::SetLookaheadDepth ( int  )
inlinevirtualinherited

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.

Definition at line 214 of file State.h.

◆ SetLookaheadDepthWithHeuristic()

virtual void Simulators::IState::SetLookaheadDepthWithHeuristic ( int  )
inlinevirtualinherited

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.

Definition at line 225 of file State.h.

◆ SetMultithreading()

virtual void Simulators::IState::SetMultithreading ( bool  multithreading = true)
pure virtualinherited

Enable/disable multithreading.

Enable/disable multithreading. Default is enabled.

Parameters
multithreadingA flag to indicate if multithreading should be enabled.

Referenced by SetMultithreading().

◆ SetUpcomingGates()

virtual void Simulators::IState::SetUpcomingGates ( const std::vector< std::shared_ptr< Circuits::IOperation< double > > > &  )
inlinevirtualinherited

Supplies upcoming gates for lookahead swap optimization.

The simulator uses these to evaluate swap costs for future gates when choosing where to meet. Only effective for MPS simulators with lookahead depth > 0.

Definition at line 234 of file State.h.

◆ SetUseOptimalMeetingPosition()

virtual void Simulators::IState::SetUseOptimalMeetingPosition ( bool  )
inlinevirtualinherited

Enables or disables optimal meeting position for MPS swaps.

When enabled, the MPS simulator uses actual bond dimensions to find the cheapest meeting position for non-adjacent qubit swaps instead of the default heuristic. Does nothing for non-MPS simulators.

Definition at line 204 of file State.h.

◆ SupportsMPSSwapOptimization()

virtual bool Simulators::IState::SupportsMPSSwapOptimization ( ) const
inlinevirtualinherited

Returns if the simulator supports MPS swap optimization.

Used to check if the simulator supports MPS swap optimization.

Returns
True if the simulator supports MPS swap optimization, false otherwise.

Definition at line 183 of file State.h.

◆ UnregisterObserver()

void Simulators::IState::UnregisterObserver ( const std::shared_ptr< ISimulatorObserver > &  observer)
inlineinherited

Unregisters an observer.

Unegisters an observer.

See also
ISimulatorObserver
Parameters
observerA smart pointer to an observer.

Definition at line 471 of file State.h.


The documentation for this class was generated from the following file: