Skip to content

Material n and k caching causes RuntimeError in torch + grad_mode #484

@manuelFragata

Description

@manuelFragata

Checklist

  • I have searched the existing issues and discussions for a similar question or problem.
  • I have read the documentation and tried to find an answer there.
  • I am using the latest version of Optiland (if not, please update and retry).
  • I have tried to reproduce or debug the issue myself before opening this.
  • I have included all necessary context, such as version info, error messages, or minimal reproducible examples.

Thanks for taking the time to go through this — it really helps us help you!

Bug Report

Describe the bug
Material n / k caching causes RuntimeError under torch + grad mode

When using the torch backend with gradient tracking enabled, calling .backward() more than once during optimization raises the RuntimeError saying "Trying to backward through the graph a second time...".

To Reproduce
Run the torch optimization notebooks with the most recent optiland version, and you will get the RuntimeError

Expected behavior
Optimization should proceed.

Environment

  • Optiland Version: latest version

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions