Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Circuits::MeasurementOperation< Time > Class Template Reference

Measurement operation class. More...

#include <Measurements.h>

Inheritance diagram for Circuits::MeasurementOperation< Time >:
Collaboration diagram for Circuits::MeasurementOperation< Time >:

Public Member Functions

 MeasurementOperation (const std::vector< std::pair< Types::qubit_t, size_t > > &qs={}, Time delay=0)
 Constructor.
std::vector< size_t > AffectedBits () const override
 Returns the classical bits affected by the measurement.
Types::qubits_vector AffectedQubits () const override
 Returns the qubits affected by the measurement.
virtual bool CanAffectQuantumState () const
 Find if the operation can affect the quantum state.
void Clear ()
 Clears the qubits and classical bits involved in the measurement.
std::shared_ptr< IOperation< Time > > Clone () const override
 Get a shared pointer to a clone of this object.
void Execute (const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
 Executes the measurement on the given simulator.
const std::vector< size_t > & GetBitsIndices () const
 Returns the classical bits where the measurement results are stored.
Types::time_type GetDelay () const
 Get the delay of the operation.
virtual size_t GetNumQubits () const
 Get the number of qubits affected by the operation.
std::shared_ptr< IOperation< Types::time_type > > getptr ()
 Get a shared pointer to this object.
const Types::qubits_vector & GetQubits () const
 Returns the qubits that are to be measured.
const std::vector< ReadoutRates > & GetReadout () const
 Per-index readout rates, empty when none are attached.
OperationType GetType () const override
 Get the type of the operation.
bool HasReadout () const
 True when readout rates are attached to this measurement.
virtual bool IsBranching () const
 Checks if the operation is a branching one.
bool IsClifford () const override
 Checks if the operation is a Clifford one.
virtual bool IsConditional () const
 Find if the operation is a conditional operation.
bool IsNoiseless () const
 Whether noise models skip this operation.
virtual bool NeedsEntanglementForDistribution () const
 Find if the operation needs entanglement for distribution.
std::shared_ptr< IOperation< Time > > Remap (const std::unordered_map< Types::qubit_t, Types::qubit_t > &qubitsMap, const std::unordered_map< Types::qubit_t, Types::qubit_t > &bitsMap={}) const override
 Get a shared pointer to a remapped operation.
void Sample (const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const
 Samples the measurement on the given simulator.
void SetBit (size_t index, Types::qubit_t bit)
 Set the classical bit to index.
virtual void SetDelay (Types::time_type d)
 Set the delay of the operation.
void SetNoiseless (bool value=true)
 Mark the operation as exempt from injected gate noise.
void SetQubit (size_t index, Types::qubit_t qubit)
 Set the qubit to measure.
void SetQubits (const std::vector< std::pair< Types::qubit_t, size_t > > &qs)
 Sets the qubits and classical bits involved in the measurement.
void SetReadout (std::vector< ReadoutRates > rates)
 Attach readout-error rates, one entry per measured index.
void SetReadoutAt (size_t index, const ReadoutRates &rates)
 Attach readout-error rates for a single measured index.
void SetStateFromSample (const std::vector< bool > &measurements, OperationState &state, Simulators::ISimulator *rng=nullptr) const
 Writes sampled outcomes into the classical state, applying readout error per measured qubit.

Detailed Description

template<typename Time = Types::time_type>
class Circuits::MeasurementOperation< Time >

Measurement operation class.

Implementation of an operation that does a qubits measurements on a simulator. The results are stored in a classical 'state'. Each qubit has a corresponding classical 'bit' where the measurement result is stored.

Template Parameters
TimeThe time type used for the simulation.
See also
IOperation

Definition at line 51 of file Measurements.h.

Constructor & Destructor Documentation

◆ MeasurementOperation()

template<typename Time = Types::time_type>
Circuits::MeasurementOperation< Time >::MeasurementOperation ( const std::vector< std::pair< Types::qubit_t, size_t > > & qs = {},
Time delay = 0 )
inline

Constructor.

Creates a measurement operation that measures the given qubits and stores the results in the given bits.

Parameters
qsThe qubits to measure and the classical bits where the result is stored, specified as pairs.
delayThe duration of the operation.
See also
IOperation

Definition at line 64 of file Measurements.h.

Member Function Documentation

◆ AffectedBits()

template<typename Time = Types::time_type>
std::vector< size_t > Circuits::MeasurementOperation< Time >::AffectedBits ( ) const
inlineoverridevirtual

Returns the classical bits affected by the measurement.

Returns the classical bits affected by the measurement.

Returns
The classical bits affected by the measurement.

Reimplemented from Circuits::IOperation< Types::time_type >.

Definition at line 253 of file Measurements.h.

References GetBitsIndices().

◆ AffectedQubits()

template<typename Time = Types::time_type>
Types::qubits_vector Circuits::MeasurementOperation< Time >::AffectedQubits ( ) const
inlineoverridevirtual

Returns the qubits affected by the measurement.

Returns the qubits affected by the measurement.

Returns
The qubits affected by the measurement.

Reimplemented from Circuits::IOperation< Types::time_type >.

Definition at line 242 of file Measurements.h.

◆ CanAffectQuantumState()

virtual bool Circuits::IOperation< Types::time_type >::CanAffectQuantumState ( ) const
inlinevirtualinherited

Find if the operation can affect the quantum state.

Returns true if the operation can affect the quantum state, false otherwise.

Returns
True if the operation can affect the quantum state, false otherwise.

Reimplemented in Circuits::Circuit< Time >, Circuits::Circuit< Types::time_type >, Circuits::Delay< Time >, and Circuits::QuantumChannelOperation< Time >.

Definition at line 473 of file Operations.h.

◆ Clear()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::Clear ( )
inline

Clears the qubits and classical bits involved in the measurement.

Clears the qubits and classical bits involved in the measurement.

Definition at line 97 of file Measurements.h.

◆ Clone()

template<typename Time = Types::time_type>
std::shared_ptr< IOperation< Time > > Circuits::MeasurementOperation< Time >::Clone ( ) const
inlineoverridevirtual

Get a shared pointer to a clone of this object.

Returns a shared pointer to a copy of this object.

Returns
A shared pointer to this object.

Implements Circuits::IOperation< Types::time_type >.

Definition at line 224 of file Measurements.h.

References Circuits::IOperation< Time >::GetDelay().

◆ Execute()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::Execute ( const std::shared_ptr< Simulators::ISimulator > & sim,
OperationState & state ) const
inlineoverridevirtual

Executes the measurement on the given simulator.

Executes the measurement on the given simulator.

Parameters
simThe simulator to execute the measurement on.
stateThe classical state for the simulator.
See also
ISimulator
OperationState

Implements Circuits::IOperation< Types::time_type >.

Definition at line 154 of file Measurements.h.

References SetStateFromSample().

◆ GetBitsIndices()

template<typename Time = Types::time_type>
const std::vector< size_t > & Circuits::MeasurementOperation< Time >::GetBitsIndices ( ) const
inline

Returns the classical bits where the measurement results are stored.

Returns the classical bits where the measurement results are stored.

Returns
The classical bits where the measurement results are stored.

Definition at line 139 of file Measurements.h.

Referenced by AffectedBits().

◆ GetDelay()

Types::time_type Circuits::IOperation< Types::time_type >::GetDelay ( ) const
inlineinherited

Get the delay of the operation.

Returns the delay due of the execution time of the operation.

Returns
The delay of the operation.

Definition at line 546 of file Operations.h.

Referenced by Circuits::NoOperation< Time >::Clone().

◆ GetNumQubits()

template<typename Time = Types::time_type>
virtual size_t Circuits::MeasurementOperation< Time >::GetNumQubits ( ) const
inlinevirtual

Get the number of qubits affected by the operation.

Returns the number of qubits affected by the operation.

Returns
The number of qubits affected by the operation.

Definition at line 87 of file Measurements.h.

◆ getptr()

std::shared_ptr< IOperation< Types::time_type > > Circuits::IOperation< Types::time_type >::getptr ( )
inlineinherited

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 535 of file Operations.h.

◆ GetQubits()

template<typename Time = Types::time_type>
const Types::qubits_vector & Circuits::MeasurementOperation< Time >::GetQubits ( ) const
inline

Returns the qubits that are to be measured.

Returns the qubits that are to be measured.

Returns
The qubits to measure.

Definition at line 128 of file Measurements.h.

◆ GetReadout()

template<typename Time = Types::time_type>
const std::vector< ReadoutRates > & Circuits::MeasurementOperation< Time >::GetReadout ( ) const
inline

Per-index readout rates, empty when none are attached.

Definition at line 364 of file Measurements.h.

◆ GetType()

template<typename Time = Types::time_type>
OperationType Circuits::MeasurementOperation< Time >::GetType ( ) const
inlineoverridevirtual

Get the type of the operation.

Returns the type of the operation, in this case, measurement.

Returns
The type of the operation.
See also
OperationType

Reimplemented from Circuits::IOperation< Types::time_type >.

Definition at line 76 of file Measurements.h.

References Circuits::kMeasurement.

◆ HasReadout()

template<typename Time = Types::time_type>
bool Circuits::MeasurementOperation< Time >::HasReadout ( ) const
inline

True when readout rates are attached to this measurement.

Definition at line 370 of file Measurements.h.

◆ IsBranching()

virtual bool Circuits::IOperation< Types::time_type >::IsBranching ( ) const
inlinevirtualinherited

◆ IsClifford()

template<typename Time = Types::time_type>
bool Circuits::MeasurementOperation< Time >::IsClifford ( ) const
inlineoverridevirtual

Checks if the operation is a Clifford one.

Checks if the operation is a Clifford one, allowing to be simulated in a stabilizers simulator.

Returns
True if it can be applied in a stabilizers simulator, false otherwise.

Reimplemented from Circuits::IOperation< Types::time_type >.

Definition at line 303 of file Measurements.h.

◆ IsConditional()

virtual bool Circuits::IOperation< Types::time_type >::IsConditional ( ) const
inlinevirtualinherited

Find if the operation is a conditional operation.

Returns true if the operation is conditional, false otherwise.

Returns
True if the operation is conditional, false otherwise.

Definition at line 500 of file Operations.h.

◆ IsNoiseless()

bool Circuits::IOperation< Types::time_type >::IsNoiseless ( ) const
inlineinherited

Whether noise models skip this operation.

Returns
True if no gate noise is injected after this operation.

Definition at line 580 of file Operations.h.

◆ NeedsEntanglementForDistribution()

virtual bool Circuits::IOperation< Types::time_type >::NeedsEntanglementForDistribution ( ) const
inlinevirtualinherited

Find if the operation needs entanglement for distribution.

Returns true if the operation needs entanglement for distribution, false otherwise.

Returns
True if the operation needs entanglement for distribution, false otherwise.

Reimplemented in Circuits::Circuit< Time >, Circuits::Circuit< Types::time_type >, and Circuits::QuantumChannelOperation< Time >.

Definition at line 488 of file Operations.h.

◆ Remap()

template<typename Time = Types::time_type>
std::shared_ptr< IOperation< Time > > Circuits::MeasurementOperation< Time >::Remap ( const std::unordered_map< Types::qubit_t, Types::qubit_t > & qubitsMap,
const std::unordered_map< Types::qubit_t, Types::qubit_t > & bitsMap = {} ) const
inlineoverridevirtual

Get a shared pointer to a remapped operation.

Returns a shared pointer to a copy of the operation with qubits and classical bits changed according to the provided maps.

Parameters
qubitsMapThe map of qubits to remap.
bitsMapThe map of classical bits to remap.
Returns
A shared pointer to the remapped object.

Implements Circuits::IOperation< Types::time_type >.

Definition at line 268 of file Measurements.h.

◆ Sample()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::Sample ( const std::shared_ptr< Simulators::ISimulator > & sim,
OperationState & state ) const
inline

Samples the measurement on the given simulator.

Samples the measurement on the given simulator. Should not apply the measurement.

Parameters
simThe simulator to sample the measurement on.
stateThe classical state for the simulator.
See also
ISimulator
OperationState

Definition at line 175 of file Measurements.h.

References SetStateFromSample().

◆ SetBit()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::SetBit ( size_t index,
Types::qubit_t bit )
inline

Set the classical bit to index.

This method sets the classical bit index at the specified index.

Parameters
indexThe index of the classical bit index.
bitThe classical bit index to set.

Definition at line 328 of file Measurements.h.

◆ SetDelay()

virtual void Circuits::IOperation< Types::time_type >::SetDelay ( Types::time_type d)
inlinevirtualinherited

Set the delay of the operation.

Sets the delay due of the execution time of the operation.

Parameters
dThe delay of the operation.

Definition at line 557 of file Operations.h.

◆ SetNoiseless()

void Circuits::IOperation< Types::time_type >::SetNoiseless ( bool value = true)
inlineinherited

Mark the operation as exempt from injected gate noise.

Noise models add no noise after a noiseless operation. This is for basis changes that belong to a non-Z measurement or reset rather than being gates in their own right. Gate copies (Clone, Remap) keep the mark.

Parameters
valueTrue to exempt the operation from gate noise.

Definition at line 570 of file Operations.h.

◆ SetQubit()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::SetQubit ( size_t index,
Types::qubit_t qubit )
inline

Set the qubit to measure.

This method sets the qubit to measure at the specified index.

Parameters
indexThe index of the qubit to measure.
qubitThe qubit to measure.

Definition at line 315 of file Measurements.h.

◆ SetQubits()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::SetQubits ( const std::vector< std::pair< Types::qubit_t, size_t > > & qs)
inline

Sets the qubits and classical bits involved in the measurement.

Sets the qubits and classical bits involved in the measurement, specified as pairs.

Parameters
qsThe qubits to measure and the classical bits where the result is stored, specified as pairs.

Definition at line 111 of file Measurements.h.

◆ SetReadout()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::SetReadout ( std::vector< ReadoutRates > rates)
inline

Attach readout-error rates, one entry per measured index.

Entries beyond qubits.size() are dropped, missing entries are zero. An empty vector removes readout error from this operation.

Parameters
ratesThe per-index rates to attach.

Definition at line 341 of file Measurements.h.

◆ SetReadoutAt()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::SetReadoutAt ( size_t index,
const ReadoutRates & rates )
inline

Attach readout-error rates for a single measured index.

Indices that are never set default to zero rates.

Parameters
indexThe measured index, not the classical bit.
ratesThe rates of the qubit measured at that index.

Definition at line 354 of file Measurements.h.

◆ SetStateFromSample()

template<typename Time = Types::time_type>
void Circuits::MeasurementOperation< Time >::SetStateFromSample ( const std::vector< bool > & measurements,
OperationState & state,
Simulators::ISimulator * rng = nullptr ) const
inline

Writes sampled outcomes into the classical state, applying readout error per measured qubit.

Parameters
measurementsOne outcome per measured index.
stateThe classical register to write.
rngSimulator whose RandomUniform() drives the readout flips. When null, or when no readout rates are attached, outcomes are written unchanged. Callers that aggregate shots must call this once per shot while HasReadout() is true – the flips are independent per shot.

Definition at line 196 of file Measurements.h.

References Circuits::OperationState::SetBit().

Referenced by Execute(), and Sample().


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