Maestro 0.3.1
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:
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.
void ApplyAmplitudeDamping (Types::qubit_t qubit, double gamma)
void ApplyBitFlipNoise (Types::qubit_t qubit, double probability)
void ApplyBitPhaseFlipNoise (Types::qubit_t qubit, double probability)
void ApplyChannel (const Types::qubits_vector &targets, const QuantumChannel::KrausOperators &krausOperators)
 Alias matching the channel terminology used by QCSim's dense backend.
void ApplyCorrelatedPhaseFlipNoise (Types::qubit_t qubit0, Types::qubit_t qubit1, double probability)
void ApplyCorrelatedPhaseFlipNoise (Types::qubit_t qubit0, Types::qubit_t qubit1, double probability, double correlation)
void ApplyDephasingNoise (Types::qubit_t qubit, double probability)
 noise.h dephasing is a stochastic phase flip, not phase damping.
void ApplyDepolarizingMixingNoise (Types::qubit_t qubit, double mixingProbability)
 Depolarizing replacement (1-p)rho + p I/2, fully mixed at p=1.
void ApplyDepolarizingNoise (Types::qubit_t qubit, double errorProbability)
 Depolarizing noise using total nonidentity-Pauli probability p.
void ApplyGeneralizedAmplitudeDamping (Types::qubit_t qubit, double gamma, double excitedStatePopulation)
void ApplyKrausChannel (const Types::qubits_vector &targets, const QuantumChannel::KrausOperators &krausOperators)
 Apply an arbitrary CPTP map supplied in Kraus form.
void ApplyPauliChannel (const Types::qubits_vector &targets, const std::vector< double > &probabilities)
 Apply an arbitrary one- or two-qubit Pauli channel.
void ApplyPauliChannel (Types::qubit_t qubit, double px, double py, double pz)
 Apply a single-qubit Pauli channel specified by X/Y/Z probabilities.
void ApplyPhaseDamping (Types::qubit_t qubit, double gamma)
 Phase damping with coherence multiplier sqrt(1-gamma).
void ApplyPhaseDampingFromTime (Types::qubit_t qubit, double duration, double tPhi)
 Pure phase damping for a physical duration and T_phi.
void ApplyPhaseFlipNoise (Types::qubit_t qubit, double probability)
virtual void ApplyQuantumChannel (const Types::qubits_vector &targets, const QuantumChannel &channel)
 Applies a local CPTP quantum channel to one or two qubits.
virtual void ApplyReset (const Types::qubits_vector &qubits)=0
 Performs a reset of the specified qubits.
void ApplyT1Relaxation (Types::qubit_t qubit, double gamma)
 Alias for the exact T1 amplitude-damping channel.
void ApplyT1RelaxationFromTime (Types::qubit_t qubit, double duration, double t1)
 Exact T1 relaxation for a physical duration and time constant.
void ApplyThermalRelaxation (Types::qubit_t qubit, double duration, double t1, double t2, double excitedStatePopulation=0.0)
void ApplyTwoQubitDepolarizingMixingNoise (Types::qubit_t qubit0, Types::qubit_t qubit1, double mixingProbability)
void ApplyTwoQubitDepolarizingNoise (Types::qubit_t qubit0, Types::qubit_t qubit1, double errorProbability)
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 DensityMatrixHermiticityResidual () const
virtual std::complex< double > DensityMatrixOverlap (const IState &) const
virtual double DensityMatrixPurity () const
virtual std::complex< double > DensityMatrixTrace () const
 Mixed-state diagnostics.
virtual std::complex< double > DensityMatrixTraceOfSquare () const
virtual double ExpectationValue (const std::string &pauliString)=0
 Returns the expected value of a Pauli string.
virtual double FidelityWithStatevector (const Eigen::VectorXcd &) const
virtual void Flush ()=0
 Flushes the applied operations.
virtual const std::unordered_map< std::string, std::string > & GetConfigMap () const =0
virtual std::string GetConfiguration (const char *key) const =0
 Returns configuration value.
