Skip to content

Add Figure 2 QNTK diagnostics reproduction - #131

Open
ninjaduck7 wants to merge 1 commit into
tensorcircuit:masterfrom
ninjaduck7:reproduce-qntk-figure2
Open

Add Figure 2 QNTK diagnostics reproduction#131
ninjaduck7 wants to merge 1 commit into
tensorcircuit:masterfrom
ninjaduck7:reproduce-qntk-figure2

Conversation

@ninjaduck7

Copy link
Copy Markdown

Summary

  • add a self-contained TensorCircuit-NG reproduction of Figure 2 from
    "Towards Practical Quantum Neural Network Diagnostics with Neural Tangent
    Kernels" (arXiv:2503.01966)
  • include the four QNTK diagnostics for low/high-frequency HVA and HEA circuits
  • include gallery metadata and the generated Figure 2 output

Reproduction scope

The example uses the paper's 6-qubit transverse-field Ising regression task,
four QNN architectures, depths 5 through 30, and three fixed random
initializations. This reduced scope covers the portion visible on the paper's
approximately 620-parameter axis.

The implementation uses TensorCircuit-NG circuits, expectations, and PyTorch
automatic differentiation. It runs on CUDA when available and falls back to
CPU.

Results

The reproduction recovers the main Figure 2 behavior:

  • low-frequency circuits retain high test R2
  • high-frequency circuits approach test R2 near zero as depth increases
  • QNTK spectral and conditioning diagnostics separate the two regimes

Validation

  • all 72 configured reproduction points completed successfully
  • generated Figure 2 output is included in outputs/result.png
  • gallery metadata and generated gallery assets are included
  • Black check passed
  • Pylint passed with 10.00/10
  • Python compilation passed
  • gallery generation passed

Reproduction command

python examples/reproduce_papers/2025_qntk_diagnostics/main.py

Notes

The manuscript does not publish the VQE target table, initialization details,
observable choice, or an explicit feature-to-angle conversion. The example
documents these reconstruction choices and uses digitized VQE targets from the
paper’s vector dataset figure.
Closes #98

@refraction-ray

Copy link
Copy Markdown
Member

Thanks for the contribution, the following are some suggestions

Critical: wrong expectation observable

examples/reproduce_papers/2025_qntk_diagnostics/main.py:147-159 evaluates expectation_ps(z=[0]), while the paper’s TFIM target is the
transverse magnetization (\langle\sigma_X\rangle).

This means the script computes the QNTK of a different model.

Performance/reproducibility suggestion: make the script backend agnostic

The script currently hard-codes PyTorch through torch.func.jacrev, torch.as_tensor, device setup, and tensor conversion. Move these
operations to tc.backend:

  • tc.backend.convert_to_tensor
  • tc.backend.jacrev
  • tc.backend.vmap
  • tc.backend.jit

Then expose a backend option for identical JAX/PyTorch runs. The benchmark should report JAX compilation time separately from steady-
state execution time and use identical precision, seeds, circuit depths, and encoding scale. The current Python loop in batch_outputs
should be replaced by backend vmap.

@ninjaduck7
ninjaduck7 force-pushed the reproduce-qntk-figure2 branch from b5a5fc3 to 272271f Compare September 2, 2026 15:05
@ninjaduck7

Copy link
Copy Markdown
Author

Thanks for the detailed review. I have pushed an update in commit 272271f.

  • Corrected the observable from expectation_ps(z=[0]) to
    expectation_ps(x=[0]), matching the transverse-X target.
  • Replaced direct PyTorch tensor/device handling with TensorCircuit backend
    APIs, including convert_to_tensor, vmap, and jit.
  • Added a --backend jax|pytorch option.
  • Kept the same precision, seeds, depths, inputs, and encoding scale for
    comparable backend runs.

JAX uses tc.backend.jacrev. For reproducibility, the tests used
TensorCircuit-NG 1.9.1 and PyTorch 2.7.1+cu128. The PyTorch
tc.backend.jacrev failure is not CUDA-specific: the same minimal test
fails on both CPU and CUDA. In TCNG 1.9.1, jacrev combines vmap with a
PyTorch backend vjp implemented through torch.autograd.functional.vjp,
which is incompatible with functorch transforms. Therefore, the PyTorch
path uses the equivalent tc.backend.grad transform for this scalar-output
Jacobian.

Validation completed:

  • PyTorch backend: 72/72 configured points completed successfully.
  • Representative JAX/PyTorch parity checks covered all four architectures.
  • Maximum output and Jacobian differences were below 5e-16.
  • The benchmark uses identical precision, seed, depths, and encoding scale,
    and reports JAX compilation separately from steady-state execution.
  • No TensorCircuit-NG core source files were modified.

The scalar observable is currently the representative first-qubit
transverse-X expectation (X_0). If the intended observable is the
normalized six-qubit average of all X expectations, please let me know.

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.

Reproduce 2503.01966

2 participants