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

Circuit class for holding the sequence of operations that can be compared with another circuit. More...

#include <Circuit.h>

Inheritance diagram for Circuits::ComparableCircuit< Time >:
Circuits::Circuit< Types::time_type > Circuits::IOperation< Types::time_type >

Public Types

using BaseClass = Circuit<Time>
 The base class type.
using Operation = IOperation<Time>
 The operation type.
using OperationPtr = std::shared_ptr<Operation>
 The shared pointer to the operation type.
using OperationsVector
 The vector of operations.
Public Types inherited from Circuits::Circuit< Types::time_type >
using ExecuteResults
 The results of the execution of the circuit.
using BitMapping
 The (qu)bit mapping for remapping.
using Operation
 The operation type.
using OperationPtr
 The shared pointer to the operation type.
using OperationsVector
 The vector of operations.
using value_type
using allocator_type
using pointer
using const_pointer
using reference
using const_reference
using size_type
using difference_type
using iterator
using const_iterator
using reverse_iterator
using const_reverse_iterator

Public Member Functions

 ComparableCircuit (const OperationsVector &ops={})
 Construct a new ComparableCircuit object.
 ComparableCircuit (const BaseClass &circ)
 Construct a new ComparableCircuit object.
ComparableCircuitoperator= (const BaseClass &circ)
 Assignment operator.
bool operator== (const BaseClass &rhs) const
 Comparison operator.
bool operator!= (const BaseClass &rhs) const
 Comparison operator.
void SetApproximateParamsCheck (bool check)
 Sets whether to check approximate equality of gate parameters.
bool GetApproximateParamsCheck () const
 Gets whether to check approximate equality of gate parameters.
void SetParamsEpsilon (double eps)
 Sets the epsilon used for checking approximate equality of gate parameters.
double GetParamsEpsilon () const
 Gets the epsilon used for checking approximate equality of gate parameters.
Public Member Functions inherited from Circuits::Circuit< Types::time_type >
 Circuit (const OperationsVector &ops={})
 Construct a new Circuit object.