virtual size_t GetCurrentMaxBondDimension () const
 Returns the maximum bond dimension reached.
virtual long long int GetGatesCounter () const
 Returns the gates counter.
virtual double getGrowthFactorGate () const
virtual double getGrowthFactorSwap () const
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 HermitizeDensityMatrix ()
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 void InitializeToBasisState (size_t num_qubits, const std::vector< bool > &basisState)
 Initializes the state to a computational basis state.
virtual void InitializeToBasisState (size_t num_qubits, Types::qubit_t basisState)
 Initializes the state to a computational basis state.
virtual void InitializeToMixtureOfBasisStates (size_t num_qubits, const std::vector< std::pair< std::vector< bool >, double > > &mixture)
 Initializes the state to a classical mixture of computational basis states.
virtual void InitializeToMixtureOfBasisStates (size_t num_qubits, const std::vector< std::pair< Types::qubit_t, double > > &mixture)
 Initializes the state to a classical mixture of computational basis states.
virtual bool IsDensityMatrixHermitian (double=1e-10) const
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 Eigen::MatrixXcd PartialTrace (const Types::qubits_vector &) const
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.
virtual void ReCanonicalizeMatrixProductOperator ()
void RegisterObserver (const std::shared_ptr< ISimulatorObserver > &observer)
 Registers an observer.
virtual void Reset ()=0
 Just resets the state to 0.
virtual void RestoreDensityMatrixTrace ()
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 setGrowthFactorGate (double factor)
virtual void setGrowthFactorSwap (double factor)
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 SetSeed (uint64_t seed)
 Seed every random stream owned by this simulator.
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.
virtual bool SupportsQuantumChannels () const
 Returns whether this state retains channel ensembles directly.
virtual void TrimMatrixProductOperator ()
void UnregisterObserver (const std::shared_ptr< ISimulatorObserver > &observer)
 Unregisters an observer.

Static Public Member Functions

static uint64_t DeriveSeed (uint64_t seed, uint64_t stream)

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

Referenced by AllocateQubits(), Simulators::ISimulator::InitializeToBasisState(), and Simulators::ISimulator::InitializeToBasisState().

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

Referenced by AllProbabilities().

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

Referenced by Amplitude().

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

◆ ApplyAmplitudeDamping()

void Simulators::IState::ApplyAmplitudeDamping ( Types::qubit_t qubit,
double gamma )
inline

◆ ApplyBitFlipNoise()

void Simulators::IState::ApplyBitFlipNoise ( Types::qubit_t qubit,
double probability )
inline

Definition at line 557 of file State.h.

References ApplyQuantumChannel(), and Simulators::QuantumChannel::BitFlip().

◆ ApplyBitPhaseFlipNoise()

void Simulators::IState::ApplyBitPhaseFlipNoise ( Types::qubit_t qubit,
double probability )
inline

Definition at line 561 of file State.h.

References ApplyQuantumChannel(), and Simulators::QuantumChannel::BitPhaseFlip().

◆ ApplyChannel()

void Simulators::IState::ApplyChannel ( const Types::qubits_vector & targets,
const QuantumChannel::KrausOperators & krausOperators )
inline

Alias matching the channel terminology used by QCSim's dense backend.

Definition at line 539 of file State.h.

References ApplyKrausChannel().

◆ ApplyCorrelatedPhaseFlipNoise() [1/2]

void Simulators::IState::ApplyCorrelatedPhaseFlipNoise ( Types::qubit_t qubit0,
Types::qubit_t qubit1,
double probability )
inline

◆ ApplyCorrelatedPhaseFlipNoise() [2/2]

void Simulators::IState::ApplyCorrelatedPhaseFlipNoise ( Types::qubit_t qubit0,
Types::qubit_t qubit1,
double probability,
double correlation )
inline

◆ ApplyDephasingNoise()

void Simulators::IState::ApplyDephasingNoise ( Types::qubit_t qubit,
double probability )
inline

noise.h dephasing is a stochastic phase flip, not phase damping.

