Line |
Branch |
Decision |
Exec |
Source |
1 |
|
|
|
// Copyright 2019-2022 Cambridge Quantum Computing |
2 |
|
|
|
// |
3 |
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
|
|
|
// you may not use this file except in compliance with the License. |
5 |
|
|
|
// You may obtain a copy of the License at |
6 |
|
|
|
// |
7 |
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0 |
8 |
|
|
|
// |
9 |
|
|
|
// Unless required by applicable law or agreed to in writing, software |
10 |
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS, |
11 |
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
|
|
|
// See the License for the specific language governing permissions and |
13 |
|
|
|
// limitations under the License. |
14 |
|
|
|
|
15 |
|
|
|
#pragma once |
16 |
|
|
|
|
17 |
|
|
|
#include <memory> |
18 |
|
|
|
|
19 |
|
|
|
#include "Predicates.hpp" |
20 |
|
|
|
|
21 |
|
|
|
namespace tket { |
22 |
|
|
|
|
23 |
|
|
|
class CompilationUnit; |
24 |
|
|
|
typedef std::map<std::type_index, PredicatePtr> |
25 |
|
|
|
PredicatePtrMap; // this is map so i can look up by type later |
26 |
|
|
|
typedef std::pair<const std::type_index, PredicatePtr> TypePredicatePair; |
27 |
|
|
|
typedef std::map<std::type_index, std::pair<PredicatePtr, bool>> PredicateCache; |
28 |
|
|
|
|
29 |
|
|
|
/* The CompilationUnit class encapsulates a Circuit and a PredicatePtrMap of the |
30 |
|
|
|
Predicates that Circuit is intended to satisfy by the end of its run through |
31 |
|
|
|
the compiler. It holdes a cache of Predicates |
32 |
|
|
|
which are currently satisfied. */ |
33 |
|
|
|
|
34 |
|
|
|
class CompilationUnit { |
35 |
|
|
|
public: |
36 |
|
|
|
explicit CompilationUnit(const Circuit& circ); |
37 |
|
|
|
CompilationUnit(const Circuit& circ, const PredicatePtrMap& preds); |
38 |
|
|
|
CompilationUnit(const Circuit& circ, const std::vector<PredicatePtr>& preds); |
39 |
|
|
|
|
40 |
|
|
|
bool calc_predicate(const Predicate& pred) const; |
41 |
|
|
|
bool check_all_predicates() |
42 |
|
|
|
const; // returns false if any of the preds are unsatisfied |
43 |
|
|
|
|
44 |
|
|
|
/* getters to inspect the data members */ |
45 |
|
|
✗ |
const Circuit& get_circ_ref() const { return circ_; } |
46 |
|
|
|
const PredicateCache& get_cache_ref() const { return cache_; } |
47 |
|
|
|
const unit_bimap_t& get_initial_map_ref() const { return maps->initial; } |
48 |
|
|
|
const unit_bimap_t& get_final_map_ref() const { return maps->final; } |
49 |
|
|
|
std::string to_string() const; |
50 |
|
|
|
|
51 |
|
|
|
friend class Circuit; |
52 |
|
|
|
friend class BasePass; |
53 |
|
|
|
friend class StandardPass; |
54 |
|
|
|
|
55 |
|
|
|
static TypePredicatePair make_type_pair(const PredicatePtr& ptr); |
56 |
|
|
|
|
57 |
|
|
|
private: |
58 |
|
|
|
void empty_cache() const; |
59 |
|
|
|
void initialize_cache() const; |
60 |
|
|
|
void initialize_maps(); |
61 |
|
|
|
Circuit circ_; // modified continuously |
62 |
|
|
|
PredicatePtrMap |
63 |
|
|
|
target_preds; // these are the predicates you WANT your circuit to |
64 |
|
|
|
// satisfy by the end of your Compiler Passes |
65 |
|
|
|
mutable PredicateCache cache_; // updated continuously |
66 |
|
|
|
|
67 |
|
|
|
// Maps from original logical qubits to corresponding current qubits |
68 |
|
|
|
std::shared_ptr<unit_bimaps_t> maps; |
69 |
|
|
|
}; |
70 |
|
|
|
|
71 |
|
|
|
} // namespace tket |
72 |
|
|
|
|