Skip to content

Tweaks to demo - error I don't understand#3

Open
mohawk2 wants to merge 2 commits into
jtrujil43:mainfrom
mohawk2:demo-tweak
Open

Tweaks to demo - error I don't understand#3
mohawk2 wants to merge 2 commits into
jtrujil43:mainfrom
mohawk2:demo-tweak

Conversation

@mohawk2
Copy link
Copy Markdown

@mohawk2 mohawk2 commented May 23, 2026

These changes are hopefully self-explanatory and slightly improve the code. But on running the demo (in order to add it to the website, as discussed), it's giving:

OOPS!!! Something went wrong, please make a bug report!: lu_backsub: LU decomposition is undef -- probably from a singular matrix.
 at lib/PDL/MatrixOps.pd line 1175.
	PDL::MatrixOps::lu_backsub(undef, undef, undef, PDL=SCALAR(0xb90677060)) called at (path)/PDL/Fit/LM.pm line 124
	PDL::lmfit(PDL=SCALAR(0xb907a3498), PDL=SCALAR(0xb907b2060), PDL=SCALAR(0xb9079ebb8), CODE(0xb8f14a5b8), PDL=SCALAR(0xb90674dc8), HASH(0xb9079e990)) called at (path)/blib/lib/Physics/Ellipsometry/VASE.pm line 173
	Physics::Ellipsometry::VASE::fit(Physics::Ellipsometry::VASE=HASH(0xb907a9c00), PDL=SCALAR(0xb90674dc8)) called at (eval 187) line 31
	eval 'package main; no strict; use PDL; 
  # Fit the multi-layer model to the real 3-angle VASE data
  $ml_vase->set_model(\\&multilayer_model);
[...]

The error is in this bit:

      print "  LM from grid best did not converge, trying refined guess...\n";
      $ml_fit = $ml_vase->fit(pdl [2.12, 1.8, 0.1, $best_d, 1.0, 0.50]);

Before throwing the exception, it reported:

---- Output:
Grid search: best thickness = 230 nm (d_s = 2.30)
Fitting with LM refinement...
  LM from grid best did not converge, trying refined guess...

It may be necessary to add more error-catching in PDL::Fit::LM so it's caught a bit more clearly, and/or prints out the data it had an error with. Let me know if so.

@mohawk2 mohawk2 mentioned this pull request May 23, 2026
@mohawk2
Copy link
Copy Markdown
Author

mohawk2 commented May 23, 2026

A further issue comes from the point I mentioned in our emails: I believe it would be a good idea (and I hope pretty easy) to make a PDL::IO::Ellipsometry module in this distro. The immediate problem I'm having is, when I try to regenerate the website, it transforms the demo text into this:

DOING (package PDL::Demos::Ellipsometry; *do_output=\&main::do_output; sub do_output; no strict; use PDL;
  ($fh, $tmpfile) = tempfile(SUFFIX => '.dat', UNLINK => 1);
do_output + $fh "# Wavelength(nm) Angle(deg) Psi(deg) Delta(deg)\n";
  for my $i (0 .. $wavelength->nelem - 1) {
do_output sprintf $fh "%.1f  %.1f  %.4f  %.4f\n",
          $wavelength->at($i), $angle->at($i),
          $psi->at($i), $delta->at($i);
  }
  close $fh;

  $vase = Physics::Ellipsometry::VASE->new(layers => 1);
  $data = $vase->load_data($tmpfile);

Because the not-very-clever heuristic wants to change print into a call to the output-capture function, do_output. If you were writing to your tempfile with a completely separate function not defined in the demo, it wouldn't have a problem. The problem it is getting here is the file-handle, which is only valid for real print, and in any case I wouldn't want to capture that here.

Separately, is there another way to get data loaded without going via a file? That feels like a further way to improve this situation.

@jtrujil43
Copy link
Copy Markdown
Owner

Yes for the demo I should put the sample data in the code itself. Will do that in the next iteration.

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