Definition at line 571 of file State.h.

References ApplyPhaseFlipNoise().

◆ ApplyDepolarizingMixingNoise()

void Simulators::IState::ApplyDepolarizingMixingNoise ( Types::qubit_t qubit,
double mixingProbability )
inline

Depolarizing replacement (1-p)rho + p I/2, fully mixed at p=1.

Definition at line 583 of file State.h.

References ApplyQuantumChannel(), and Simulators::QuantumChannel::DepolarizingMixing().

◆ ApplyDepolarizingNoise()

void Simulators::IState::ApplyDepolarizingNoise ( Types::qubit_t qubit,
double errorProbability )
inline

Depolarizing noise using total nonidentity-Pauli probability p.

Definition at line 576 of file State.h.

References ApplyQuantumChannel(), and Simulators::QuantumChannel::Depolarizing().

◆ ApplyGeneralizedAmplitudeDamping()

void Simulators::IState::ApplyGeneralizedAmplitudeDamping ( Types::qubit_t qubit,
double gamma,
double excitedStatePopulation )
inline

◆ ApplyKrausChannel()

void Simulators::IState::ApplyKrausChannel ( const Types::qubits_vector & targets,
const QuantumChannel::KrausOperators & krausOperators )
inline

Apply an arbitrary CPTP map supplied in Kraus form.

Definition at line 532 of file State.h.

References ApplyQuantumChannel().

Referenced by ApplyChannel().

◆ ApplyPauliChannel() [1/2]

void Simulators::IState::ApplyPauliChannel ( const Types::qubits_vector & targets,
const std::vector< double > & probabilities )
inline

Apply an arbitrary one- or two-qubit Pauli channel.

Definition at line 546 of file State.h.

References ApplyQuantumChannel(), and Simulators::QuantumChannel::Pauli().

◆ ApplyPauliChannel() [2/2]

void Simulators::IState::ApplyPauliChannel ( Types::qubit_t qubit,
double px,
double py,
double pz )
inline

Apply a single-qubit Pauli channel specified by X/Y/Z probabilities.

Definition at line 552 of file State.h.

References ApplyQuantumChannel(), and Simulators::QuantumChannel::Pauli().

◆ ApplyPhaseDamping()

void Simulators::IState::ApplyPhaseDamping ( Types::qubit_t qubit,
double gamma )
inline

Phase damping with coherence multiplier sqrt(1-gamma).

Definition at line 613 of file State.h.

References ApplyQuantumChannel(), and Simulators::QuantumChannel::PhaseDamping().

Referenced by ApplyPhaseDampingFromTime().

◆ ApplyPhaseDampingFromTime()

void Simulators::IState::ApplyPhaseDampingFromTime ( Types::qubit_t qubit,
double duration,
double tPhi )
inline

Pure phase damping for a physical duration and T_phi.

gamma=1-exp(-2 duration/T_phi), so coherences decay as exp(-duration/T_phi).

Definition at line 621 of file State.h.

References ApplyPhaseDamping().

◆ ApplyPhaseFlipNoise()

void Simulators::IState::ApplyPhaseFlipNoise ( Types::qubit_t qubit,
double probability )
inline

Definition at line 566 of file State.h.

References ApplyQuantumChannel(), and Simulators::QuantumChannel::PhaseFlip().

Referenced by ApplyDephasingNoise().

◆ ApplyQuantumChannel()

virtual void Simulators::IState::ApplyQuantumChannel ( const Types::qubits_vector & targets,
const QuantumChannel & channel )
inlinevirtual

Applies a local CPTP quantum channel to one or two qubits.

The order of target qubits has the same matrix convention as ApplyGenericTwoQubitGate: targets[0] is the least-significant local basis bit. Backends that do not represent mixed states exactly throw.

Definition at line 485 of file State.h.

