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

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

#include <State.h>

Inheritance diagram for Simulators::IState:
Simulators::ISimulator

Public Member Functions

virtual ~IState ()=default
 Virtual destructor.
virtual void Initialize ()=0
 Initializes the state.
virtual void InitializeState (size_t num_qubits, std::vector< std::complex< double > > &amplitudes)=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 Reset ()=0
 Just resets the state to 0.
virtual void Configure (const char *key, const char *value)=0
 Configures the state.
virtual std::string GetConfiguration (const char *key) const =0
 Returns configuration value.
virtual size_t AllocateQubits (size_t num_qubits)=0
 Allocates qubits.
virtual size_t GetNumberOfQubits () const =0
 Returns the number of qubits.
virtual void Clear ()=0
 Clears the state.
virtual size_t Measure (const Types::qubits_vector &qubits)=0
 Performs a measurement on the specified qubits.
virtual void ApplyReset (const Types::qubits_vector &qubits)=0
 Performs a reset of the specified qubits.
virtual double Probability (Types::qubit_t outcome)=0
 Returns the probability of the specified outcome.
virtual std::complex< double > Amplitude (Types::qubit_t outcome)=0
 Returns the amplitude of the specified state.
virtual std::vector< double > AllProbabilities ()=0
 Returns the probabilities of all possible outcomes.
virtual std::vector< double > Probabilities (const Types::qubits_vector &qubits)=0
 Returns the probabilities of the specified outcomes.
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 double ExpectationValue (const std::string &pauliString)=0
 Returns the expected value of a Pauli string.
void RegisterObserver (const std::shared_ptr< ISimulatorObserver > &observer)
 Registers an observer.
void UnregisterObserver (const std::shared_ptr< ISimulatorObserver > &observer)
 Unregisters an observer.
void ClearObservers ()
 Clears all observers.
virtual SimulatorType GetType () const =0
 Returns the type of simulator.
virtual SimulationType GetSimulationType () const =0
 Returns the type of simulation.
virtual void Flush ()=0
 Flushes the applied operations.
virtual void SaveStateToInternalDestructive ()=0
 Saves the state to internal storage.
virtual void RestoreInternalDestructiveSavedState ()=0
 Restores the state from the internally saved state.
virtual void SaveState ()=0
 Saves the state to internal storage.
virtual void RestoreState ()=0
 Restores the state from the internally saved state.
virtual std::complex< double > AmplitudeRaw (Types::qubit_t outcome)=0
 Gets the amplitude.
virtual void SetMultithreading (bool multithreading=true)=0
 Enable/disable multithreading.
virtual bool GetMultithreading () const =0
 Get the multithreading flag.
virtual bool IsQcsim () const =0
 Returns if the simulator is a qcsim simulator.
virtual Types::qubit_t MeasureNoCollapse ()=0
 Measures all the qubits without collapsing the state.

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

Use this interface if only the state of the simulator is required.

See also
ISimulator

Definition at line 99 of file State.h.

Constructor & Destructor Documentation

◆ ~IState()

virtual Simulators::IState::~IState ( )
virtualdefault

Virtual destructor.

Since this is a base class, the destructor should be virtual.

Member Function Documentation

◆ AllocateQubits()

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

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.

◆ AllProbabilities()

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

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.

◆ Amplitude()

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

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.

◆ AmplitudeRaw()

virtual std::complex< double > Simulators::IState::AmplitudeRaw ( Types::qubit_t outcome)
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.

◆ ApplyReset()

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

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.

◆ Clear()

virtual void Simulators::IState::Clear ( )
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.

◆ ClearObservers()

void Simulators::IState::ClearObservers ( )
inline

Clears all observers.

Clears all observers.

Definition at line 346 of file State.h.

◆ Configure()

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

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.

◆ DontNotify()

void Simulators::IState::DontNotify ( )
inlineprotected

Stops notifying observers.

Use it to stop notifying observers until Notify is called.

Definition at line 478 of file State.h.

◆ ExpectationValue()

virtual double Simulators::IState::ExpectationValue ( const std::string & pauliString)
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).

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

◆ GetConfiguration()

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

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.

◆ GetMultithreading()

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

Get the multithreading flag.

Returns the multithreading flag.

Returns
The multithreading flag.

◆ GetNumberOfQubits()

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

Returns the number of qubits.

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

Returns
The number of qubits.

◆ GetSimulationType()

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

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 virtual

Returns the type of simulator.

Returns the type of simulator.

Returns
The type of simulator.
See also
SimulatorType

◆ Initialize()

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

Initializes the state.

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

See also
IState::AllocateQubits

◆ InitializeState() [1/3]

virtual void Simulators::IState::InitializeState ( size_t num_qubits,
AER::Vector< std::complex< double > > & amplitudes )
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.

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

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

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

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

◆ Measure()

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

Performs a measurement on the specified qubits.

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

◆ MeasureNoCollapse()

virtual Types::qubit_t Simulators::IState::MeasureNoCollapse ( )
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.

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

◆ Notify()

void Simulators::IState::Notify ( )
inlineprotected

Starts notifying observers.

Use it to allow notifying observers.

Definition at line 485 of file State.h.

◆ NotifyObservers()

void Simulators::IState::NotifyObservers ( const Types::qubits_vector & affectedQubits)
inlineprotected

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 494 of file State.h.

◆ Probabilities()

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

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 virtual

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.

◆ RegisterObserver()

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

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 325 of file State.h.

◆ Reset()

virtual void Simulators::IState::Reset ( )
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).

◆ RestoreInternalDestructiveSavedState()

virtual void Simulators::IState::RestoreInternalDestructiveSavedState ( )
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.

◆ RestoreState()

virtual void Simulators::IState::RestoreState ( )
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.

◆ SampleCounts()

virtual std::unordered_map< Types::qubit_t, Types::qubit_t > Simulators::IState::SampleCounts ( const Types::qubits_vector & qubits,
size_t shots = 1000 )
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.

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

◆ SaveStateToInternalDestructive()

virtual void Simulators::IState::SaveStateToInternalDestructive ( )
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.

◆ SetMultithreading()

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

Enable/disable multithreading.

Enable/disable multithreading. Default is enabled.

Parameters
multithreadingA flag to indicate if multithreading should be enabled.

◆ UnregisterObserver()

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

Unregisters an observer.

Unegisters an observer.

See also
ISimulatorObserver
Parameters
observerA smart pointer to an observer.

Definition at line 337 of file State.h.


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