Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with low_level interface example #347

Open
timothyara opened this issue Sep 22, 2023 · 13 comments
Open

Help with low_level interface example #347

timothyara opened this issue Sep 22, 2023 · 13 comments

Comments

@timothyara
Copy link

Hello,
I'm running the mixture_modeAvg under mixtures in the low_level interface but I seem to be getting this error: PyError ($(Expr(:escape, :(ccall(#= /Users/timothyaraujo/.julia/packages/PyCall/ilqDX/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'ValueError'>
ValueError('x and y must have same first dimension, but have shapes (1345,) and (2, 1345)')
File "/Users/timothyaraujo/.julia/conda/3/aarch64/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 1721, in plot
lines = [*self._get_lines(self, *args, data=data, **kwargs)]
File "/Users/timothyaraujo/.julia/conda/3/aarch64/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 303, in call
yield from self._plot_args(
File "/Users/timothyaraujo/.julia/conda/3/aarch64/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 499, in _plot_args
raise ValueError(f"x and y must have same first dimension, but " ...
Can I get some help with this? It would also be nice if there were some comments or some documentation that explains how the simulation parameters are being set. I'm specifically interested in spectrum of a 800nm, 30 fs, few mJ pulse after passage of an Ar filled, few mm diameter hollow core fiber. So, I'm most interesting in the gas pressure needed to obtain a supercontinuum. I'm attaching the code in the zipped file which is in the state that I ran it.
Archive.zip

Thanks.

@omairg
Copy link

omairg commented Sep 25, 2023

Hi, I just came across your post while trying to use this package. I think your error message was due to an error in the stats plotting tool as I got the code to run by commenting out line 47, i.e. # Plotting.stats(output). Since the Luna package is still an early release (v0.3) I think they might have made changes to this plotting routine that broke it for this case. From your question, i think you might just want to simulate spectral broadening in a single hollow-core fiber which you can do using the simple_interface examples, i.e. the first part of the 2 stage_compressor. I think these will only work with single gases rather than mixtures but you will probably be able to find condition in which to make a supercontinuum without using a mixture, which is probably best as making gas mixtures is an extra step of hassle in real-life as well.
hope this helps

@chrisbrahms
Copy link
Collaborator

@omairg is mostly correct. The issue here is that for a gas mixture, the density statistic which is being collected is multidimensional (number of gases x propagation steps). The statistics plotting routine can't deal with that at the moment. If you need this functionality, we can add it.

From what you're saying, @omairg is also correct in suggesting that the simple interface will do the job for you, and this has been more thoroughly tested (and the examples should all be up to date).

Regarding parameter settings, are you asking how to make Luna run a simulations for exactly the numbers you want, or how to choose the gas pressure? If the former isn't clear, do ask and we can help and add to the documentation where needed (I'm aware that the docs are woefully incomplete--at the moment we simply don't have the time to write more of it). The latter is a much more complicated question which would turn the documentation into a physics paper. Happy to help in choosing parameters, but there is no one recipe which will work to get the output you need.

@timothyara
Copy link
Author

@omairg @chrisbrahms Thanks for the help! I'm running the 2 stage compressor program and it's doing everything I need it to do. I did add a line to it at the ending (Plotting.spec_2d(compressor, log10=true) to plot the spectrum but for some reason I'm getting duplicate spectrum plots for the He11 mode even though I set modes = 1. Any idea what is causing this? Also, is there any way to export the plots as a jpeg or png?

@timothyara
Copy link
Author

I would also like to know if for the 2 stage compressor does the simulation assume that the FWHM of the pulse is matched to the core fiber diameter?

@omairg
Copy link

omairg commented Sep 26, 2023

hi, I;m not sure about the reasons why you are getting multiple plots, bu there is a built in command in the matplotlib library for saving figures, you would use it as follows where savename is a string that you want to save with. I think the type of file depends on the extension you give it.
Plotting.plt.savefig(savename * "_.png").

Since you are probably new to Julia, i have been finding that the free bing chatGPT is usefull for providing information on how to do things in both Julia and Python, although it does get things wrong.

My understading of the code is that the energy you give the code is the starting energy in the lowest order mode of the HCF, this is a pretty good assumption because when the pulse diameters are matched then the coupling to that modes is >98% and less than a few percent for the other modes. however this is for an ideal Gaussian mode coupling the lowest order Bessel mode of the fiber. However in real life, their might be astigmatism etc that will cause the coupling efficiency to be less.
Regards

@chrisbrahms
Copy link
Collaborator

@omairg @chrisbrahms Thanks for the help! I'm running the 2 stage compressor program and it's doing everything I need it to do. I did add a line to it at the ending (Plotting.spec_2d(compressor, log10=true) to plot the spectrum but for some reason I'm getting duplicate spectrum plots for the He11 mode even though I set modes = 1. Any idea what is causing this? Also, is there any way to export the plots as a jpeg or png?

The double plot is because by default, the prop_2D command produces one figure for each mode and additionally one figure for the sum of all modes. Because you only have one mode, these are identical. I suppose we should check for this and avoid double plotting if it's not required... To turn this off, you can set a modes keyword argument to select figures, for example prop_2D(compressor; modes=:sum) will only plot the sum figure and prop_2D(compressor; modes=1) only the first mode (in your case these are identical of course).

@omairg's way to save the figure works, but it will save the current figure which isn't always the one you want. The plotting function also returns the figure object, which you can then save:

fig = Plotting.prop_2D(...)
fig.savefig("test.png")

will save the figure as PNG. The API for savefig is identical to the matplotlib one (because that's what is being used under the hood here).
Alternatively, the figure itself should have a save button at the bottom left:
image

I would also like to know if for the 2 stage compressor does the simulation assume that the FWHM of the pulse is matched to the core fiber diameter?

By default, a LunaPulse transfers all the modes 1-to-1 from one waveguide to the next, i.e. it assumes perfect re-imaging of the output of the first waveguide onto the entrance face of the second. The default for the first waveguide is coupling purely to the fundamental mode as @omairg said already. The only other option we've currently got implemented in the simple interface is to assume a Gaussian beam with some radius (and perfectly flat phase), see GaussBeamPulse.

@omairg
Copy link

omairg commented Sep 27, 2023

Thanks @chrisbrahms,you learn something new each day, hope you don't mind me trying to help with advice, just to mirror Martin's comments, this is a really usefull package to have open-sourced, and it's seems especially suited to experimentalists, so thanks for putting in the work.

@timothyara
Copy link
Author

@chrisbrahms @omairg Is there a way to implement a hollow core fiber with a gas pressure distribution (ie one that varies with the propagation distance along the fiber)? I appreciate the help!

@omairg
Copy link

omairg commented Sep 28, 2023

@timothyara Hi, the documentation page for the prop_capillary function explains how to do this, it just involves entering a tuple for the pressure rather than a single value,
http://lupo-lab.com/Luna.jl/dev/interface.html#Luna.Interface.prop_capillary-Tuple.
To check the actual density is correct you can use the Plotting.stats() function which has a density plot as one of it's outputs. Generally the code includes a lot of these type of statistics with the output class in a variable called "stats". To see the keys for the data that is stored you can type the following command:
println(keys(output["stats"]))

@timothyara
Copy link
Author

@omairg @chrisbrahms
Hello,
Is there an example of using GaussPulse and GaussBeamPulse for use with prop_capillary(...)? I attempted using GaussPulse in my low level interface 2 stage compressor code but I'm getting an error "GaussPulse not defined" when I ran the code. My understanding is I need to use the two together to specify a waist (beam radius) and a duration of the pulse. The reason I'm trying to implement this into the 2 stage compressor is to determine waist size that will best couple the pulse into the hollow core fiber entrance that way I can get an idea for what particular focal length and f# I will need in the experiment. I'm attaching a screenshot of the portion of the code that I think is causing me problems where I'm attempting to pass in the GaussBeamPulse into prop_capillary.
HCFscreenshot

Thank you !!

@omairg
Copy link

omairg commented Oct 4, 2023

Hi Timothy, I'm not really familiar with these low level bits of Luna, but i think it isn't really necessary to do a calculation for what you want to know. If you are transferring one HCF mode to another fiber mode with a different diameter, then you only need to make sure your optical imaging system has an appropriate magnification/demagnification according to the ratio of the diameters of the fibers you are using. i.e. if the diameters were the same then you would choose lenses that would image the end of one HCF 1:1 onto the entrance of the other HCF. This should give you optimal coupling assuming a perfect imaging system, because the fundamental modes have the same profile but just will have different sizes depending on the fiber diameter.
This a link to a paper which covers some of the coupling conditions and losses for the initial coupling of a Gaussian Laser mode to the Bessel Modes of a hollow-core fiber, https://doi.org/10.1117/1.601768 . In case you don't have access, i'm attaching a calculation i made at some point of the coupling. nb. sorry the axes aren't well labelled and my notation for the modes is probably not right, 1.0 = 100% transmission on the y-axis. The x-axis, is the ratio of $\frac{\omega}{a}$, where $\omega$ is the standard definiton of the size of a Gaussian laser beam, i.e. the 1/$e^{2}$ radius, and $a$ is the bore radius. the optimal coupling occurs when this ratio is 0.64, with a coupling of > 98% to the lowest order mode (blue). The other higher modes (m >1) should correspond to the other modes of the multi-mode option of Luna. As you can see, when the initial laser beam spot is chosen for good coupling, the energy transmitted to the higher order modes is negligible. Hopefully, Chris will correct me if i'm wrong. Regards

HEm Couplings

@timothyara
Copy link
Author

Thanks for your response @omairg . I will keep this condition for optimal coupling of Gaussian to Bessel mode of fiber in mind when designing my optical setup. I'm still interested in specifying more details about the beam (i.e gaussian,fwhm, wo, etc) to see if it has any impact on the results of the simulation. So, I'm still seeking resources/examples that show me how to do this.

@chrisbrahms
Copy link
Collaborator

The GaussPulse not defined error is caused by the fact that Luna doesn't directly export that variable, so using Luna doesn't make it available. Get it from the Pulses module instead:

gb = Pulses.GaussPulse(...)
gbp = Pulses.GaussBeamPulse(...)

Two other notes:

  1. In your screenshot you specify all of the arguments to GaussPulse, but you don't always need to do that--everything that isn't required will default to the sensible standard values.
  2. Your code will throw another error in the last line, because you're trying to pass in gbp as a keyword argument. What you need here is pulses=gbp instead. (For more details on when you can leave out the = for keyword arguments, see the relevant page in the Julia docs)

Also, just for future reference: when posting code to an issue, it's much easier to help you if you copy&paste the code as text (in a code block, see the GitHub docs) rather than a screenshot. Saves me typing it back in to run it myself 😃

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

No branches or pull requests

3 participants