Skip to content

Commit

Permalink
Merge pull request #292 from CQCL/release/1.0.1
Browse files Browse the repository at this point in the history
Release/1.0.1
  • Loading branch information
cqc-alec authored Mar 15, 2022
2 parents ea97df1 + e1bf256 commit 9370d6b
Show file tree
Hide file tree
Showing 29 changed files with 96 additions and 1,840 deletions.
1 change: 0 additions & 1 deletion pytket/binders/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ PYBIND11_MODULE(transform, m) {
"Rebase from any gate set into the gate set supported by "
"ProjectQ (Rx, Ry, Rz, X, Y, Z, S, T, V, H, CX, CZ, CRz, "
"SWAP).")
//.def_static("RebaseToMaryland", &Transforms::rebase_UMD)
.def_static(
"DecomposeCCX", &Transforms::decomp_CCX,
"Decomposes all 3-qubit Toffoli (CCX) gates into "
Expand Down
7 changes: 7 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

1.0.1 (March 2022)
------------------

Fixes:

* Fix problem with unassigned ancilla qubits during mapping.

1.0.0 (March 2022)
------------------

Expand Down
2 changes: 1 addition & 1 deletion pytket/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# The short X.Y version
version = "1.0"
# The full version, including alpha/beta/rc tags
release = "1.0.0"
release = "1.0.1"


# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions tket/proptests/proptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ using namespace tket;
DO(DecomposeBoxes) \
DO(ComposePhasePolyBoxes) \
DO(SquashTK1) \
DO(RebaseCirq) \
DO(RebaseTket) \
DO(RebaseQuil) \
DO(RebasePyZX) \
DO(RebaseProjectQ) \
DO(DecomposeBridges) \
DO(FlattenRegisters) \
DO(RemoveBarriers) \
Expand Down
35 changes: 0 additions & 35 deletions tket/src/ArchAwareSynth/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,41 +228,6 @@ IterationOrder::IterationOrder(const Architecture &arch) {
std::reverse(iterationorder.begin(), iterationorder.end());
}

std::ostream &operator<<(std::ostream &out, const PathHandler &path) {
out << "\nprint the details of a pathhandler: \n";
out << "size: " << path.get_size() << "\n";
out << "connectivity_matrix_:\n ";

for (unsigned i = 0; i != path.get_size(); ++i) {
for (unsigned j = 0; j != path.get_size(); ++j) {
out << path.get_connectivity_matrix()(i, j) << ", ";
}
out << std::endl;
}
out << std::endl;

out << "distance_matrix_:\n ";

for (unsigned i = 0; i != path.get_size(); ++i) {
for (unsigned j = 0; j != path.get_size(); ++j) {
out << path.get_distance_matrix()(i, j) << ", ";
}
out << std::endl;
}
out << std::endl;

out << "path_matrix_:\n ";

for (unsigned i = 0; i != path.get_size(); ++i) {
for (unsigned j = 0; j != path.get_size(); ++j) {
out << path.get_path_matrix()(i, j) << ", ";
}
out << std::endl;
}
out << std::endl;
return out;
}

MatrixXb PathHandler::get_connectivity_matrix() const {
return connectivity_matrix_;
}
Expand Down
36 changes: 0 additions & 36 deletions tket/src/ArchAwareSynth/SteinerTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,41 +806,5 @@ unsigned CNotSwapSynth::swap_to_root(

bool CNotSwapSynth::valid_result() { return CNOT_matrix.is_id(); }

std::ostream& operator<<(std::ostream& out, const SteinerTree& st) {
out << "\nprint the details of a steiner tree: \n";
out << "root: " << st.root << "\n";
out << "cost: " << st.tree_cost << "\n";
out << "SteinerNodeTypes: ";
for (SteinerNodeType nt : st.node_types) {
out << (int)nt << " ";
}
out << "\n";
out << "neighbours: ";

for (unsigned n : st.num_neighbours) {
out << n << " ";
}
out << "\n\n";
return out;
}

std::ostream& operator<<(std::ostream& out, const CNotSwapSynth& cnot) {
out << "\nprint the details of a CNot synth object: \n";

out << "circuit:\n";
for (auto g : cnot.circ) {
out << g << ", ";
}
out << std::endl;

out << "path:\n";
out << cnot.paths;

out << "CNot matrix:\n";
out << cnot.CNOT_matrix;

return out;
}

} // namespace aas
} // namespace tket
5 changes: 0 additions & 5 deletions tket/src/ArchAwareSynth/include/ArchAwareSynth/Path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,5 @@ class IterationOrder {
*/
std::vector<Node> find_hampath(const Architecture &arch, long timeout = 10000);

/**
* print out a given Pathhandler
*/
std::ostream &operator<<(std::ostream &out, const PathHandler &path);

} // namespace aas
} // namespace tket
10 changes: 0 additions & 10 deletions tket/src/ArchAwareSynth/include/ArchAwareSynth/SteinerTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ class SteinerTree {
*/
std::vector<unsigned> nodes() const;

/**
* function to stream a steiner tree
*/
friend std::ostream &operator<<(std::ostream &out, const SteinerTree &st);

unsigned tree_cost; // the cost to reduce the Steiner tree alone
int last_operation_cost;
unsigned root;
Expand Down Expand Up @@ -185,11 +180,6 @@ class CNotSwapSynth {
*/
bool valid_result();

/**
* function to stream a CNotSwapSynth
*/
friend std::ostream &operator<<(std::ostream &out, const CNotSwapSynth &cnot);

private:
void add_swap(unsigned first, unsigned second);
void cleanup_swaps();
Expand Down
1 change: 0 additions & 1 deletion tket/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ list(APPEND TKET_COMPS
Architecture
Simulation
Diagonalisation
Program
Characterisation
Converters
Placement
Expand Down
89 changes: 47 additions & 42 deletions tket/src/Mapping/MappingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,55 +101,60 @@ bool MappingManager::route_circuit_with_maps(
// find next routed/unrouted boundary given updates
mapping_frontier->advance_frontier_boundary(this->architecture_);
}

// check all nodes placed

bool found_unplaced_qubit = false;

// search for unplaced qubitto speed up the runtime
for (Qubit q : mapping_frontier->circuit_.all_qubits()) {
if (!this->architecture_->node_exists(Node(q))) {
found_unplaced_qubit = true;
break;
}
}

if (found_unplaced_qubit && label_isolated_qubits) {
// there may still be some unlabelled qubits
if (label_isolated_qubits) {
circuit_modified = true;
qubit_vector_t q_vec = mapping_frontier->circuit_.all_qubits();
unit_map_t qubit_to_nodes_place;
node_set_t node_set_placed;

for (Qubit q : q_vec) {
if (this->architecture_->node_exists(Node(q))) {
qubit_to_nodes_place.insert({q, Node(q)});
node_set_placed.insert(Node(q));
unit_map_t placement;
qubit_vector_t to_place;
std::vector<Node> placed;

// Find which/if any qubits need placing
for (const Qubit& q : mapping_frontier->circuit_.all_qubits()) {
Node n(q);
if (!this->architecture_->node_exists(n)) {
// Ancilla qubits can be assigned during routing
// If some qubits are unplaced then its possible the returned circuit
// has more qubits than the architecture has nodes, which is bad instead
// at least assign any unlabelled qubits to any ancilla nodes to prevent
// this
if (mapping_frontier->ancilla_nodes_.size() > 0) {
circuit_modified = true;
Node ancilla = *mapping_frontier->ancilla_nodes_.begin();
mapping_frontier->merge_ancilla(q, ancilla);
mapping_frontier->ancilla_nodes_.erase(
mapping_frontier->ancilla_nodes_.begin());
placed.push_back(n);
} else {
to_place.push_back(n);
}
} else {
placed.push_back(n);
// if already placed, make sure qubit retains placement
placement.insert({n, n});
}
}

node_vector_t nodes_vec = this->architecture_->get_all_nodes_vec();

// place all unplaced qubits

for (Qubit q : q_vec) {
if (!this->architecture_->node_exists(Node(q))) {
// found unplaced qubit

unsigned index_to_use = 0;
while (node_set_placed.find(nodes_vec[index_to_use]) !=
node_set_placed.end()) {
++index_to_use;
}
qubit_to_nodes_place.insert({q, nodes_vec[index_to_use]});
node_set_placed.insert(nodes_vec[index_to_use]);
// avoid doing std::set_difference unless qubits need to be placed
unsigned n_placed = to_place.size();
if (n_placed > 0) {
std::vector<Node> difference,
architecture_nodes = this->architecture_->get_all_nodes_vec();
std::set_difference(
architecture_nodes.begin(), architecture_nodes.end(), placed.begin(),
placed.end(), std::inserter(difference, difference.begin()));
// should always be enough remaining qubits to assign unplaced qubits to
TKET_ASSERT(difference.size() >= n_placed);
for (unsigned i = 0; i < n_placed; i++) {
// naively assign each qubit to some free node
placement.insert({to_place[i], difference[i]});
mapping_frontier->update_bimaps(
mapping_frontier->get_qubit_from_circuit_uid(q),
nodes_vec[index_to_use]);
mapping_frontier->get_qubit_from_circuit_uid(to_place[i]),
difference[i]);
}
}

mapping_frontier->update_linear_boundary_uids(qubit_to_nodes_place);
mapping_frontier->circuit_.rename_units(qubit_to_nodes_place);
mapping_frontier->update_linear_boundary_uids(placement);
mapping_frontier->circuit_.rename_units(placement);
}
}

return circuit_modified;
Expand Down
17 changes: 0 additions & 17 deletions tket/src/Predicates/CompilerPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,24 +378,10 @@ void from_json(const nlohmann::json& j, PassPtr& pp) {
pp = PeepholeOptimise2Q();
} else if (passname == "FullPeepholeOptimise") {
pp = FullPeepholeOptimise();
} else if (passname == "RebaseCirq") {
pp = RebaseCirq();
} else if (passname == "RebaseTket") {
pp = RebaseTket();
} else if (passname == "RebaseHQS") {
pp = RebaseHQS();
} else if (passname == "RebaseQuil") {
pp = RebaseQuil();
} else if (passname == "RebaseProjectQ") {
pp = RebaseProjectQ();
} else if (passname == "RebasePyZX") {
pp = RebasePyZX();
} else if (passname == "RebaseUMD") {
pp = RebaseUMD();
} else if (passname == "RebaseUFR") {
pp = RebaseUFR();
} else if (passname == "RebaseOQC") {
pp = RebaseOQC();
} else if (passname == "RemoveRedundancies") {
pp = RemoveRedundancies();
} else if (passname == "SynthesiseHQS") {
Expand Down Expand Up @@ -485,9 +471,6 @@ void from_json(const nlohmann::json& j, PassPtr& pp) {
content.at("x_circuit").get<Circuit>());
}
pp = gen_simplify_initial(ac, caq, xc);
} else if (passname == "SquashHQS") {
// SEQUENCE PASS - DESERIALIZABLE ONLY
pp = SquashHQS();
} else if (passname == "FullMappingPass") {
// SEQUENCE PASS - DESERIALIZABLE ONLY
Architecture arc = content.at("architecture").get<Architecture>();
Expand Down
2 changes: 0 additions & 2 deletions tket/src/Predicates/PassGenerators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,9 @@ PassPtr gen_routing_pass(
Transform t = Transform(trans);

PredicatePtr twoqbpred = std::make_shared<MaxTwoQubitGatesPredicate>();
PredicatePtr placedpred = std::make_shared<PlacementPredicate>(arc);
PredicatePtr n_qubit_pred =
std::make_shared<MaxNQubitsPredicate>(arc.n_nodes());
PredicatePtrMap precons{
CompilationUnit::make_type_pair(placedpred),
CompilationUnit::make_type_pair(twoqbpred),
CompilationUnit::make_type_pair(n_qubit_pred)};

Expand Down
Loading

0 comments on commit 9370d6b

Please sign in to comment.