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 "Ops/Op.hpp" |
18 |
|
|
|
#include "Utils/Json.hpp" |
19 |
|
|
|
|
20 |
|
|
|
namespace tket { |
21 |
|
|
|
|
22 |
|
|
|
class SubstitutionFailure : public std::logic_error { |
23 |
|
|
|
public: |
24 |
|
|
✗ |
explicit SubstitutionFailure(const std::string &message) |
25 |
|
|
✗ |
: std::logic_error(message) {} |
26 |
|
|
|
}; |
27 |
|
|
|
|
28 |
|
|
|
class Gate : public Op { |
29 |
|
|
|
public: |
30 |
|
|
|
// return hermitian conjugate |
31 |
|
|
|
Op_ptr dagger() const override; |
32 |
|
|
|
|
33 |
|
|
|
// return transpose |
34 |
|
|
|
Op_ptr transpose() const override; |
35 |
|
|
|
|
36 |
|
|
|
Op_ptr symbol_substitution( |
37 |
|
|
|
const SymEngine::map_basic_basic &sub_map) const override; |
38 |
|
|
|
|
39 |
|
|
|
std::string get_name(bool latex = false) const override; |
40 |
|
|
|
|
41 |
|
|
|
std::string get_command_str(const unit_vector_t &args) const override; |
42 |
|
|
|
|
43 |
|
|
|
/** |
44 |
|
|
|
* Return the gate decomposition in terms of Rz(a)Rx(b)Rz(c). |
45 |
|
|
|
* |
46 |
|
|
|
* This decomposition is in matrix-multiplication order, i.e. the reverse of |
47 |
|
|
|
* circuit order. |
48 |
|
|
|
* |
49 |
|
|
|
* @return a, b, c and a global phase |
50 |
|
|
|
*/ |
51 |
|
|
|
std::vector<Expr> get_tk1_angles() const; |
52 |
|
|
|
std::vector<Expr> get_params() const override; |
53 |
|
|
|
std::vector<Expr> get_params_reduced() const override; |
54 |
|
|
|
SymSet free_symbols() const override; |
55 |
|
|
|
|
56 |
|
|
|
unsigned n_qubits() const override; |
57 |
|
|
|
|
58 |
|
|
|
std::optional<Pauli> commuting_basis(unsigned i) const override; |
59 |
|
|
|
|
60 |
|
|
|
bool commutes_with_basis( |
61 |
|
|
|
const std::optional<Pauli> &colour, unsigned i) const override; |
62 |
|
|
|
|
63 |
|
|
|
op_signature_t get_signature() const override; |
64 |
|
|
|
|
65 |
|
|
|
nlohmann::json serialize() const override; |
66 |
|
|
|
|
67 |
|
|
|
static Op_ptr deserialize(const nlohmann::json &j); |
68 |
|
|
|
|
69 |
|
|
|
std::optional<double> is_identity() const override; |
70 |
|
|
|
bool is_clifford() const override; |
71 |
|
|
|
Eigen::MatrixXcd get_unitary() const override; |
72 |
|
|
|
|
73 |
|
|
✗ |
~Gate() override {} |
74 |
|
|
|
|
75 |
|
|
|
/** |
76 |
|
|
|
* Equality check between two Gate instances |
77 |
|
|
|
*/ |
78 |
|
|
|
bool is_equal(const Op &other) const override; |
79 |
|
|
|
|
80 |
|
|
|
Gate( |
81 |
|
|
|
OpType type, const std::vector<Expr> ¶ms = {}, unsigned n_qubits = 0); |
82 |
|
|
|
|
83 |
|
|
|
Gate(); |
84 |
|
|
|
|
85 |
|
|
|
private: |
86 |
|
|
|
// vector of symbolic params |
87 |
|
|
|
const std::vector<Expr> params_; |
88 |
|
|
|
unsigned n_qubits_; /**< Number of qubits, when not deducible from type */ |
89 |
|
|
|
}; |
90 |
|
|
|
|
91 |
|
|
|
} // namespace tket |
92 |
|
|
|
|