Referenced by ApplyAmplitudeDamping(), ApplyBitFlipNoise(), ApplyBitPhaseFlipNoise(), ApplyCorrelatedPhaseFlipNoise(), ApplyCorrelatedPhaseFlipNoise(), ApplyDepolarizingMixingNoise(), ApplyDepolarizingNoise(), ApplyGeneralizedAmplitudeDamping(), ApplyKrausChannel(), ApplyPauliChannel(), ApplyPauliChannel(), ApplyPhaseDamping(), ApplyPhaseFlipNoise(), ApplyThermalRelaxation(), ApplyTwoQubitDepolarizingMixingNoise(), and ApplyTwoQubitDepolarizingNoise().

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

◆ ApplyT1Relaxation()

void Simulators::IState::ApplyT1Relaxation ( Types::qubit_t qubit,
double gamma )
inline

Alias for the exact T1 amplitude-damping channel.

Definition at line 594 of file State.h.

References ApplyAmplitudeDamping().

◆ ApplyT1RelaxationFromTime()

void Simulators::IState::ApplyT1RelaxationFromTime ( Types::qubit_t qubit,
double duration,
double t1 )
inline

Exact T1 relaxation for a physical duration and time constant.

Definition at line 599 of file State.h.

References ApplyAmplitudeDamping().

◆ ApplyThermalRelaxation()

void Simulators::IState::ApplyThermalRelaxation ( Types::qubit_t qubit,
double duration,
double t1,
double t2,
double excitedStatePopulation = 0.0 )
inline

◆ ApplyTwoQubitDepolarizingMixingNoise()

void Simulators::IState::ApplyTwoQubitDepolarizingMixingNoise ( Types::qubit_t qubit0,
Types::qubit_t qubit1,
double mixingProbability )
inline

◆ ApplyTwoQubitDepolarizingNoise()

void Simulators::IState::ApplyTwoQubitDepolarizingNoise ( Types::qubit_t qubit0,
Types::qubit_t qubit1,
double errorProbability )
inline

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

Referenced by ClearSimulator(), Simulators::ISimulator::InitializeToBasisState(), and Simulators::ISimulator::InitializeToBasisState().

◆ ClearObservers()

void Simulators::IState::ClearObservers ( )
inline

Clears all observers.

Clears all observers.

Definition at line 825 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.

Referenced by ConfigureSimulator(), and SetSeed().

◆ DensityMatrixHermiticityResidual()

virtual double Simulators::IState::DensityMatrixHermiticityResidual ( ) const
inlinevirtual

Definition at line 506 of file State.h.

◆ DensityMatrixOverlap()

virtual std::complex< double > Simulators::IState::DensityMatrixOverlap ( const IState & ) const
inlinevirtual

Definition at line 503 of file State.h.

◆ DensityMatrixPurity()

virtual double Simulators::IState::DensityMatrixPurity ( ) const
inlinevirtual

Definition at line 497 of file State.h.

◆ DensityMatrixTrace()

virtual std::complex< double > Simulators::IState::DensityMatrixTrace ( ) const
inlinevirtual

Mixed-state diagnostics.

Implemented by density-matrix and MPO backends.

Definition at line 494 of file State.h.

◆ DensityMatrixTraceOfSquare()

virtual std::complex< double > Simulators::IState::DensityMatrixTraceOfSquare ( ) const
inlinevirtual

Definition at line 500 of file State.h.

◆ DeriveSeed()

uint64_t Simulators::IState::DeriveSeed ( uint64_t seed,
uint64_t stream )
inlinestatic

◆ DontNotify()

void Simulators::IState::DontNotify ( )
inlineprotected

Stops notifying observers.

Use it to stop notifying observers until Notify is called.

Definition at line 985 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.

◆ FidelityWithStatevector()

virtual double Simulators::IState::FidelityWithStatevector ( const Eigen::VectorXcd & ) const
inlinevirtual

Definition at line 515 of file State.h.

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

Referenced by FlushSimulator().

◆ GetConfigMap()

virtual const std::unordered_map< std::string, std::string > & Simulators::IState::GetConfigMap ( ) const
pure virtual

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

Referenced by GetConfiguration().

