Maestro 0.3.1
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
20template <typename Time = Types::time_type>
21class QuantumChannelOperation : public IOperation<Time> {
22 public:
24 const Simulators::QuantumChannel& channel,
25 Time delay = 0)
26 : IOperation<Time>(delay), targets_(targets), channel_(channel) {
27 if (targets_.size() != channel_.GetNumberOfQubits())
28 throw std::invalid_argument(
29 "The number of channel targets does not match its Kraus operators");
30 if (targets_.empty() || targets_.size() > 2)
31 throw std::invalid_argument(
32 "Maestro circuit channels support only one or two qubits");
33
34 std::unordered_set<Types::qubit_t> uniqueTargets;
35 for (const Types::qubit_t target : targets_)
36 if (!uniqueTargets.insert(target).second)
37 throw std::invalid_argument(
38 "Quantum-channel target qubits must be distinct");
39 }
40
41 void Execute(const std::shared_ptr<Simulators::ISimulator>& simulator,
42 OperationState& state) const override {
43 (void)state;
44 simulator->ApplyQuantumChannel(targets_, channel_);
45 }
46
47 OperationType GetType() const override {
49 }
50
51 Types::qubits_vector AffectedQubits() const override { return targets_; }
52
53 bool CanAffectQuantumState() const override { return true; }
54
55 bool NeedsEntanglementForDistribution() const override {
56 return targets_.size() > 1;
57 }
58
59 const Simulators::QuantumChannel& GetChannel() const { return channel_; }
60
61 std::shared_ptr<IOperation<Time>> Clone() const override {
62 return std::make_shared<QuantumChannelOperation<Time>>(
63 targets_, channel_, IOperation<Time>::GetDelay());
64 }
65
66 std::shared_ptr<IOperation<Time>> Remap(
67 const std::unordered_map<Types::qubit_t, Types::qubit_t>& qubitsMap,
68 const std::unordered_map<Types::qubit_t, Types::qubit_t>& bitsMap = {})
69 const override {
70 (void)bitsMap;
71 Types::qubits_vector remappedTargets = targets_;
72 for (Types::qubit_t& target : remappedTargets) {
73 const auto mapped = qubitsMap.find(target);
74 if (mapped != qubitsMap.end()) target = mapped->second;
75 }
76 return std::make_shared<QuantumChannelOperation<Time>>(
77 remappedTargets, channel_, IOperation<Time>::GetDelay());
78 }
79
80 private:
81 Types::qubits_vector targets_;
82 Simulators::QuantumChannel channel_;
83};
84
85} // namespace Circuits
86
87#endif // _CIRCUIT_QUANTUM_CHANNEL_OPERATION_H_
Time GetDelay() const
Get the delay of the operation.
Definition Operations.h:501
IOperation(Types::time_type delay=0)
Definition Operations.h:368
The state class that stores the classical state of a quantum circuit execution.
Definition Operations.h:65
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:27
@ kQuantumChannel
a non-unitary CPTP operation on the simulator state
Definition Operations.h:47
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.
Definition Types.h:22
uint_fast64_t qubit_t
The type of a qubit.
Definition Types.h:21