Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
QuantumChannelOperation.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#ifndef _CIRCUIT_QUANTUM_CHANNEL_OPERATION_H_
10#define _CIRCUIT_QUANTUM_CHANNEL_OPERATION_H_
11
12#include <stdexcept>
13#include <unordered_set>
14
15#include "Operations.h"
16
17namespace Circuits
18{
19
21template <typename Time = Types::time_type> class QuantumChannelOperation : public IOperation<Time>
22{
23 public:
24 QuantumChannelOperation(const Types::qubits_vector &targets, const Simulators::QuantumChannel &channel, Time delay = 0)
25 : IOperation<Time>(delay), targets_(targets), channel_(channel)
26 {
27 if (targets_.size() != channel_.GetNumberOfQubits())
28 throw std::invalid_argument("The number of channel targets does not match its Kraus operators");
29 if (targets_.empty() || targets_.size() > 2)
30 throw std::invalid_argument("Maestro circuit channels support only one or two qubits");
31
32 std::unordered_set<Types::qubit_t> uniqueTargets;
33 for (const Types::qubit_t target : targets_)
34 if (!uniqueTargets.insert(target).second)
35 throw std::invalid_argument("Quantum-channel target qubits must be distinct");
36 }
37
38 void Execute(const std::shared_ptr<Simulators::ISimulator> &simulator, OperationState &state) const override
39 {
40 (void)state;
41 simulator->ApplyQuantumChannel(targets_, channel_);
42 }
43
44 OperationType GetType() const override
45 {
47 }
48
50 {
51 return targets_;
52 }
53
54 bool CanAffectQuantumState() const override
55 {
56 return true;
57 }
58
60 {
61 return targets_.size() > 1;
62 }
63
65 {
66 return channel_;
67 }
68
69 std::shared_ptr<IOperation<Time>> Clone() const override
70 {
71 return std::make_shared<QuantumChannelOperation<Time>>(targets_, channel_, IOperation<Time>::GetDelay());
72 }
73
74 std::shared_ptr<IOperation<Time>> Remap(const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
75 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {}) const override
76 {
77 (void)bitsMap;
78 Types::qubits_vector remappedTargets = targets_;
79 for (Types::qubit_t &target : remappedTargets)
80 {
81 const auto mapped = qubitsMap.find(target);
82 if (mapped != qubitsMap.end())
83 target = mapped->second;
84 }
85 return std::make_shared<QuantumChannelOperation<Time>>(remappedTargets, channel_, IOperation<Time>::GetDelay());
86 }
87
88 private:
89 Types::qubits_vector targets_;
90 Simulators::QuantumChannel channel_;
91};
92
93} // namespace Circuits
94
95#endif // _CIRCUIT_QUANTUM_CHANNEL_OPERATION_H_
Time GetDelay() const
Get the delay of the operation.
Definition Operations.h:546
IOperation(Types::time_type delay=0)
Definition Operations.h:410
The state class that stores the classical state of a quantum circuit execution.
Definition Operations.h:68
void Execute(const std::shared_ptr< Simulators::ISimulator > &simulator, OperationState &state) const override
Execute the operation.
bool CanAffectQuantumState() const override
Find if the operation can affect the quantum state.
OperationType GetType() const override
Get the type of the operation.
QuantumChannelOperation(const Types::qubits_vector &targets, const Simulators::QuantumChannel &channel, Time delay=0)
Types::qubits_vector AffectedQubits() const override
Returns the affected qubits.
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.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
bool NeedsEntanglementForDistribution() const override
Find if the operation needs entanglement for distribution.
const Simulators::QuantumChannel & GetChannel() const
A local completely-positive, trace-preserving map in Kraus form.
OperationType
The type of operations.
Definition Operations.h:29
@ kQuantumChannel
a non-unitary CPTP operation on the simulator state
Definition Operations.h:49
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.
Definition Types.h:24
uint_fast64_t qubit_t
The type of a qubit.
Definition Types.h:23