tket
Loading...
Searching...
No Matches
Op.cpp
Go to the documentation of this file.
1// Copyright Quantinuum
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#include "tket/Ops/Op.hpp"
16
17#include <sstream>
18
19#include "tket/Ops/OpPtr.hpp"
20
21namespace tket {
22
23std::string Op::get_name(bool latex) const {
24 if (latex) {
25 return get_desc().latex();
26 } else {
27 return get_desc().name();
28 }
29}
30
31std::string Op::get_command_str(const unit_vector_t& args) const {
32 std::stringstream out;
33 out << get_name();
34 if (!args.empty()) {
35 out << " " << args[0].repr();
36 for (unsigned i = 1; i < args.size(); i++) {
37 out << ", " << args[i].repr();
38 }
39 }
40 out << ";";
41 return out.str();
42}
43
44std::ostream& operator<<(std::ostream& os, Op const& operation) {
45 return os << operation.get_name();
46}
47
48void to_json(nlohmann::json& j, const Op_ptr& op) { j = op->serialize(); }
49
50} // namespace tket
Operations.
std::string name() const
Name.
Definition OpDesc.cpp:40
std::string latex() const
Name in Latex representation.
Definition OpDesc.cpp:42
Abstract class representing an operation type.
Definition Op.hpp:53
virtual std::string get_name(bool latex=false) const
String representation.
Definition Op.cpp:23
OpDesc get_desc() const
Get operation descriptor.
Definition Op.hpp:96
virtual std::string get_command_str(const unit_vector_t &args) const
Command representation.
Definition Op.cpp:31
Defines tket::DeviceCharacterisation, used in NoiseAwarePlacement and in commute_SQ_gates_through_SWA...
Definition Path.cpp:22
std::ostream & operator<<(std::ostream &out, const Circuit &circ)
std::shared_ptr< const Op > Op_ptr
Definition OpPtr.hpp:24
std::vector< UnitID > unit_vector_t
Definition UnitID.hpp:311
void to_json(nlohmann::json &j, const Architecture::Connection &link)