diff --git a/tket/include/tket/Transformations/GreedyPauliOptimisation.hpp b/tket/include/tket/Transformations/GreedyPauliOptimisation.hpp index a1ab387619..de6bb19d5c 100644 --- a/tket/include/tket/Transformations/GreedyPauliOptimisation.hpp +++ b/tket/include/tket/Transformations/GreedyPauliOptimisation.hpp @@ -92,7 +92,6 @@ struct TQE { bool operator<(const TQE& other) const { return std::tie(type, a, b) < std::tie(other.type, other.a, other.b); } - std::string repr() const; }; /** @@ -107,7 +106,6 @@ struct Rotation2Q { Expr angle; unsigned index; bool operator<(const Rotation2Q& other) const { return index < other.index; } - std::string repr() const; }; /** @@ -134,7 +132,6 @@ class PauliNode { virtual void swap(const unsigned& a, const unsigned& b); virtual CommuteInfo get_commute_info() const = 0; virtual std::vector reduction_tqes() const = 0; - virtual std::string repr() const = 0; virtual ~PauliNode(); }; @@ -307,8 +304,6 @@ class ClassicalNode : public PauliNode { CommuteInfo get_commute_info() const override; - std::string repr() const override; - protected: const std::vector args_; const Op_ptr op_; @@ -337,8 +332,6 @@ class PauliRotation : public SingleNode { CommuteInfo get_commute_info() const override; - std::string repr() const override; - protected: const Expr theta_; }; @@ -361,8 +354,6 @@ class MidMeasure : public SingleNode { CommuteInfo get_commute_info() const override; unsigned bit() const { return bit_; }; - std::string repr() const override; - protected: const unsigned bit_; }; @@ -424,8 +415,6 @@ class ConditionalBlock : public PauliNode { return rotations_; }; - std::string repr() const override; - protected: std::vector, bool, Expr>> rotations_; const std::vector cond_bits_; @@ -464,8 +453,6 @@ class PauliPropagation : public ACPairNode { unsigned qubit_index() const { return qubit_index_; }; - std::string repr() const override; - private: const unsigned qubit_index_; }; @@ -493,7 +480,6 @@ class Reset : public ACPairNode { PauliNodeType get_type() const override { return PauliNodeType::Reset; }; CommuteInfo get_commute_info() const override; - std::string repr() const override; }; typedef boost::adjacency_list< diff --git a/tket/src/Transformations/GreedyPauliOps.cpp b/tket/src/Transformations/GreedyPauliOps.cpp index 84884848a3..3e0af85795 100644 --- a/tket/src/Transformations/GreedyPauliOps.cpp +++ b/tket/src/Transformations/GreedyPauliOps.cpp @@ -26,82 +26,6 @@ namespace Transforms { namespace GreedyPauliSimp { -static std::string pauli_str(const Pauli& p) { - switch (p) { - case Pauli::I: - return "I"; - case Pauli::Z: - return "Z"; - case Pauli::X: - return "X"; - case Pauli::Y: - return "Y"; - } -} - -static std::string pauli_vec_str(const std::vector& pvec) { - std::string s; - for (unsigned i = 0; i < pvec.size(); i++) { - s += pauli_str(pvec[i]); - if (i != pvec.size() - 1) s += "-"; - } - return s; -} - -static std::string pauli_pair_str( - const std::vector& zvec, const std::vector& xvec) { - std::string s; - for (unsigned i = 0; i < zvec.size(); i++) { - s += pauli_str(zvec[i]); - s += "|"; - s += pauli_str(xvec[i]); - if (i != zvec.size() - 1) s += "-"; - } - return s; -} - -std::string TQE::repr() const { - std::stringstream ss; - ss << "TQE ["; - switch (type) { - case TQEType::XX: - ss << "XX"; - break; - case TQEType::XY: - ss << "XY"; - break; - case TQEType::XZ: - ss << "XZ"; - break; - case TQEType::YX: - ss << "YX"; - break; - case TQEType::YY: - ss << "YY"; - break; - case TQEType::YZ: - ss << "YZ"; - break; - case TQEType::ZX: - ss << "ZX"; - break; - case TQEType::ZY: - ss << "ZY"; - break; - case TQEType::ZZ: - ss << "ZZ"; - } - ss << " " << a << " " << b << "]"; - return ss.str(); -} - -std::string Rotation2Q::repr() const { - std::stringstream ss; - ss << "Rotation2Q [" << pauli_str(p_a) << pauli_str(p_b) << angle << " " << a - << " " << b << "]"; - return ss.str(); -} - static CommuteType get_pauli_pair_commute_type( const Pauli& p0, const Pauli& p1) { if (p0 == Pauli::I && p1 == Pauli::I) { @@ -382,13 +306,6 @@ PauliRotation::PauliRotation(std::vector string, bool sign, Expr theta) CommuteInfo PauliRotation::get_commute_info() const { return {{string_}, {}}; } -std::string PauliRotation::repr() const { - std::stringstream ss; - ss << "PauliRotation [" << pauli_vec_str(string_) << "," << this->angle() - << "]"; - return ss.str(); -} - ConditionalBlock::ConditionalBlock( std::vector, bool, Expr>> rotations, std::vector cond_bits, unsigned cond_value) @@ -457,8 +374,6 @@ void ConditionalBlock::append(const ConditionalBlock& other) { } } -std::string ConditionalBlock::repr() const { return "ConditionalBlock []"; } - // PauliPropagation PauliPropagation::PauliPropagation( std::vector z_string, std::vector x_string, bool z_sign, @@ -470,10 +385,6 @@ CommuteInfo PauliPropagation::get_commute_info() const { return {{z_string_, x_string_}, {}}; } -std::string PauliPropagation::repr() const { - return "PauliPropagation [" + pauli_pair_str(z_string_, x_string_) + "]"; -} - // ClassicalNode ClassicalNode::ClassicalNode(std::vector args, Op_ptr op) : args_(args), op_(op) {} @@ -486,8 +397,6 @@ CommuteInfo ClassicalNode::get_commute_info() const { return {{}, bits_info}; } -std::string ClassicalNode::repr() const { return "Classical []"; } - // MidMeasure MidMeasure::MidMeasure(std::vector string, bool sign, unsigned bit) : SingleNode(string, sign), bit_(bit) {} @@ -496,10 +405,6 @@ CommuteInfo MidMeasure::get_commute_info() const { return {{string_}, {{Bit(bit_), BitType::WRITE}}}; } -std::string MidMeasure::repr() const { - return "MidMeasure [" + pauli_vec_str(string_) + "]"; -} - // Reset Reset::Reset( std::vector z_string, std::vector x_string, bool z_sign, @@ -510,10 +415,6 @@ CommuteInfo Reset::get_commute_info() const { return {{z_string_, x_string_}, {}}; } -std::string Reset::repr() const { - return "Reset [" + pauli_pair_str(z_string_, x_string_) + "]"; -} - } // namespace GreedyPauliSimp } // namespace Transforms diff --git a/tket/src/Transformations/GreedyPauliOptimisation.cpp b/tket/src/Transformations/GreedyPauliOptimisation.cpp index c357f049c0..2ec1627241 100644 --- a/tket/src/Transformations/GreedyPauliOptimisation.cpp +++ b/tket/src/Transformations/GreedyPauliOptimisation.cpp @@ -148,21 +148,16 @@ static double default_pauliexp_tqe_cost( double exp_cost = 0; double tab_cost = 0; unsigned count = 0; - std::cout << "cost tqe " << tqe.repr() << ":\n"; for (const std::vector& rotation_set : rotation_sets) { for (const PauliNode_ptr& node : rotation_set) { - int cost = node->tqe_cost_increase(tqe); - exp_cost += weight * cost; - std::cout << node->repr() << " " << weight << " " << cost << "\n"; + exp_cost += weight * node->tqe_cost_increase(tqe); if (++count >= max_lookahead) break; } if (count >= max_lookahead) break; weight *= discount; } for (const PauliNode_ptr& node : rows) { - int cost = node->tqe_cost_increase(tqe); - tab_cost += weight * cost; - std::cout << node->repr() << " " << weight << " " << cost << "\n"; + tab_cost += weight * node->tqe_cost_increase(tqe); if (++count >= max_lookahead) break; } return exp_cost + tab_cost; @@ -609,14 +604,6 @@ static void pauli_exps_synthesis( DepthTracker& depth_tracker, double discount_rate, double depth_weight, unsigned max_lookahead, unsigned max_tqe_candidates, unsigned seed, bool allow_zzphase) { - std::cout << "Initial nodes:\n"; - for (const std::vector& set : rotation_sets) { - std::cout << "{"; - for (const PauliNode_ptr& node : set) { - std::cout << node->repr() << ","; - } - std::cout << "}\n"; - } while (true) { consume_nodes( rotation_sets, circ, depth_tracker, discount_rate, depth_weight); @@ -680,32 +667,10 @@ static void pauli_exps_synthesis( } } // select the best one - std::cout << "first set nodes :\n"; - for (const PauliNode_ptr& node : first_set) { - std::cout << node->repr() << "\n"; - } - std::cout << "tableau rows :\n"; - for (const PauliNode_ptr& node : rows) { - std::cout << node->repr() << "\n"; - } - std::cout << "tqe candidates :\n"; - for (auto it = tqe_candidates_cost.begin(); it != tqe_candidates_cost.end(); - it++) { - std::cout << it->first.repr() << " " << it->second[0] << " " - << it->second[1] << "\n"; - } - std::cout << "rot2q candidates :\n"; - for (auto it = rot2q_gates_cost.begin(); it != rot2q_gates_cost.end(); - it++) { - std::cout << it->first.repr() << " " << it->second[0] << " " - << it->second[1] << "\n"; - } - auto [min_tqes, min_rot2qs] = minmax_selection( tqe_candidates_cost, rot2q_gates_cost, {1, depth_weight}); if (min_rot2qs.empty()) { TQE selected_tqe = sample_random_tqe(min_tqes, seed); - std::cout << "Apply " << selected_tqe.repr() << "\n"; // apply TQE apply_tqe_to_circ(selected_tqe, circ); depth_tracker.add_2q_gate(selected_tqe.a, selected_tqe.b); @@ -725,7 +690,6 @@ static void pauli_exps_synthesis( return r1.index > r2.index; }); for (const Rotation2Q& rot : min_rot2qs) { - std::cout << "Apply " << rot.repr() << "\n"; apply_rot2q_to_circ(rot, circ); first_set.erase(first_set.begin() + rot.index); }