|
Maestro 0.1.0
Unified interface for quantum circuit simulation
|
Circuit class for holding the sequence of operations. More...
#include <Circuit.h>
Public Types | |
| using | ExecuteResults |
| The results of the execution of the circuit. | |
| using | BitMapping |
| The (qu)bit mapping for remapping. | |
| 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. | |
| using | value_type = typename OperationsVector::value_type |
| using | allocator_type = typename OperationsVector::allocator_type |
| using | pointer = typename OperationsVector::pointer |
| using | const_pointer = typename OperationsVector::const_pointer |
| using | reference = typename OperationsVector::reference |
| using | const_reference = typename OperationsVector::const_reference |
| using | size_type = typename OperationsVector::size_type |
| using | difference_type = typename OperationsVector::difference_type |
| using | iterator = typename OperationsVector::iterator |
| using | const_iterator = typename OperationsVector::const_iterator |
| using | reverse_iterator = typename OperationsVector::reverse_iterator |
| using | const_reverse_iterator |
Public Member Functions | |
| 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< Time > > &circuit) |
| Adds operations from another circuit to the circuit. | |
| const OperationsVector & | GetOperations () 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< Time > > | 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, OperationPtr > | GetLastOperationsOnQubits () const |
| Returns the last operations on circuit's qubits. | |
| std::unordered_map< size_t, OperationPtr > | GetFirstOperationsOnQubits () const |
| Returns the first operations on circuit's qubits. | |
| void | AddResetsIfNeeded (Time delay=0) |
| Add resets at the end of the circuit. | |
| void | AddResetsAtBeginningIfNeeded (Time 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< Time > > | GetDepth () const |
| Get circuit depth. | |
| std::pair< size_t, Time > | GetMaxDepth () 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< Time > > | 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< Time > > | 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_t > | GetCliffordQubits () const |
| Get the qubits that are acted on by Clifford operations. | |
| std::vector< std::shared_ptr< Circuit< Time > > > | 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. | |
| const auto & | operator[] (size_t pos) const |
| 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. | |
Static Public Member Functions | |
| 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. | |
Circuit class for holding the sequence of operations.
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.
| Time | The time type used for operation timing. |
| using Circuits::Circuit< Time >::allocator_type = typename OperationsVector::allocator_type |
| using Circuits::Circuit< Time >::BitMapping |
The (qu)bit mapping for remapping.
| using Circuits::Circuit< Time >::const_iterator = typename OperationsVector::const_iterator |
| using Circuits::Circuit< Time >::const_pointer = typename OperationsVector::const_pointer |
| using Circuits::Circuit< Time >::const_reference = typename OperationsVector::const_reference |
| using Circuits::Circuit< Time >::const_reverse_iterator |
| using Circuits::Circuit< Time >::difference_type = typename OperationsVector::difference_type |
| using Circuits::Circuit< Time >::ExecuteResults |
| using Circuits::Circuit< Time >::iterator = typename OperationsVector::iterator |
| using Circuits::Circuit< Time >::Operation = IOperation<Time> |
| using Circuits::Circuit< Time >::OperationPtr = std::shared_ptr<Operation> |
| using Circuits::Circuit< Time >::OperationsVector |
| using Circuits::Circuit< Time >::pointer = typename OperationsVector::pointer |
| using Circuits::Circuit< Time >::reference = typename OperationsVector::reference |
| using Circuits::Circuit< Time >::reverse_iterator = typename OperationsVector::reverse_iterator |
| using Circuits::Circuit< Time >::size_type = typename OperationsVector::size_type |
| using Circuits::Circuit< Time >::value_type = typename OperationsVector::value_type |
|
inline |
Construct a new Circuit object.
Constructs a new Circuit object with the given operations.
| ops | The operations to add to the circuit. |
|
inlinestatic |
Accumulate the results of a circuit execution to already existing results.
Accumulates the results of a circuit execution to already existing results.
| results | The existing results to accumulate to. |
| newResults | The new results to add to the existing results. |
|
inlinestatic |
Accumulate the results of a circuit execution to already existing results with remapping.
Accumulates the results of a circuit execution to already existing results with remapping back.
| results | The existing results to accumulate to. |
| newResults | The new results to add to the existing results. |
| bitsMap | The map of classical bits to remap. |
| ignoreNotMapped | If true, the results that are not in the map will be ignored. |
| sz | The size of the results vector. |
|
inline |
Checks if the circuit has only operations that act on adjacent qubits.
Checks if the circuit has only operations that act on adjacent qubits. Can be useful in picking up a tensor network contractor, for example. Also such a circuit is easier to simulate in a MPS simulator, since swap gates are not needed to be added to bring up the qubits next to each other before applying a two qubits gate.
|
inline |
|
inline |
Adds an operation to the circuit.
Adds an operation to the circuit.
| op | The operation to add. |
|
inline |
Adds operations to the circuit.
Adds operations to the circuit.
| ops | The operations to add. |
|
inline |
|
inline |
|
inlineoverridevirtual |
Returns the affected bits.
Returns the affected classical bits.
Reimplemented from Circuits::IOperation< Types::time_type >.
|
inlineoverridevirtual |
Returns the affected qubits.
Returns the affected qubits by the operation.
Reimplemented from Circuits::IOperation< Types::time_type >.
|
inlinenoexcept |
|
inlineoverridevirtual |
Find if the circuit can affect the quantum state.
Returns true if the circuit can affect the quantum state, false otherwise.
Reimplemented from Circuits::IOperation< Types::time_type >.
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
Get the percentage of Clifford operations in the circuit.
Returns the percentage of Clifford operations in the circuit. Considers gates as Clifford if they are supported by the Clifford simulator.
|
inlineoverridevirtual |
Get a shared pointer to a clone of this object.
Returns a shared pointer to a copy of this object.
Implements Circuits::IOperation< Types::time_type >.
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inline |
|
inlineoverridevirtual |
Execute the circuit on the given simulator.
Executes the circuit on the given simulator.
| sim | The simulator to execute the circuit on. |
| state | The classical state containing the classical bits. |
Implements Circuits::IOperation< Types::time_type >.
|
inline |
Execute the measurement operations from the circuit on the given simulator.
Execute the measurements operations from the circuit on the given simulator.
| sim | The simulator to execute the circuit on. |
| state | The classical state containing the classical bits. |
|
inline |
Execute the non-measurements operations from the circuit on the given simulator.
Execute the non-measurements operations from the circuit on the given simulator.
| sim | The simulator to execute the circuit on. |
| state | The classical state containing the classical bits. |
|
inline |
|
inline |
Get the circuit cut.
Cuts out a circuit from the current circuit, starting from the startQubit and ending at the endQubit. Throws an exception if there is an operation that affects both qubits inside and outside of the specified interval. The returned circuit contains only operations that act on the qubits in the specified interval.
| startQubit | The start qubit of the interval. |
| endQubit | The end qubit of the interval. |
|
inline |
Get the qubits that are acted on by Clifford operations.
Returns the qubits that are acted on only by Clifford operations. Considers gates as Clifford if they are supported by the Clifford simulator.
|
inline |
Get circuit depth.
Returns the depth of the circuit as a pair of the depth and an estimate of time cost for each qubit. Should be considered only as an estimate.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Get the operations in the circuit.
Returns the operations in the circuit.
|
inline |
Returns the qubits affected by the operations.
Returns the qubits affected by the operations. They might not cover all qubits, there might be gaps. In such cases a remapping might be needed, for example in a scheduler.
|
inlineoverridevirtual |
Get the type of the circuit.
Returns the type of the circuit.
Reimplemented from Circuits::IOperation< Types::time_type >.
|
inline |
|
inline |
Checks if the circuit has measurements that are followed by operations that affect the measured qubits.
Checks if the circuit has measurements that are followed by operations that affect the measured qubits.
|
inlineoverridevirtual |
Checks if the circuit is a Clifford circuit.
Checks if the circuit is a Clifford circuit. Considers gates as Clifford if they are supported by the Clifford simulator.
Reimplemented from Circuits::IOperation< Types::time_type >.
|
inline |
|
inline |
|
inlineoverridevirtual |
Find if the circuit needs entanglement for distribution.
Returns true if the circuit needs entanglement for distribution, false otherwise.
Reimplemented from Circuits::IOperation< Types::time_type >.
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlineoverride |
Get a shared pointer to a circuit remapped.
Returns a shared pointer to a copy of the circuit with qubits and classical bits changed according to the provided maps.
| qubitsMap | The map of qubits to remap. |
| bitsMap | The map of classical bits to remap. |
|
inlinestatic |
Map back the results for a remapped circuit.
Maps back the results for a remapped circuit, using the provided map. The results are the results of the execution of the circuit without remapping.
| results | The results to map back. |
| bitsMap | The map of classical bits to remap. |
| ignoreNotMapped | If true, the results that are not in the map will be ignored. |
| sz | The size of the results vector. |
|
inline |
Get a shared pointer to a circuit remapped to a continuous interval starting from zero.
Returns a shared pointer to a copy of the circuit with qubits and classical bits changed according to the provided maps.
| bitsMap | The map of classical bits, to allow remapping the results back to the original circuit results. |
|
inlinenoexcept |
|
inline |
Replaces an operation in the circuit.
Replaces an operation in the circuit.
| index | The index of the operation to replace. |
| op | The operation to replace with. |
|
inline |
|
inline |
Set the operations in the circuit.
Sets the operations in the circuit.
| ops | The operations to set. |
|
inline |
|
inline |