◆ GetCurrentMaxBondDimension()

virtual size_t Simulators::IState::GetCurrentMaxBondDimension ( ) const
inlinevirtual

Returns the maximum bond dimension reached.

Returns the maximum bond dimension reached during execution, if applicable (mps simulator, either qcsim or gpu).

Definition at line 975 of file State.h.

◆ GetGatesCounter()

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

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

◆ getGrowthFactorGate()

virtual double Simulators::IState::getGrowthFactorGate ( ) const
inlinevirtual

Definition at line 389 of file State.h.

◆ getGrowthFactorSwap()

virtual double Simulators::IState::getGrowthFactorSwap ( ) const
inlinevirtual

Definition at line 388 of file State.h.

◆ GetMultithreading()

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

Get the multithreading flag.

Returns the multithreading flag.

Returns
The multithreading flag.

Referenced by GetMultithreading().

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

Referenced by GetNumberOfQubits().

◆ 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

◆ HermitizeDensityMatrix()

virtual void Simulators::IState::HermitizeDensityMatrix ( )
inlinevirtual

Definition at line 521 of file State.h.

◆ IncrementGatesCounter()

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

Definition at line 384 of file State.h.

◆ 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

Referenced by InitializeSimulator(), Simulators::ISimulator::InitializeToBasisState(), and Simulators::ISimulator::InitializeToBasisState().

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

◆ InitializeToBasisState() [1/2]

virtual void Simulators::IState::InitializeToBasisState ( size_t num_qubits,
const std::vector< bool > & basisState )
inlinevirtual

Initializes the state to a computational basis state.

Same as the Types::qubit_t overload, but the basis state is given as one bool per qubit so it is not limited to 64 qubits.

Parameters
num_qubitsThe number of qubits to initialize the state with.
basisStateThe computational basis state, entry i selects qubit i.

Reimplemented in Simulators::ISimulator.

Definition at line 232 of file State.h.

◆ InitializeToBasisState() [2/2]

virtual void Simulators::IState::InitializeToBasisState ( size_t num_qubits,
Types::qubit_t basisState )
inlinevirtual

Initializes the state to a computational basis state.

Call it only on a non-initialized state, it allocates the qubits and initializes the state itself. Every simulator supports this: backends with a direct primitive (density matrix, matrix product operator, matrix product state, statevector) use it; ISimulator provides a generic fallback (reset to |0...0>, then apply X on every set bit) for the rest.

Don't use it for more than 64 qubits, as the basis state is packed in a single Types::qubit_t; use the std::vector<bool> overload instead, which the matrix product operator and matrix product state backends (the only ones that can scale that far) support natively.

Parameters
num_qubitsThe number of qubits to initialize the state with.
basisStateThe computational basis state, bit i selects qubit i.

Reimplemented in Simulators::ISimulator.

Definition at line 214 of file State.h.

◆ InitializeToMixtureOfBasisStates() [1/2]

virtual void Simulators::IState::InitializeToMixtureOfBasisStates ( size_t num_qubits,
const std::vector< std::pair< std::vector< bool >, double > > & mixture )
inlinevirtual

Initializes the state to a classical mixture of computational basis states.

Same as the Types::qubit_t-keyed overload, but each basis state is given as one bool per qubit so it is not limited to 64 qubits. Currently only the matrix product operator backend supports this.

Parameters
num_qubitsThe number of qubits to initialize the state with.
mixtureThe mixture, as pairs of (basis state, weight).

Definition at line 281 of file State.h.

◆ InitializeToMixtureOfBasisStates() [2/2]

virtual void Simulators::IState::InitializeToMixtureOfBasisStates ( size_t num_qubits,
const std::vector< std::pair< Types::qubit_t, double > > & mixture )
inlinevirtual

Initializes the state to a classical mixture of computational basis states.

