Skip to content

Commit

Permalink
Revert "Add debug info"
Browse files Browse the repository at this point in the history
This reverts commit e5030e2.
  • Loading branch information
yao-cqc committed Oct 16, 2024
1 parent e5030e2 commit 65ee40b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 151 deletions.
14 changes: 0 additions & 14 deletions tket/include/tket/Transformations/GreedyPauliOptimisation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand All @@ -107,7 +106,6 @@ struct Rotation2Q {
Expr angle;
unsigned index;
bool operator<(const Rotation2Q& other) const { return index < other.index; }
std::string repr() const;
};

/**
Expand All @@ -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<TQE> reduction_tqes() const = 0;
virtual std::string repr() const = 0;
virtual ~PauliNode();
};

Expand Down Expand Up @@ -307,8 +304,6 @@ class ClassicalNode : public PauliNode {

CommuteInfo get_commute_info() const override;

std::string repr() const override;

protected:
const std::vector<UnitID> args_;
const Op_ptr op_;
Expand Down Expand Up @@ -337,8 +332,6 @@ class PauliRotation : public SingleNode {

CommuteInfo get_commute_info() const override;

std::string repr() const override;

protected:
const Expr theta_;
};
Expand All @@ -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_;
};
Expand Down Expand Up @@ -424,8 +415,6 @@ class ConditionalBlock : public PauliNode {
return rotations_;
};

std::string repr() const override;

protected:
std::vector<std::tuple<std::vector<Pauli>, bool, Expr>> rotations_;
const std::vector<unsigned> cond_bits_;
Expand Down Expand Up @@ -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_;
};
Expand Down Expand Up @@ -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<
Expand Down
99 changes: 0 additions & 99 deletions tket/src/Transformations/GreedyPauliOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pauli>& 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<Pauli>& zvec, const std::vector<Pauli>& 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) {
Expand Down Expand Up @@ -382,13 +306,6 @@ PauliRotation::PauliRotation(std::vector<Pauli> 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<std::tuple<std::vector<Pauli>, bool, Expr>> rotations,
std::vector<unsigned> cond_bits, unsigned cond_value)
Expand Down Expand Up @@ -457,8 +374,6 @@ void ConditionalBlock::append(const ConditionalBlock& other) {
}
}

std::string ConditionalBlock::repr() const { return "ConditionalBlock []"; }

// PauliPropagation
PauliPropagation::PauliPropagation(
std::vector<Pauli> z_string, std::vector<Pauli> x_string, bool z_sign,
Expand All @@ -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<UnitID> args, Op_ptr op)
: args_(args), op_(op) {}
Expand All @@ -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<Pauli> string, bool sign, unsigned bit)
: SingleNode(string, sign), bit_(bit) {}
Expand All @@ -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<Pauli> z_string, std::vector<Pauli> x_string, bool z_sign,
Expand All @@ -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
Expand Down
40 changes: 2 additions & 38 deletions tket/src/Transformations/GreedyPauliOptimisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PauliNode_ptr>& 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;
Expand Down Expand Up @@ -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<PauliNode_ptr>& 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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 65ee40b

Please sign in to comment.