diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index cc080c1a1e6..f4a3360c12c 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -132,7 +132,7 @@ Completed deprecation cycles - Deprecated in v0.29 - Removed in v0.31 -* ``qml.op_sum``` has been removed. Users should use ``qml.sum`` instead. +* ``qml.op_sum`` has been removed. Users should use ``qml.sum`` instead. - Deprecated in v0.29. - Removed in v0.31. diff --git a/pennylane/tape/qscript.py b/pennylane/tape/qscript.py index 77f33a50938..b354dbda2f2 100644 --- a/pennylane/tape/qscript.py +++ b/pennylane/tape/qscript.py @@ -1428,6 +1428,10 @@ def __getitem__(self, item): ) return super().__getitem__(item) + def copy(self): + """Custom copy function to return a SpecsDict instead of a dict.""" + return SpecsDict(self.items()) + def make_qscript(fn, shots: Optional[Union[int, Sequence, Shots]] = None): """Returns a function that generates a qscript from a quantum function without any diff --git a/pennylane/transforms/optimization/pattern_matching.py b/pennylane/transforms/optimization/pattern_matching.py index 6b2f6d23522..ef54d3e0648 100644 --- a/pennylane/transforms/optimization/pattern_matching.py +++ b/pennylane/transforms/optimization/pattern_matching.py @@ -141,10 +141,10 @@ def circuit(): In our case, it is possible to find three CNOTs and replace this pattern with only two CNOTs and therefore optimizing the circuit. The number of CNOTs in the circuit is reduced by one. - >>> qml.specs(qnode)()["gate_types"]["CNOT"] + >>> qml.specs(qnode)()["resources"].gate_types["CNOT"] 4 - >>> qml.specs(optimized_qnode)()["gate_types"]["CNOT"] + >>> qml.specs(optimized_qnode)()["resources"].gate_types["CNOT"] 3 >>> print(qml.draw(qnode)()) diff --git a/pennylane/transforms/specs.py b/pennylane/transforms/specs.py index 1dd993caa95..e508b808a46 100644 --- a/pennylane/transforms/specs.py +++ b/pennylane/transforms/specs.py @@ -88,20 +88,23 @@ def specs_qnode(*args, **kwargs): """Returns information on the structure and makeup of provided QNode. Dictionary keys: - * ``"num_operations"`` - * ``"num_observables"`` - * ``"num_diagonalizing_gates"`` - * ``"gate_sizes"``: dictionary mapping gate number of wires to number of occurances - * ``"gate_types"``: dictionary mapping gate types to number of occurances + * ``"num_operations"`` number of operations in the qnode + * ``"num_observables"`` number of observables in the qnode + * ``"num_diagonalizing_gates"`` number of diagonalizing gates required for execution of the qnode + * ``"resources"``: a :class:`~.resource.Resources` object containing resource quantities used by the qnode * ``"num_used_wires"``: number of wires used by the circuit * ``"num_device_wires"``: number of wires in device * ``"depth"``: longest path in directed acyclic graph representation - * ``"dev_short_name"``: name of QNode device - * ``"diff_method"`` + * ``"device_name"``: name of QNode device + * ``"expansion_strategy"``: string specifying method for decomposing operations in the circuit + * ``"gradient_options"``: additional configurations for gradient computations + * ``"interface"``: autodiff framework to dispatch to for the qnode execution + * ``"diff_method"``: a string specifying the differntiation method + * ``"gradient_fn"``: executable to compute the gradient of the qnode Potential Additional Information: * ``"num_trainable_params"``: number of individual scalars that are trainable - * ``"num_parameter_shift_executions"``: number of times circuit will execute when + * ``"num_gradient_executions"``: number of times circuit will execute when calculating the derivative Returns: diff --git a/tests/tape/test_qscript.py b/tests/tape/test_qscript.py index 8a5e8d36506..9186322be44 100644 --- a/tests/tape/test_qscript.py +++ b/tests/tape/test_qscript.py @@ -468,6 +468,16 @@ def test_specs_tape(self, make_script): assert specs["num_trainable_params"] == 5 assert specs["depth"] == 3 + def test_specs_copy(self, make_script): + """Test that the copy method of specs retuns a SpecsDict.""" + qs = make_script + copied_specs = qs.specs.copy() + + assert isinstance(copied_specs, qml.tape.qscript.SpecsDict) + with pytest.warns(UserWarning, match="key is deprecated and will be removed"): + for k, v in qs.specs.items(): + assert copied_specs[k] == v + @pytest.mark.parametrize( "shots, total_shots, shot_vector", [