Skip to content

Remove the Autograd interface - #10551

Open
JerryChen97 wants to merge 24 commits into
mainfrom
remove-autograd-interface
Open

JerryChen97 wants to merge 24 commits into
mainfrom
remove-autograd-interface

Conversation

@JerryChen97

Copy link
Copy Markdown
Contributor

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.grad and qp.jacobian gain 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.

Respect Torch trainability in classical cotransforms and migrate remaining interface fixtures and examples to NumPy, JAX, and Torch.

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

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.41%. Comparing base (9282ed9) to head (fbd6349).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JerryChen97
JerryChen97 requested a max review from Copilot November 17, 2026 21:10
@JerryChen97

Copy link
Copy Markdown
Contributor Author

[sc-136770]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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.py Uses Torch execution configurations.
tests/workflow/test_resolve_interface.py Tests rejection of Autograd inference.
tests/workflow/test_get_best_diff_method.py Migrates differentiation selection coverage.
tests/workflow/test_construct_batch.py Uses trainable Torch parameters.
tests/workflow/interfaces/test_transform_program_integration.py Replaces Autograd cases with NumPy.
tests/workflow/interfaces/run/test_run.py Removes Autograd interface parametrization.
tests/workflow/interfaces/qnode/test_torch_qnode.py Tests switching from NumPy to Torch.
tests/workflow/interfaces/execute/test_torch.py Uses Torch execution configuration.
tests/workflow/interfaces/execute/test_jax_jit.py Uses NumPy reference execution.
tests/transforms/test_defer_measurements.py Uses standard NumPy inputs.
tests/transforms/test_compile.py Creates explicit NumPy parameters.
tests/transforms/test_broadcast_expand.py Replaces legacy broadcast input fixtures.
tests/transforms/decompositions/test_cliffordt_transform.py Retains JAX and Torch gradient comparisons.
tests/testing/test_assert_valid.py Adds native differentiation validation cases.
tests/test_vqe.py Compares JAX and Torch gradients.
tests/test_return_types.py Uses NumPy execution parametrization.
tests/test_return_types_qnode.py Migrates stacked Jacobian checks to JAX.
tests/test_return_types_legacy.py Uses NumPy legacy execution cases.
tests/test_compiler.py Uses JAX differentiation references.
tests/templates/test_subroutine.py Uses JAX gradient inputs.
tests/templates/tensornetworks/test_TTN.py Migrates differentiability checks to JAX.
tests/templates/tensornetworks/test_MERA.py Migrates differentiability checks to JAX.
tests/templates/swapnetworks/test_ccl2.py Removes Autograd cases; uses JAX gradients.
tests/templates/subroutines/time_evolution/test_trotter.py Migrates gradient checks to JAX.
tests/templates/subroutines/time_evolution/test_commuting_evolution.py Updates native gradient-transform coverage.
tests/templates/subroutines/test_qubitization.py Removes dedicated Autograd integration test.
tests/templates/subroutines/test_qsvt.py Uses JAX differentiation and precision context.
tests/templates/subroutines/test_qrom.py Normalizes NumPy bitstring inputs.
tests/templates/subroutines/test_permute.py Uses NumPy QNode execution.
tests/templates/subroutines/test_controlled_sequence.py Migrates composite-operation gradient inputs.
tests/templates/subroutines/qchem/test_uccsd.py Removes dedicated Autograd coverage.
tests/templates/subroutines/qchem/test_single_excitation.py Removes dedicated Autograd coverage.
tests/templates/subroutines/qchem/test_kupccgsd.py Uses JAX parameter-shift comparison inputs.
tests/templates/subroutines/qchem/test_double_excitation.py Removes dedicated Autograd coverage.
tests/templates/subroutines/qchem/test_basis_rotation.py Removes dedicated Autograd coverage.
tests/templates/subroutines/qchem/test_all_singles_doubles.py Removes dedicated Autograd coverage.
tests/templates/subroutines/arithmetic/test_signed_out_square.py Uses standard NumPy fixtures.
tests/templates/subroutines/arithmetic/test_out_square.py Uses standard NumPy fixtures.
tests/templates/subroutines/arithmetic/test_out_multiplier.py Uses standard NumPy fixtures.
tests/templates/state_preparations/test_superposition.py Migrates gradient smoke tests to JAX.
tests/templates/state_preparations/test_mottonen_state_prep.py Uses NumPy execution and JAX gradients.
tests/templates/layers/test_random.py Removes dedicated Autograd integration test.
tests/shadow/test_shadow_transforms.py Updates execution defaults and interface cases.
tests/shadow/test_shadow_entropies.py Uses NumPy forward-execution coverage.
tests/shadow/test_shadow_class.py Separates standard and legacy NumPy inputs.
tests/qchem/test_structure.py Converts circuit inputs and observable coefficients.
tests/qchem/test_hamiltonians.py Migrates energy-gradient integration to JAX.
tests/qchem/test_dipole.py Migrates dipole gradients to JAX.
tests/qchem/openfermion_pyscf_tests/test_convert.py Uses standard NumPy fixtures.
tests/pauli/test_trace_inner_product.py Routes retained classical coverage to core.
tests/pauli/test_conversion.py Uses native JAX gradient-wrapper comparisons.
tests/optimize/test_spsa.py Adds explicit NumPy execution conversions.
tests/optimize/test_rotosolve.py Wraps legacy inputs for NumPy execution.
tests/optimize/test_rotoselect.py Updates NumPy execution setup and naming.
tests/optimize/test_reconstruct.py Retains classical tests; removes Autograd QNodes.
tests/optimize/test_qnspsa.py Adds NumPy parameter-conversion transforms.
tests/optimize/test_qng_qjit.py Uses JAX references and asserts initial state.
tests/optimize/test_optimize.py Replaces legacy QNode costs with classical equivalents.
tests/optimize/test_nesterov_momentum.py Supplies native gradients through optimizer hooks.
tests/optimize/test_momentum_qng_qjit.py Keeps reference parameters in JAX.
tests/optimize/test_gradient_descent.py Supplies native gradients through optimizer hooks.
tests/ops/test_channel_ops.py Migrates channel gradient checks to JAX.
tests/ops/qubit/test_state_prep.py Updates interfaces and removes Autograd backprop case.
tests/ops/qubit/test_sparse.py Uses JAX gradient inputs.
tests/ops/qubit/test_matrix_ops.py Migrates BlockEncode differentiation inputs.
tests/ops/op_math/test_sum.py Uses JAX measurement-gradient inputs.
tests/ops/op_math/test_sprod.py Uses JAX scalar and circuit gradients.
tests/ops/op_math/test_prod.py Updates gradient and broadcasting inputs.
tests/ops/op_math/test_pow_op.py Uses JAX gradients and NumPy broadcasting.
tests/ops/op_math/test_exp.py Uses Torch trainability coverage.
tests/ops/op_math/test_evolution.py Uses JAX parameter-shift comparison input.
tests/ops/op_math/test_decompositions.py Removes Autograd QNode warning cases.
tests/ops/op_math/test_controlled_decompositions.py Compares native JAX differentiation methods.
tests/ops/op_math/test_adjoint.py Updates gradient and broadcasting inputs.
tests/ops/functions/test_matrix.py Routes classical Autograd coverage to core.
tests/ops/functions/test_dot.py Routes classical Autograd coverage to core.
tests/numpy/test_numpy_wrapper.py Adds classical array-conversion gradient regression.
tests/noise/test_mitigate.py Converts forward-execution parameters to NumPy.
tests/measurements/test_vn_entropy.py Updates interfaces and removes Autograd gradients.
tests/measurements/test_sample.py Migrates sample Jacobian coverage to JAX.
tests/measurements/test_mutual_info.py Updates interfaces and removes Autograd gradients.
tests/measurements/test_measurements_legacy.py Uses NumPy legacy measurement execution.
tests/measurements/test_expval.py Uses NumPy expectation-value execution.
tests/math/test_matrix_manipulation.py Preserves classical Autograd coverage in core.
tests/math/test_is_independent.py Removes QNode cases from independence checks.
tests/math/test_init.py Preserves classical Autograd coverage in core.
tests/math/test_functions.py Tests interface rejection and JAX covariance gradients.
tests/logging/test_logging_jax.py Updates inputs and expected execution logs.
tests/liealg/test_lie_closure.py Preserves classical Autograd coverage in core.
tests/helpers/legacy_optimizer_native.py Adapts native derivatives for legacy optimizers.
tests/gradients/parameter_shift/test_parameter_shift_shot_vec.py Migrates inputs and custom-result differentiation checks.
tests/gradients/core/test_vjp.py Adds object and empty Jacobian regressions.
tests/gradients/core/test_fisher.py Migrates Fisher integration to retained frameworks.
tests/gradients/core/test_adjoint_diff.py Uses Torch for non-trainable-unitary checks.
tests/drawer/test_draw_mpl.py Uses trainable Torch drawing inputs.
tests/docs/test_supported_confs.py Removes Autograd from supported configurations.
tests/devices/test_qubit_device.py Adds scatter dtype and zero-fill coverage.
tests/devices/test_null_qubit.py Migrates gradient and Jacobian checks to Torch.
tests/devices/test_lightning_qubit.py Uses JAX integration parameters.
tests/devices/test_legacy_facade.py Uses Torch passthrough capabilities.
tests/devices/test_execution_config.py Tests rejection of Autograd configuration.
tests/devices/test_default_mixed.py Removes Autograd interface parametrizations.
tests/devices/qubit/test_simulate.py Updates supported interfaces and preservation checks.
tests/devices/qubit_mixed/test_qubit_mixed_simulate.py Removes Autograd interface parametrization.
tests/devices/default_qubit/test_default_qubit_preprocessing.py Migrates preprocessing gradient checks to JAX.
tests/devices/default_qubit/test_default_qubit_native_mcm.py Uses standard NumPy circuit parameters.
tests/core/test_cotransform_cache.py Tests retained interfaces and Torch trainability.
tests/core/operator/test_core_operator.py Routes classical Autograd coverage to core.
tests/conftest.py Removes Autograd from shared interface fixture.
pennylane/workflow/run.py Removes Autograd dispatch and cache selection.
pennylane/workflow/resolution.py Rejects inferred Autograd execution interfaces.
pennylane/workflow/qnode.py Documents retained execution interfaces.
pennylane/workflow/jacobian_products.py Updates interface references in docstrings.
pennylane/workflow/interfaces/torch.py Updates nested-result documentation.
pennylane/workflow/execution.py Documents NumPy execution and Torch differentiation.
pennylane/workflow/construct_batch.py Updates NumPy examples and expected batches.
pennylane/transforms/unitary_to_rot.py Migrates differentiation examples to JAX.
pennylane/transforms/defer_measurements.py Updates execution and differentiation examples.
pennylane/transforms/batch_partial.py Migrates differentiable batching examples to Torch.
pennylane/transforms/batch_params.py Migrates parameter-batching examples to Torch.
pennylane/testing/operators.py Uses JAX for differentiation validation.
pennylane/templates/subroutines/time_evolution/trotter.py Documents explicit JAX gradient arguments.
pennylane/templates/subroutines/time_evolution/qdrift.py Uses JAX differentiation example input.
pennylane/templates/subroutines/qpe.py Uses standard NumPy in example.
pennylane/templates/subroutines/qchem/uccsd.py Uses a native JAX optimization loop.
pennylane/templates/subroutines/qchem/kupccgsd.py Uses a native JAX optimization loop.
pennylane/templates/layers/random.py Uses standard NumPy example weights.
pennylane/templates/layers/gate_fabric.py Uses a native JAX optimization loop.
pennylane/templates/embeddings/qaoaembedding.py Documents JAX weight and feature optimization.
pennylane/shadows/transforms.py Migrates differentiable shadow example to Torch.
pennylane/shadows/__init__.py Migrates shadow-gradient example to Torch.
pennylane/pauli/conversion.py Uses JAX complex-gradient example.
pennylane/optimize/shot_adaptive.py Orders trainable argument indices consistently.
pennylane/ops/op_math/sum.py Migrates gradient example to JAX.
pennylane/ops/op_math/sprod.py Uses explicit native gradient arguments.
pennylane/ops/op_math/prod.py Migrates execution and gradient examples.
pennylane/ops/op_math/controlled.py Migrates gradient example to JAX.
pennylane/noise/mitigate.py Migrates mitigation gradients to Torch.
pennylane/measurements/vn_entropy.py Migrates entropy-gradient example to JAX.
pennylane/measurements/state.py Uses framework-aware math and JAX input.
pennylane/measurements/sample.py Migrates sample Jacobian examples to JAX.
pennylane/measurements/mutual_info.py Migrates gradient example to JAX.
pennylane/measurements/classical_shadow.py Migrates shadow differentiation examples to Torch.
pennylane/measurements/__init__.py Uses JAX measurement-gradient input.
pennylane/math/interface_utils.py Removes the canonical Autograd interface.
pennylane/gradients/fisher.py Removes Autograd Jacobian dispatch.
pennylane/drawer/draw.py Updates transformed-circuit drawing examples.
pennylane/devices/tracker.py Migrates gradient-tracking examples to Torch.
pennylane/devices/tests/test_measurements.py Uses JAX device-gradient comparisons.
pennylane/devices/tests/test_compare_default_qubit.py Migrates device comparison inputs to JAX.
pennylane/core/transforms/cotransform_cache.py Removes Autograd dispatch; filters Torch arguments.
pennylane/core/operator/base.py Updates NumPy examples and representations.
doc/releases/changelog-dev.rst Records native differentiation and interface removal.
.github/workflows/update-durations.yml Removes obsolete Autograd job exclusion.
.github/workflows/rerun-test.yml Removes Autograd rerun options.
.github/workflows/interface-unit-tests.yml Removes the dedicated Autograd CI job.

Review effort: Max

Comment thread pennylane/workflow/resolution.py Resolved
Comment thread tests/qchem/test_structure.py Outdated
Comment on lines +371 to +372
coeffs, ops = h.terms()
return qp.expval(qp.Hamiltonian(qp.math.toarray(coeffs), ops))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pennylane/optimize/shot_adaptive.py Resolved
Comment thread pennylane/testing/operators.py Resolved
Comment thread doc/releases/changelog-dev.rst Resolved
Comment on lines 244 to 246

elif interface == "autograd":
jac = jacobian(new_qnode)

else:
raise ValueError(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


H = qp.SparseHamiltonian(qp.X.compute_sparse_matrix(), wires=0)
x = qp.numpy.array(0.1)
x = torch.tensor(0.1, requires_grad=True)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/qchem/test_dipole.py Outdated
Comment on lines +263 to +264
coeffs, ops = d_qubit.terms()
return qp.expval(qp.Hamiltonian(qp.math.toarray(coeffs), ops))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pennylane/workflow/run.py
Comment on lines 93 to 94
config.gradient_keyword_arguments,
cache_full_jacobian=config.interface == Interface.AUTOGRAD,
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JerryChen97

Copy link
Copy Markdown
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants