Skip to content

Commit

Permalink
Update docmain to align with main (#1688)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Nov 20, 2024
1 parent c365f8f commit 3d7685b
Show file tree
Hide file tree
Showing 125 changed files with 3,093 additions and 2,027 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-without-conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
- name: Install symengine
run: |
cd ${TMP_DIR}
wget https://github.com/symengine/symengine/archive/refs/tags/v0.12.0.tar.gz
tar xzvf v0.12.0.tar.gz
cd symengine-0.12.0/
wget https://github.com/symengine/symengine/archive/refs/tags/v0.13.0.tar.gz
tar xzvf v0.13.0.tar.gz
cd symengine-0.13.0/
mkdir build
cd build
cmake -GNinja -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTS=OFF -DBUILD_BENCHMARKS=OFF ..
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ jobs:
python -m pip install -U mypy pybind11-stubgen
cd pytket
./stub_generation/regenerate_stubs
git diff --quiet pytket/_tket && echo "Stubs are up-to-date" || exit 1 # fail if stubs change after regeneration
git diff pytket/_tket && echo "Stubs are up-to-date" || exit 1 # fail if stubs change after regeneration
python -m mypy --config-file=mypy.ini --no-incremental -p pytket -p tests
- name: Upload package
if: github.event_name == 'push' && needs.check_changes.outputs.tket_changed == 'true'
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install black and pylint
run: pip install black pylint
- name: Install black, pylint and ruff
run: pip install black pylint ruff
- name: Check files are formatted with black
run: |
# Paths specified to avoid formatting submodules
Expand All @@ -25,3 +25,7 @@ jobs:
run: |
cd pytket
pylint --ignore-paths=pytket/_tket pytket/
- name: ruff check
run: |
cd pytket
ruff check .
10 changes: 6 additions & 4 deletions .github/workflows/pytket_benchmarking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ jobs:

- name: Post to a Slack channel
id: slack
uses: slackapi/slack-github-action@v1.27.0
uses: slackapi/slack-github-action@v2.0.0
with:
channel-id: 'G01CP0YFFA7'
slack-message: '${{ env.RETURN_TEST }} Release tag: ${{ github.event.release.tag_name }}.'
method: chat.postMessage
token: ${{ secrets.PYTKET_BENCHMARKING_SLACK_BOT_TOKEN }}
payload: |
channel: 'G01CP0YFFA7'
text: '${{ env.RETURN_TEST }} Release tag: ${{ github.event.release.tag_name }}.'
env:
SLACK_BOT_TOKEN: ${{ secrets.PYTKET_BENCHMARKING_SLACK_BOT_TOKEN }}
RETURN_TEST: ${{ env.RETURN_TEST }}
6 changes: 3 additions & 3 deletions build-without-conan.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ make install

```
cd ${TMP_DIR}
wget https://github.com/symengine/symengine/archive/refs/tags/v0.12.0.tar.gz
tar xzvf v0.12.0.tar.gz
cd symengine-0.12.0/
wget https://github.com/symengine/symengine/archive/refs/tags/v0.13.0.tar.gz
tar xzvf v0.13.0.tar.gz
cd symengine-0.13.0/
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTS=OFF -DBUILD_BENCHMARKS=OFF ..
Expand Down
47 changes: 45 additions & 2 deletions pytket/binders/circuit/Circuit/add_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ void init_circuit_add_op(py::class_<Circuit, std::shared_ptr<Circuit>> &c) {
[](Circuit *circ, const py::tket_custom::BitLogicExpression &exp,
const py::tket_custom::SequenceVec<Bit> &outputs,
const py::kwargs &kwargs) {
PyErr_WarnEx(
PyExc_DeprecationWarning,
"The add_classicalexpbox_bit method is deprecated. Please use "
"Circuit::add_clexpr() instead.",
1);
auto inputs = exp.attr("all_inputs")().cast<std::set<Bit>>();
py::tket_custom::SequenceVec<Bit> o_vec, io_vec;

Expand All @@ -439,7 +444,9 @@ void init_circuit_add_op(py::class_<Circuit, std::shared_ptr<Circuit>> &c) {
n_i, n_io, n_o, exp),
o_vec, kwargs);
},
"Append a :py:class:`ClassicalExpBox` over Bit to the circuit.\n\n"
"Append a :py:class:`ClassicalExpBox` over Bit to the circuit.\n"
"DEPRECATED: Please use :py:meth:`add_clexpr` instead. This method "
"will be removed after pytket 1.40.\n\n"
":param classicalexpbox: The box to append\n"
":param args: Indices of the qubits to append the box to"
"\n:return: the new :py:class:`Circuit`",
Expand All @@ -450,6 +457,11 @@ void init_circuit_add_op(py::class_<Circuit, std::shared_ptr<Circuit>> &c) {
const py::tket_custom::BitRegisterLogicExpression &exp,
const py::tket_custom::SequenceVec<Bit> &outputs,
const py::kwargs &kwargs) {
PyErr_WarnEx(
PyExc_DeprecationWarning,
"The add_classicalexpbox_register method is deprecated. Please "
"use Circuit::add_clexpr() instead.",
1);
auto inputs =
exp.attr("all_inputs")().cast<std::set<BitRegister>>();
std::set<Bit> all_bits;
Expand Down Expand Up @@ -481,7 +493,9 @@ void init_circuit_add_op(py::class_<Circuit, std::shared_ptr<Circuit>> &c) {
o_vec, kwargs);
},
"Append a :py:class:`ClassicalExpBox` over BitRegister to the "
"circuit.\n\n"
"circuit.\n"
"DEPRECATED: Please use :py:meth:`add_clexpr` instead. This method "
"will be removed after pytket 1.40.\n\n"
":param classicalexpbox: The box to append\n"
":param args: Indices of the qubits to append the box to"
"\n:return: the new :py:class:`Circuit`",
Expand All @@ -499,6 +513,35 @@ void init_circuit_add_op(py::class_<Circuit, std::shared_ptr<Circuit>> &c) {
":param args: The bits to apply the expression to\n"
":return: the new :py:class:`Circuit`",
py::arg("expr"), py::arg("args"))
.def(
"add_clexpr_from_logicexp",
[](Circuit *circ, const py::tket_custom::LogicExpression &exp,
const py::tket_custom::SequenceVec<Bit> &output_bits,
const py::kwargs &kwargs) {
py::list outputs;
for (const auto &bit : output_bits) {
outputs.append(bit);
}
py::module clexpr = py::module::import("pytket.circuit.clexpr");
py::object add_op =
clexpr.attr("_add_clexpr_to_circuit_from_logicexp");
add_op(circ, exp, outputs, **kwargs);
return circ;
},
"Append a :py:class:`ClExprOp` defined in terms of a logical "
"expression.\n\n"
"Example:\n"
">>> c = Circuit()\n"
">>> x_reg = c.add_c_register('x', 3)\n"
">>> y_reg = c.add_c_register('y', 3)\n"
">>> z_reg = c.add_c_register('z', 3)\n"
">>> c.add_clexpr_from_logicexp(x_reg | y_reg, z_reg.to_list())\n"
">>> [ClExpr x[0], x[1], x[2], y[0], y[1], y[2], z[0], z[1], z[2]; "
"]\n\n"
":param exp: logical expression\n"
":param output_bits: list of bits in output\n"
":return: the updated circuit",
py::arg("exp"), py::arg("output_bits"))
.def(
"add_custom_gate",
[](Circuit *circ, const composite_def_ptr_t &definition,
Expand Down
20 changes: 14 additions & 6 deletions pytket/binders/circuit/Circuit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,12 @@ void def_circuit(py::class_<Circuit, std::shared_ptr<Circuit>> &pyCircuit) {
.def(
"flatten_registers", &Circuit::flatten_registers,
"Combines all qubits into a single register namespace with "
"the default name, and likewise for bits")
"the default name, and likewise for bits"
"\n\n:param relabel_classical_expression: Determines whether python "
"classical expressions held in `ClassicalExpBox` have their "
"expression "
"relabelled to match relabelled Bit.",
py::arg("relabel_classical_expression") = true)

// Circuit composition:
.def(
Expand Down Expand Up @@ -472,15 +477,18 @@ void def_circuit(py::class_<Circuit, std::shared_ptr<Circuit>> &pyCircuit) {
"\n\n:return: the circuit depth")
.def(
"n_gates_of_type",
[](const Circuit &circ, const OpType &_type) {
return circ.count_gates(_type);
[](const Circuit &circ, const OpType &_type,
const bool include_conditional) {
return circ.count_gates(_type, include_conditional);
},
"Returns the number of vertices in the dag of a given "
"operation type.\n\n>>> c.CX(0,1)\n>>> c.H(0)\n>>> "
"c.CX(0,1)\n>>> c.n_gates_of_type(OpType.CX)\n2\n\n:param "
"type: The operation type to search for\n:return: the "
"number of operations matching `type`",
py::arg("type"))
"type: The operation type to search for\n\n:param "
"include_conditional: if set to true, conditional gates will "
"be counted, too\n\n:return: the number of operations "
"matching `type`",
py::arg("type"), py::arg("include_conditional") = false)
.def(
"n_1qb_gates",
[](const Circuit &circ) { return circ.count_n_qubit_gates(1); },
Expand Down
4 changes: 2 additions & 2 deletions pytket/binders/circuit/clexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace tket {

static std::string qasm_bit_repr(
const ClExprTerm &term, const std::map<int, Bit> &input_bits) {
if (const int *n = std::get_if<int>(&term)) {
if (const uint64_t *n = std::get_if<uint64_t>(&term)) {
switch (*n) {
case 0:
return "0";
Expand All @@ -56,7 +56,7 @@ static std::string qasm_bit_repr(

static std::string qasm_reg_repr(
const ClExprTerm &term, const std::map<int, BitRegister> &input_regs) {
if (const int *n = std::get_if<int>(&term)) {
if (const uint64_t *n = std::get_if<uint64_t>(&term)) {
std::stringstream ss;
ss << *n;
return ss.str();
Expand Down
4 changes: 3 additions & 1 deletion pytket/binders/circuit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,9 @@ PYBIND11_MODULE(circuit, m) {
"A classical operation applied to multiple bits simultaneously")
.value(
"ClassicalExpBox", OpType::ClassicalExpBox,
"A box for holding compound classical operations on Bits.")
"A box for holding compound classical operations on Bits.\n"
"DEPRECATED: Please use :py:class:`WiredClExpr` instead. This class "
"will be removed after pytket 1.40.")
.value(
"MultiplexorBox", OpType::MultiplexorBox,
"A multiplexor (i.e. uniformly controlled operations)")
Expand Down
Loading

0 comments on commit 3d7685b

Please sign in to comment.