Repository navigation
Remove the Autograd interface - #10551
JerryChen97 wants to merge 24 commits into
Conversation
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Respect Torch trainability in classical cotransforms and migrate remaining interface fixtures and examples to NumPy, JAX, and Torch. Assisted-by: Codex
…utograd-interface Assisted-by: Codex
Allow NumPy and JAX jobs to collect the Hessian module without Torch installed, and mark migrated Torch-only scenarios consistently. Assisted-by: Codex
Use native JAX metric inputs, mark Torch-only fixtures consistently, and keep scalar finite-shift references compatible with pytest 9.2. Assisted-by: Codex
Use native JAX parameters for the state-preparation metric reference and run the trainability rejection fixture in the Torch job. Assisted-by: Codex
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10551 +/- ##
==========================================
- Coverage 99.43% 99.41% -0.02%
==========================================
Files 614 613 -1
Lines 67794 67866 +72
==========================================
+ Hits 67408 67472 +64
- Misses 386 394 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Assisted-by: Codex
There was a problem hiding this comment.
🟡 Changes recommended
Interface-resolution regressions reject legacy PennyLane NumPy parameters even during explicit NumPy execution and prevent default QNodes from directly using non-differentiable QChem observables.
7 open issues
Avoid Autograd inference in explicit NumPy interface probes · New Make non-trainable QChem observables usable by NumPy QNodes · New Route retained Autograd tests to active CI suites · New Support native JAX trainability in optimizer steps · New Enable JAX x64 during conversion and Jacobian checks · New Document PennyLane NumPy input restrictions beyond gradient workflows · New Migrate remaining public examples away from PennyLane NumPy · New
What changed in this PR
AI-assisted summary for developer review: this PR removes Autograd from PennyLane’s QNode and execution interfaces, while retaining it internally for legacy classical helpers. Execution, differentiation examples, and generic coverage move toward NumPy, JAX, and PyTorch.
Changes:
- Removes Autograd interface resolution and workflow dispatch.
- Migrates tests and examples to retained frameworks, including native operator validation and legacy optimizer adapters.
- Removes the dedicated Autograd CI job and documents migration requirements.
Validation: Targeted source inspection only; project tests and CI results were not verified.
File Description tests/workflow/test_setup_transform_program.pyUses Torch execution configurations. tests/workflow/test_resolve_interface.pyTests rejection of Autograd inference. tests/workflow/test_get_best_diff_method.pyMigrates differentiation selection coverage. tests/workflow/test_construct_batch.pyUses trainable Torch parameters. tests/workflow/interfaces/test_transform_program_integration.pyReplaces Autograd cases with NumPy. tests/workflow/interfaces/run/test_run.pyRemoves Autograd interface parametrization. tests/workflow/interfaces/qnode/test_torch_qnode.pyTests switching from NumPy to Torch. tests/workflow/interfaces/execute/test_torch.pyUses Torch execution configuration. tests/workflow/interfaces/execute/test_jax_jit.pyUses NumPy reference execution. tests/transforms/test_defer_measurements.pyUses standard NumPy inputs. tests/transforms/test_compile.pyCreates explicit NumPy parameters. tests/transforms/test_broadcast_expand.pyReplaces legacy broadcast input fixtures. tests/transforms/decompositions/test_cliffordt_transform.pyRetains JAX and Torch gradient comparisons. tests/testing/test_assert_valid.pyAdds native differentiation validation cases. tests/test_vqe.pyCompares JAX and Torch gradients. tests/test_return_types.pyUses NumPy execution parametrization. tests/test_return_types_qnode.pyMigrates stacked Jacobian checks to JAX. tests/test_return_types_legacy.pyUses NumPy legacy execution cases. tests/test_compiler.pyUses JAX differentiation references. tests/templates/test_subroutine.pyUses JAX gradient inputs. tests/templates/tensornetworks/test_TTN.pyMigrates differentiability checks to JAX. tests/templates/tensornetworks/test_MERA.pyMigrates differentiability checks to JAX. tests/templates/swapnetworks/test_ccl2.pyRemoves Autograd cases; uses JAX gradients. tests/templates/subroutines/time_evolution/test_trotter.pyMigrates gradient checks to JAX. tests/templates/subroutines/time_evolution/test_commuting_evolution.pyUpdates native gradient-transform coverage. tests/templates/subroutines/test_qubitization.pyRemoves dedicated Autograd integration test. tests/templates/subroutines/test_qsvt.pyUses JAX differentiation and precision context. tests/templates/subroutines/test_qrom.pyNormalizes NumPy bitstring inputs. tests/templates/subroutines/test_permute.pyUses NumPy QNode execution. tests/templates/subroutines/test_controlled_sequence.pyMigrates composite-operation gradient inputs. tests/templates/subroutines/qchem/test_uccsd.pyRemoves dedicated Autograd coverage. tests/templates/subroutines/qchem/test_single_excitation.pyRemoves dedicated Autograd coverage. tests/templates/subroutines/qchem/test_kupccgsd.pyUses JAX parameter-shift comparison inputs. tests/templates/subroutines/qchem/test_double_excitation.pyRemoves dedicated Autograd coverage. tests/templates/subroutines/qchem/test_basis_rotation.pyRemoves dedicated Autograd coverage. tests/templates/subroutines/qchem/test_all_singles_doubles.pyRemoves dedicated Autograd coverage. tests/templates/subroutines/arithmetic/test_signed_out_square.pyUses standard NumPy fixtures. tests/templates/subroutines/arithmetic/test_out_square.pyUses standard NumPy fixtures. tests/templates/subroutines/arithmetic/test_out_multiplier.pyUses standard NumPy fixtures. tests/templates/state_preparations/test_superposition.pyMigrates gradient smoke tests to JAX. tests/templates/state_preparations/test_mottonen_state_prep.pyUses NumPy execution and JAX gradients. tests/templates/layers/test_random.pyRemoves dedicated Autograd integration test. tests/shadow/test_shadow_transforms.pyUpdates execution defaults and interface cases. tests/shadow/test_shadow_entropies.pyUses NumPy forward-execution coverage. tests/shadow/test_shadow_class.pySeparates standard and legacy NumPy inputs. tests/qchem/test_structure.pyConverts circuit inputs and observable coefficients. tests/qchem/test_hamiltonians.pyMigrates energy-gradient integration to JAX. tests/qchem/test_dipole.pyMigrates dipole gradients to JAX. tests/qchem/openfermion_pyscf_tests/test_convert.pyUses standard NumPy fixtures. tests/pauli/test_trace_inner_product.pyRoutes retained classical coverage to core. tests/pauli/test_conversion.pyUses native JAX gradient-wrapper comparisons. tests/optimize/test_spsa.pyAdds explicit NumPy execution conversions. tests/optimize/test_rotosolve.pyWraps legacy inputs for NumPy execution. tests/optimize/test_rotoselect.pyUpdates NumPy execution setup and naming. tests/optimize/test_reconstruct.pyRetains classical tests; removes Autograd QNodes. tests/optimize/test_qnspsa.pyAdds NumPy parameter-conversion transforms. tests/optimize/test_qng_qjit.pyUses JAX references and asserts initial state. tests/optimize/test_optimize.pyReplaces legacy QNode costs with classical equivalents. tests/optimize/test_nesterov_momentum.pySupplies native gradients through optimizer hooks. tests/optimize/test_momentum_qng_qjit.pyKeeps reference parameters in JAX. tests/optimize/test_gradient_descent.pySupplies native gradients through optimizer hooks. tests/ops/test_channel_ops.pyMigrates channel gradient checks to JAX. tests/ops/qubit/test_state_prep.pyUpdates interfaces and removes Autograd backprop case. tests/ops/qubit/test_sparse.pyUses JAX gradient inputs. tests/ops/qubit/test_matrix_ops.pyMigrates BlockEncode differentiation inputs. tests/ops/op_math/test_sum.pyUses JAX measurement-gradient inputs. tests/ops/op_math/test_sprod.pyUses JAX scalar and circuit gradients. tests/ops/op_math/test_prod.pyUpdates gradient and broadcasting inputs. tests/ops/op_math/test_pow_op.pyUses JAX gradients and NumPy broadcasting. tests/ops/op_math/test_exp.pyUses Torch trainability coverage. tests/ops/op_math/test_evolution.pyUses JAX parameter-shift comparison input. tests/ops/op_math/test_decompositions.pyRemoves Autograd QNode warning cases. tests/ops/op_math/test_controlled_decompositions.pyCompares native JAX differentiation methods. tests/ops/op_math/test_adjoint.pyUpdates gradient and broadcasting inputs. tests/ops/functions/test_matrix.pyRoutes classical Autograd coverage to core. tests/ops/functions/test_dot.pyRoutes classical Autograd coverage to core. tests/numpy/test_numpy_wrapper.pyAdds classical array-conversion gradient regression. tests/noise/test_mitigate.pyConverts forward-execution parameters to NumPy. tests/measurements/test_vn_entropy.pyUpdates interfaces and removes Autograd gradients. tests/measurements/test_sample.pyMigrates sample Jacobian coverage to JAX. tests/measurements/test_mutual_info.pyUpdates interfaces and removes Autograd gradients. tests/measurements/test_measurements_legacy.pyUses NumPy legacy measurement execution. tests/measurements/test_expval.pyUses NumPy expectation-value execution. tests/math/test_matrix_manipulation.pyPreserves classical Autograd coverage in core. tests/math/test_is_independent.pyRemoves QNode cases from independence checks. tests/math/test_init.pyPreserves classical Autograd coverage in core. tests/math/test_functions.pyTests interface rejection and JAX covariance gradients. tests/logging/test_logging_jax.pyUpdates inputs and expected execution logs. tests/liealg/test_lie_closure.pyPreserves classical Autograd coverage in core. tests/helpers/legacy_optimizer_native.pyAdapts native derivatives for legacy optimizers. tests/gradients/parameter_shift/test_parameter_shift_shot_vec.pyMigrates inputs and custom-result differentiation checks. tests/gradients/core/test_vjp.pyAdds object and empty Jacobian regressions. tests/gradients/core/test_fisher.pyMigrates Fisher integration to retained frameworks. tests/gradients/core/test_adjoint_diff.pyUses Torch for non-trainable-unitary checks. tests/drawer/test_draw_mpl.pyUses trainable Torch drawing inputs. tests/docs/test_supported_confs.pyRemoves Autograd from supported configurations. tests/devices/test_qubit_device.pyAdds scatter dtype and zero-fill coverage. tests/devices/test_null_qubit.pyMigrates gradient and Jacobian checks to Torch. tests/devices/test_lightning_qubit.pyUses JAX integration parameters. tests/devices/test_legacy_facade.pyUses Torch passthrough capabilities. tests/devices/test_execution_config.pyTests rejection of Autograd configuration. tests/devices/test_default_mixed.pyRemoves Autograd interface parametrizations. tests/devices/qubit/test_simulate.pyUpdates supported interfaces and preservation checks. tests/devices/qubit_mixed/test_qubit_mixed_simulate.pyRemoves Autograd interface parametrization. tests/devices/default_qubit/test_default_qubit_preprocessing.pyMigrates preprocessing gradient checks to JAX. tests/devices/default_qubit/test_default_qubit_native_mcm.pyUses standard NumPy circuit parameters. tests/core/test_cotransform_cache.pyTests retained interfaces and Torch trainability. tests/core/operator/test_core_operator.pyRoutes classical Autograd coverage to core. tests/conftest.pyRemoves Autograd from shared interface fixture. pennylane/workflow/run.pyRemoves Autograd dispatch and cache selection. pennylane/workflow/resolution.pyRejects inferred Autograd execution interfaces. pennylane/workflow/qnode.pyDocuments retained execution interfaces. pennylane/workflow/jacobian_products.pyUpdates interface references in docstrings. pennylane/workflow/interfaces/torch.pyUpdates nested-result documentation. pennylane/workflow/execution.pyDocuments NumPy execution and Torch differentiation. pennylane/workflow/construct_batch.pyUpdates NumPy examples and expected batches. pennylane/transforms/unitary_to_rot.pyMigrates differentiation examples to JAX. pennylane/transforms/defer_measurements.pyUpdates execution and differentiation examples. pennylane/transforms/batch_partial.pyMigrates differentiable batching examples to Torch. pennylane/transforms/batch_params.pyMigrates parameter-batching examples to Torch. pennylane/testing/operators.pyUses JAX for differentiation validation. pennylane/templates/subroutines/time_evolution/trotter.pyDocuments explicit JAX gradient arguments. pennylane/templates/subroutines/time_evolution/qdrift.pyUses JAX differentiation example input. pennylane/templates/subroutines/qpe.pyUses standard NumPy in example. pennylane/templates/subroutines/qchem/uccsd.pyUses a native JAX optimization loop. pennylane/templates/subroutines/qchem/kupccgsd.pyUses a native JAX optimization loop. pennylane/templates/layers/random.pyUses standard NumPy example weights. pennylane/templates/layers/gate_fabric.pyUses a native JAX optimization loop. pennylane/templates/embeddings/qaoaembedding.pyDocuments JAX weight and feature optimization. pennylane/shadows/transforms.pyMigrates differentiable shadow example to Torch. pennylane/shadows/__init__.pyMigrates shadow-gradient example to Torch. pennylane/pauli/conversion.pyUses JAX complex-gradient example. pennylane/optimize/shot_adaptive.pyOrders trainable argument indices consistently. pennylane/ops/op_math/sum.pyMigrates gradient example to JAX. pennylane/ops/op_math/sprod.pyUses explicit native gradient arguments. pennylane/ops/op_math/prod.pyMigrates execution and gradient examples. pennylane/ops/op_math/controlled.pyMigrates gradient example to JAX. pennylane/noise/mitigate.pyMigrates mitigation gradients to Torch. pennylane/measurements/vn_entropy.pyMigrates entropy-gradient example to JAX. pennylane/measurements/state.pyUses framework-aware math and JAX input. pennylane/measurements/sample.pyMigrates sample Jacobian examples to JAX. pennylane/measurements/mutual_info.pyMigrates gradient example to JAX. pennylane/measurements/classical_shadow.pyMigrates shadow differentiation examples to Torch. pennylane/measurements/__init__.pyUses JAX measurement-gradient input. pennylane/math/interface_utils.pyRemoves the canonical Autograd interface. pennylane/gradients/fisher.pyRemoves Autograd Jacobian dispatch. pennylane/drawer/draw.pyUpdates transformed-circuit drawing examples. pennylane/devices/tracker.pyMigrates gradient-tracking examples to Torch. pennylane/devices/tests/test_measurements.pyUses JAX device-gradient comparisons. pennylane/devices/tests/test_compare_default_qubit.pyMigrates device comparison inputs to JAX. pennylane/core/transforms/cotransform_cache.pyRemoves Autograd dispatch; filters Torch arguments. pennylane/core/operator/base.pyUpdates NumPy examples and representations. doc/releases/changelog-dev.rstRecords native differentiation and interface removal. .github/workflows/update-durations.ymlRemoves obsolete Autograd job exclusion. .github/workflows/rerun-test.ymlRemoves Autograd rerun options. .github/workflows/interface-unit-tests.ymlRemoves the dedicated Autograd CI job.
Review effort: Max
| coeffs, ops = h.terms() | ||
| return qp.expval(qp.Hamiltonian(qp.math.toarray(coeffs), ops)) |
There was a problem hiding this comment.
Fixed in 1737af987. Frozen chemistry inputs now produce NumPy coefficients, so their mapped observables work directly in default QNodes. Explicit classical and JAX chemistry differentiation paths are preserved.
Assisted by Codex.
There was a problem hiding this comment.
Follow-up in 9f38319c1: updated the frozen-coefficient assertions to require NumPy values and non-trainability. The explicit trainable-coefficient checks remain unchanged.
Assisted by Codex.
| pytest_xml_file_path: '${{ inputs.job_name_prefix }}autograd-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}.xml' | ||
| pytest_markers: autograd and not finite-diff and not param-shift and not catalyst | ||
|
|
||
| jax-tests: |
There was a problem hiding this comment.
Fixed in 7228b76af. The retained Adjoint matrix regression and confirmed classical/device-helper cases now run in Core. Obsolete Autograd QNode variants were removed or migrated to supported interfaces, preserving the unique gradient assertions.
Assisted by Codex.
There was a problem hiding this comment.
Fixed in eab37fa. The remaining retired QNode cases are removed where native equivalents preserve their assertions, and unique cases are migrated to NumPy, JAX or Torch. The retained FABLE matrix check is explicitly routed to Core. Native counterpart gaps in multi-argument/full-gradient, shot-vector and parameter-shift coverage are corrected. A final collection-only audit finds no unrouted Autograd-marked cases; focused migrated checks pass.
Assisted by Codex.
|
|
||
| elif interface == "autograd": | ||
| jac = jacobian(new_qnode) | ||
|
|
||
| else: | ||
| raise ValueError( |
There was a problem hiding this comment.
Fixed in 568b4eeaa and 1137753dd. The named Fisher, metric-tensor, finite-difference, and covariance examples now use retained frameworks with updated outputs, along with related gradient-reference examples. Physical tape-parameter selection uses supported tape APIs. These edits leave implementation code unchanged.
Assisted by Codex.
There was a problem hiding this comment.
The remaining discovered example families are handled in fbd6349: public guides, joint chemistry optimization, optimizer examples, and NumPy-wrapper guidance now use supported execution paths. QNSPSA’s internal forward batches use NumPy explicitly; Adaptive’s unsupported legacy training example is retired with its limitation documented. Changed example families and the joint chemistry loop were executed. Qiskit conversion could not be exercised locally because the plugin is absent; the equivalent native JAX circuit was verified.
Assisted by Codex.
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved interface conversions break QNode execution with frozen dipole observables and legacy NumPy inputs, alongside Torch Jacobian caching regressions and CI coverage gaps.
7 open issues
Handle legacy Autograd inputs in NumPy backprop validation · New Normalize frozen dipole coefficients for default QNodes · New Make non-trainable QChem observables usable by NumPy QNodes Migrate or reroute tests orphaned by Autograd job removal · New Restore full-Jacobian caching for Torch backward calls · New Route retained Autograd tests to active CI suites Migrate remaining public examples away from PennyLane NumPy
4 resolved since last review
Review effort: Max
|
|
||
| H = qp.SparseHamiltonian(qp.X.compute_sparse_matrix(), wires=0) | ||
| x = qp.numpy.array(0.1) | ||
| x = torch.tensor(0.1, requires_grad=True) |
There was a problem hiding this comment.
Fixed in 612c8a481. Legacy array data is normalized to NumPy only in the capability probe, allowing explicit NumPy/None forward execution with the default differentiation selection. Canonical automatic and explicit Autograd execution remain rejected.
Assisted by Codex.
| coeffs, ops = d_qubit.terms() | ||
| return qp.expval(qp.Hamiltonian(qp.math.toarray(coeffs), ops)) |
There was a problem hiding this comment.
Fixed in 2bb5968. Frozen, no-argument DHF dipole coefficients now become ordinary NumPy arrays at the shared fermionic boundary, so both dipole producers work directly in default QNodes. Explicit differentiable arguments and JAX paths are preserved. The regression now uses the generated observable directly, with an independent matrix expectation and a classical derivative check.
Assisted by Codex.
| pytest_xml_file_path: '${{ inputs.job_name_prefix }}autograd-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}.xml' | ||
| pytest_markers: autograd and not finite-diff and not param-shift and not catalyst | ||
|
|
||
| jax-tests: |
There was a problem hiding this comment.
Fixed in eab37fa. The remaining retired QNode cases are removed where native equivalents preserve their assertions, and unique cases are migrated to NumPy, JAX or Torch. The retained FABLE matrix check is explicitly routed to Core. Native counterpart gaps in multi-argument/full-gradient, shot-vector and parameter-shift coverage are corrected. A final collection-only audit finds no unrouted Autograd-marked cases; focused migrated checks pass.
Assisted by Codex.
| config.gradient_keyword_arguments, | ||
| cache_full_jacobian=config.interface == Interface.AUTOGRAD, | ||
| ) |
There was a problem hiding this comment.
Fixed in 30dc66a. Torch gradient-transform pipelines now enable the full-Jacobian cache at each differentiation layer. Torch graph-building modes have separate entries, so an ordinary backward cannot disconnect a later higher derivative. Analytic, finite-shot and partitioned-shot vector Jacobians reuse the same shifted results; nested Jacobians and the retained-graph mode transition are covered. The cache documentation now describes this behavior.
Assisted by Codex.
There was a problem hiding this comment.
The shared sampled Jacobian also changes the seeded outputs shown in two shadow examples. Those display values are updated in 11061c2 after reproducing the CI outputs and verifying both example files. Seeds, shots, tolerances and implementation are unchanged.
Assisted by Codex.
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
|
Unfortunately, removing autograd seems highly non-trivial and leading to many aspects from different components of the library. A full re-design of removal roadmap is needed rather than to finish everythig in a mega PR |



Remove Autograd as a QNode and execution interface, including automatic inference, its workflow implementation, and its dedicated interface tests and CI job. NumPy, JAX, and PyTorch remain supported.
qp.gradandqp.jacobiangain native eager JAX/PyTorch dispatch while preserving capture and Catalyst differentiation. Update the interface documentation and migrate generic workflow coverage to the retained frameworks.Autograd remains an internal dependency for legacy NumPy, optimizer, and classical helpers; removing that dependency is outside this first step.
Assisted by Codex.