void Execute (const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
 Execute the circuit on the given simulator.
OperationType GetType () const override
 Get the type of the circuit.
void AddOperation (const OperationPtr &op)
 Adds an operation to the circuit.
void ReplaceOperation (size_t index, const OperationPtr &op)
 Replaces an operation in the circuit.
void SetOperations (const OperationsVector &ops)
 Set the operations in the circuit.
void AddOperations (const OperationsVector &ops)
 Adds operations to the circuit.
void AddCircuit (const std::shared_ptr< Circuit< Types::time_type > > &circuit)
 Adds operations from another circuit to the circuit.
const OperationsVectorGetOperations () const
 Get the operations in the circuit.
void Clear ()
 Clears the operations from the circuit.
OperationPtr Clone () const override
 Get a shared pointer to a clone of this object.
OperationPtr CloneFlyweight () const
 Get a shared pointer to a clone of this object, but without cloning the operations.
OperationPtr Remap (const BitMapping &qubitsMap, const BitMapping &bitsMap={}) const override
 Get a shared pointer to a circuit remapped.
std::shared_ptr< Circuit< Types::time_type > > RemapToContinuous (BitMapping &newQubitsMap, BitMapping &reverseBitsMap, size_t &nrQubits, size_t &nrCbits) const
 Get a shared pointer to a circuit remapped to a continuous interval starting from zero.
void ConvertForDistribution ()
 Converts the circuit for distributed computing.
void ConvertForCutting ()
 Converts the circuit for distributed computing.
void EnsureProperOrderForMeasurements ()
size_t GetMaxQubitIndex () const
 Returns the max qubit id for all operations.
size_t GetMinQubitIndex () const
 Returns the min qubit id for all operations.
size_t GetMaxCbitIndex () const
 Returns the max classical bit id for all operations.
size_t GetMinCbitIndex () const
 Returns the min classical bit id for all operations.
std::set< size_t > GetQubits () const
 Returns the qubits affected by the operations.
std::set< size_t > GetBits () const
 Returns the classical bits affected by the operations.
Types::qubits_vector AffectedQubits () const override
 Returns the affected qubits.
std::vector< size_t > AffectedBits () const override
 Returns the affected bits.
bool NeedsEntanglementForDistribution () const override
 Find if the circuit needs entanglement for distribution.
bool CanAffectQuantumState () const override
 Find if the circuit can affect the quantum state.
std::unordered_map< size_t, OperationPtrGetLastOperationsOnQubits () const
 Returns the last operations on circuit's qubits.
std::unordered_map< size_t, OperationPtrGetFirstOperationsOnQubits () const
 Returns the first operations on circuit's qubits.
void AddResetsIfNeeded (Types::time_type delay=0)
 Add resets at the end of the circuit.
void AddResetsAtBeginningIfNeeded (Types::time_type delay=0)
 Add resets at the beginning of the circuit.
void Optimize (bool optimizeRotationGates=true)
 Circuit optimization.
void MoveMeasurementsAndResets ()
 Move the measurements and resets closer to the beginning of the circuit.
std::pair< std::vector< size_t >, std::vector< Types::time_type > > GetDepth () const
 Get circuit depth.
std::pair< size_t, Types::time_typeGetMaxDepth () const
 Get max circuit depth.
size_t GetNumberOfOperations () const
 Get the number of operations in the circuit.
OperationPtr GetOperation (size_t pos) const
 Get an operation at a given position.
std::shared_ptr< Circuit< Types::time_type > > GetCircuitCut (Types::qubit_t startQubit, Types::qubit_t endQubit) const
 Get the circuit cut.
bool HasOpsAfterMeasurements () const
 Checks if the circuit has measurements that are followed by operations that affect the measured qubits.
std::vector< bool > ExecuteNonMeasurements (const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const
 Execute the non-measurements operations from the circuit on the given simulator.
void ExecuteMeasurements (const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state, const std::vector< bool > &executedOps) const
 Execute the measurement operations from the circuit on the given simulator.
std::shared_ptr< MeasurementOperation< Types::time_type > > GetLastMeasurements (const std::vector< bool > &executedOps, bool sort=true) const
bool HasConditionalOperations () const
 Checks if the circuit has clasically conditional operations.
bool ActsOnlyOnAdjacentQubits () const
 Checks if the circuit has only operations that act on adjacent qubits.
bool IsForest () const
 Checks if the circuit is a forest circuit.
bool IsClifford () const override
 Checks if the circuit is a Clifford circuit.
double CliffordPercentage () const
 Get the percentage of Clifford operations in the circuit.
std::unordered_set< Types::qubit_tGetCliffordQubits () const
 Get the qubits that are acted on by Clifford operations.
std::vector< std::shared_ptr< Circuit< Types::time_type > > > SplitCircuit () const
 Splits a circuit that has disjoint subcircuits in it into separate circuits.
iterator begin () noexcept
 Get the begin iterator for the operations.
iterator end () noexcept
 Get the end iterator for the operations.
const_iterator cbegin () const noexcept
 Get the const begin iterator for the operations.
const_iterator cend () const noexcept
 Get the const end iterator for the operations.
reverse_iterator rbegin () noexcept
 Get the reverse begin iterator for the operations.
reverse_iterator rend () noexcept
 Get the reverse end iterator for the operations.
const_reverse_iterator crbegin () const noexcept
 Get the const reverse begin iterator for the operations.
const_reverse_iterator crend () const noexcept
 Get the const reverse end iterator for the operations.
auto size () const
 Get the number of operations in the circuit.
auto empty () const
 Check if the circuit is empty.
auto & operator[] (size_t pos)
 Get the operation at a given position.
void resize (size_t size)
 Resizes the circuit.
Public Member Functions inherited from Circuits::IOperation< Types::time_type >
 IOperation (Types::time_type delay=0)
 Construct a new IOperation object.
virtual ~IOperation ()=default
 Destroy the IOperation object.
virtual std::shared_ptr< IOperation< Types::time_type > > Remap (const std::unordered_map< Types::qubit_t, Types::qubit_t > &qubitsMap, const std::unordered_map< Types::qubit_t, Types::qubit_t > &bitsMap={}) const=0
 Get a shared pointer to a remapped operation.
virtual bool IsConditional () const
 Find if the operation is a conditional operation.
std::shared_ptr< IOperation< Types::time_type > > getptr ()
 Get a shared pointer to this object.
Types::time_type GetDelay () const
 Get the delay of the operation.
void SetDelay (Types::time_type d)
 Set the delay of the operation.

Additional Inherited Members

Static Public Member Functions inherited from Circuits::Circuit< Types::time_type >
static ExecuteResults RemapResultsBack (const ExecuteResults &results, const BitMapping &bitsMap={}, bool ignoreNotMapped=false, size_t sz=0)
 Map back the results for a remapped circuit.
static void AccumulateResults (ExecuteResults &results, const ExecuteResults &newResults)
 Accumulate the results of a circuit execution to already existing results.
static void AccumulateResultsWithRemapBack (ExecuteResults &results, const ExecuteResults &newResults, const BitMapping &bitsMap={}, bool ignoreNotMapped=true, size_t sz=0)
 Accumulate the results of a circuit execution to already existing results with remapping.

Detailed Description

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

Circuit class for holding the sequence of operations that can be compared with another circuit.

Contains a sequence of operations that can be executed, supplying a function that allows executing them in a simulator. Allows adding operations and converting them to prepare the circuit for distributed computing.

Template Parameters
TimeThe time type used for operation timing.
See also
Circuit
IOperation
ISimulator

Definition at line 2422 of file Circuit.h.

Member Typedef Documentation

◆ BaseClass

template<typename Time = Types::time_type>
using Circuits::ComparableCircuit< Time >::BaseClass = Circuit<Time>

The base class type.

Definition at line 2424 of file Circuit.h.

◆ Operation

template<typename Time = Types::time_type>
using Circuits::ComparableCircuit< Time >::Operation = IOperation<Time>

The operation type.

Definition at line 2425 of file Circuit.h.

◆ OperationPtr

template<typename Time = Types::time_type>
using Circuits::ComparableCircuit< Time >::OperationPtr = std::shared_ptr<Operation>

The shared pointer to the operation type.

Definition at line 2426 of file Circuit.h.

◆ OperationsVector

template<typename Time = Types::time_type>
using Circuits::ComparableCircuit< Time >::OperationsVector
Initial value:
std::vector<OperationPtr>

The vector of operations.

Definition at line 2428 of file Circuit.h.

Constructor & Destructor Documentation

◆ ComparableCircuit() [1/2]

template<typename Time = Types::time_type>
Circuits::ComparableCircuit< Time >::ComparableCircuit ( const OperationsVector & ops = {})
inline

Construct a new ComparableCircuit object.

Constructs a new ComparableCircuit object with the given operations.

Parameters
opsThe operations to add to the circuit.
See also
IOperation

Definition at line 2438 of file Circuit.h.

◆ ComparableCircuit() [2/2]

template<typename Time = Types::time_type>
Circuits::ComparableCircuit< Time >::ComparableCircuit ( const BaseClass & circ)
inline

Construct a new ComparableCircuit object.

Constructs a new ComparableCircuit object with the given Circuit.

Parameters
circuitThe circuit from where to add the operations to the comparable circuit.
See also
Circuit

Definition at line 2448 of file Circuit.h.

Member Function Documentation

◆ GetApproximateParamsCheck()

template<typename Time = Types::time_type>
bool Circuits::ComparableCircuit< Time >::GetApproximateParamsCheck ( ) const
inline

Gets whether to check approximate equality of gate parameters.

Gets whether to check approximate equality of gate parameters.

Returns
Whether to check approximate equality of gate parameters.

Definition at line 2611 of file Circuit.h.

◆ GetParamsEpsilon()

template<typename Time = Types::time_type>
double Circuits::ComparableCircuit< Time >::GetParamsEpsilon ( ) const
inline

Gets the epsilon used for checking approximate equality of gate parameters.

Gets the epsilon used for checking approximate equality of gate parameters.

Returns
The epsilon used for checking approximate equality of gate parameters.

Definition at line 2631 of file Circuit.h.

◆ operator!=()

template<typename Time = Types::time_type>
bool Circuits::ComparableCircuit< Time >::operator!= ( const BaseClass & rhs) const
inline

Comparison operator.

Compares two circuits for inequality.

Parameters
rhsThe circuit to compare to.

Definition at line 2595 of file Circuit.h.

◆ operator=()

template<typename Time = Types::time_type>
ComparableCircuit & Circuits::ComparableCircuit< Time >::operator= ( const BaseClass & circ)
inline

Assignment operator.

Assigns the operations from the given circuit to this circuit.

Parameters
circThe circuit from where to add the operations to this circuit.
Returns
A reference to this circuit.

Definition at line 2457 of file Circuit.h.

◆ operator==()

template<typename Time = Types::time_type>
bool Circuits::ComparableCircuit< Time >::operator== ( const BaseClass & rhs) const
inline

Comparison operator.

Compares two circuits for equality.

Parameters
rhsThe circuit to compare to.

Definition at line 2469 of file Circuit.h.

◆ SetApproximateParamsCheck()

template<typename Time = Types::time_type>
void Circuits::ComparableCircuit< Time >::SetApproximateParamsCheck ( bool check)
inline

Sets whether to check approximate equality of gate parameters.

Sets whether to check approximate equality of gate parameters.

Parameters
checkWhether to check approximate equality of gate parameters.

Definition at line 2603 of file Circuit.h.

◆ SetParamsEpsilon()

template<typename Time = Types::time_type>
void Circuits::ComparableCircuit< Time >::SetParamsEpsilon ( double eps)
inline

Sets the epsilon used for checking approximate equality of gate parameters.

Sets the epsilon used for checking approximate equality of gate parameters.

Parameters
epsThe epsilon used for checking approximate equality of gate parameters.

Definition at line 2621 of file Circuit.h.


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