Skip to content

Commit

Permalink
Use ClExprOp by default when converting from QASM; add deprecation …
Browse files Browse the repository at this point in the history
…warnings (#1670)
  • Loading branch information
cqc-alec authored Nov 12, 2024
1 parent 1a53ef4 commit c375eae
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
18 changes: 16 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 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
2 changes: 1 addition & 1 deletion pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def requirements(self):
self.requires("pybind11_json/0.2.14")
self.requires("symengine/0.12.0")
self.requires("tkassert/0.3.4@tket/stable")
self.requires("tket/1.3.44@tket/stable")
self.requires("tket/1.3.45@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tktokenswap/0.3.9@tket/stable")
Expand Down
5 changes: 5 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Features:
* Add option to not relabel `ClassicalExpBox` when calling `rename_units`
and `flatten_registers`
* Implement `dagger()` and `transpose()` for `CustomGate`.
* Use `ClExprOp` by default when converting from QASM.

Deprecations:

* Deprecate `ClassicalExpBox` and related methods, in favour of `ClExprOp`.

Fixes:

Expand Down
3 changes: 3 additions & 0 deletions pytket/pytket/_tket/circuit.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ class Circuit:
def add_classicalexpbox_bit(self, expression: pytket.circuit.logic_exp.BitLogicExp, target: typing.Sequence[pytket._tket.unit_id.Bit], **kwargs: Any) -> Circuit:
"""
Append a :py:class:`ClassicalExpBox` over Bit to the circuit.
DEPRECATED: Please use :py:meth:`add_clexpr` instead. This method will be removed after pytket 1.40.
:param classicalexpbox: The box to append
:param args: Indices of the qubits to append the box to
Expand All @@ -1446,6 +1447,7 @@ class Circuit:
def add_classicalexpbox_register(self, expression: pytket.circuit.logic_exp.RegLogicExp, target: typing.Sequence[pytket._tket.unit_id.Bit], **kwargs: Any) -> Circuit:
"""
Append a :py:class:`ClassicalExpBox` over BitRegister to the circuit.
DEPRECATED: Please use :py:meth:`add_clexpr` instead. This method will be removed after pytket 1.40.
:param classicalexpbox: The box to append
:param args: Indices of the qubits to append the box to
Expand Down Expand Up @@ -3619,6 +3621,7 @@ class OpType:
MultiBit : A classical operation applied to multiple bits simultaneously
ClassicalExpBox : A box for holding compound classical operations on Bits.
DEPRECATED: Please use :py:class:`WiredClExpr` instead. This class will be removed after pytket 1.40.
MultiplexorBox : A multiplexor (i.e. uniformly controlled operations)
Expand Down
10 changes: 5 additions & 5 deletions pytket/pytket/qasm/qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def __init__(
self,
return_gate_dict: bool = False,
maxwidth: int = 32,
use_clexpr: bool = False,
use_clexpr: bool = True,
) -> None:
super().__init__()
self.q_registers: dict[str, int] = {}
Expand Down Expand Up @@ -978,7 +978,7 @@ def circuit_from_qasm(
input_file: Union[str, "os.PathLike[Any]"],
encoding: str = "utf-8",
maxwidth: int = 32,
use_clexpr: bool = False,
use_clexpr: bool = True,
) -> Circuit:
"""A method to generate a tket Circuit from a qasm file.
Expand All @@ -1000,7 +1000,7 @@ def circuit_from_qasm(


def circuit_from_qasm_str(
qasm_str: str, maxwidth: int = 32, use_clexpr: bool = False
qasm_str: str, maxwidth: int = 32, use_clexpr: bool = True
) -> Circuit:
"""A method to generate a tket Circuit from a qasm string.
Expand All @@ -1023,7 +1023,7 @@ def circuit_from_qasm_str(


def circuit_from_qasm_io(
stream_in: TextIO, maxwidth: int = 32, use_clexpr: bool = False
stream_in: TextIO, maxwidth: int = 32, use_clexpr: bool = True
) -> Circuit:
"""A method to generate a tket Circuit from a qasm text stream"""
return circuit_from_qasm_str(
Expand All @@ -1036,7 +1036,7 @@ def circuit_from_qasm_wasm(
wasm_file: Union[str, "os.PathLike[Any]"],
encoding: str = "utf-8",
maxwidth: int = 32,
use_clexpr: bool = False,
use_clexpr: bool = True,
) -> Circuit:
"""A method to generate a tket Circuit from a qasm string and external WASM module.
Expand Down
2 changes: 1 addition & 1 deletion tket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class TketConan(ConanFile):
name = "tket"
version = "1.3.44"
version = "1.3.45"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down

0 comments on commit c375eae

Please sign in to comment.