Sets the state to rho = sum_k weights[k] |states[k]><states[k]|. Call it only on a non-initialized state, it allocates the qubits and initializes the state itself. Weights are normalized so the trace is 1; only backends that can represent a mixed state support this - currently the density matrix and matrix product operator backends. Other backends throw, and there is no generic fallback: unlike a basis state, a mixture cannot be reached with unitary gates alone.

Don't use it for more than 64 qubits, as each basis state is packed in a single Types::qubit_t; use the std::vector<bool>-keyed overload instead for the matrix product operator backend, which can scale that far.

Parameters
num_qubitsThe number of qubits to initialize the state with.
mixtureThe mixture, as pairs of (basis state, weight).

Definition at line 260 of file State.h.

◆ IsDensityMatrixHermitian()

virtual bool Simulators::IState::IsDensityMatrixHermitian ( double = 1e-10) const
inlinevirtual

Definition at line 509 of file State.h.

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

Referenced by IsQcsim().

◆ Measure()

virtual size_t Simulators::IState::Measure ( const Types::qubits_vector & qubits)
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

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 virtual

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

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

◆ MeasureNoCollapseMany()

virtual std::vector< bool > Simulators::IState::MeasureNoCollapseMany ( )
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

Returns
The result of the measurements

◆ Notify()

void Simulators::IState::Notify ( )
inlineprotected

Starts notifying observers.

Use it to allow notifying observers.

Definition at line 992 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 1001 of file State.h.

◆ PartialTrace()

virtual Eigen::MatrixXcd Simulators::IState::PartialTrace ( const Types::qubits_vector & ) const
inlinevirtual

Definition at line 512 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.

Referenced by Probability().

◆ ProjectOnZero()

virtual std::complex< double > Simulators::IState::ProjectOnZero ( )
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.

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

◆ ReCanonicalizeMatrixProductOperator()

virtual void Simulators::IState::ReCanonicalizeMatrixProductOperator ( )
inlinevirtual

Definition at line 527 of file State.h.

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

Referenced by ResetSimulator().

◆ RestoreDensityMatrixTrace()

virtual void Simulators::IState::RestoreDensityMatrixTrace ( )
inlinevirtual

Definition at line 518 of file State.h.

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

Referenced by RestoreInternalDestructiveSavedState().

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

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

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

Referenced by SaveState().

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

Referenced by SaveStateToInternalDestructive().

◆ SetGatesCounter()

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

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

◆ setGrowthFactorGate()

virtual void Simulators::IState::setGrowthFactorGate ( double factor)
inlinevirtual

Definition at line 392 of file State.h.

◆ setGrowthFactorSwap()

virtual void Simulators::IState::setGrowthFactorSwap ( double factor)
inlinevirtual

Definition at line 391 of file State.h.

◆ SetInitialQubitsMap()

virtual void Simulators::IState::SetInitialQubitsMap ( const std::vector< long long int > & initialMap)
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.

Definition at line 316 of file State.h.

◆ SetLookaheadDepth()

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

Definition at line 337 of file State.h.

◆ SetLookaheadDepthWithHeuristic()

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

Definition at line 348 of file State.h.

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

Referenced by SetMultithreading().

◆ SetSeed()

virtual void Simulators::IState::SetSeed ( uint64_t seed)
inlinevirtual

Seed every random stream owned by this simulator.

Definition at line 129 of file State.h.

References Configure().

◆ SetUpcomingGates()

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

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

◆ SetUseOptimalMeetingPosition()

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

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

◆ SupportsMPSSwapOptimization()

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

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

◆ SupportsQuantumChannels()

virtual bool Simulators::IState::SupportsQuantumChannels ( ) const
inlinevirtual

Returns whether this state retains channel ensembles directly.

This is true for QCSim density-matrix/MPO states and Aer density-matrix states. MPO results remain subject to configured bond truncation. A statevector or MPS can sample Kraus trajectories, but does not retain the resulting ensemble in a single state.

Definition at line 476 of file State.h.

◆ TrimMatrixProductOperator()

virtual void Simulators::IState::TrimMatrixProductOperator ( )
inlinevirtual

Definition at line 524 of file State.h.

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


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