How do I fix a problem of a solution directory that is not found in GEKKO for optimization - gekko

This is about a programming model that is correct, because it sometimes gives solutions, but sometimes (even for simple optimization problems) I get a directory problem.
from gekko import GEKKO
m = GEKKO()
x = m.Var()
y = m.Var()
m.Equations([3*x+2*y==1, x+2*y==0])
m.solve(disp=False)
print(x.value,y.value)
The error message printed is:
Error: 'results.json' not found. Check above for additional error details.
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\pc\\AppData\\Local\\Temp\\tmpdwyu_skngk_model0\\options.json'
How could I fix this problem? I think it has nothing to do with the model, it's a general problem.

How often does this error occur? Gekko uses a temporary folder to store files in text format, transfer those files to a remote server for solution, and retrieve the solution from the server. If there is an intermittent Internet connection problem then I recommend that you use a local mode where it does not rely on an Internet connection. To use the local mode (available for MacOS, Raspberry Pi ARM Linux, Linux, and Windows), change the remote option to False as:
m = GEKKO(remote=False)
If you still get an error and can provide a reproducable bug report, please submit a new issue on GitHub.

I m already using the local mode (m = GEKKO(remote=False)) but still have the error . The error occurs frequently. when I run the code and I have this error, if run it a second and a third time ... It works in n th time but, I dont now hat to do, so it works from te first time

Related

Pytorch : W ParallelNative.cpp:206

I'm trying to use a pre-trained template on my image set by following the tutorial right here :
https://pytorch.org/tutorials/beginner/finetuning_torchvision_models_tutorial.html
Only I always get this "error" when I run my code and the console locks up :
[W ParallelNative.cpp:206] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
Thank you in advance for your help,
I have the same problem.
Mac. Python 3.6 (also reproduces on 3.8). Pytorch 1.7.
It seems that with this error dataloaders don't (or can't) use parallel computing.
You can remove the error (this will not fix the problem) in two ways.
If you can access your dataloaders, set num_workers=0 when creating a dataloader
Set environment variable export OMP_NUM_THREADS=1
Again, both solutions kill parallel computing and may slow down data loading (and therefore training). I look forward to efficient solutions or a patch in Pytorch 1.7

mclapply and spark_read_parquet

I am relatively new as active user to the forum, but have to thank you all first your contributions because I have been looking for answers since years...
Today, I have a question that nobody has solved or I am not able to find...
I am trying to read files in parallel from s3 (AWS) to spark (local computer) as part of a test system. I have used mclapply, but when set more that 1 core, it fails...
Example: (the same code works when using one core, but fails when using 2)
new_rdd_global <- mclapply(seq(file_paths), function(i){spark_read_parquet(sc, name=paste0("rdd_",i), path=file_paths[i])}, mc.cores = 1)
new_rdd_global <- mclapply(seq(file_paths), function(i){spark_read_parquet(sc, name=paste0("rdd_",i), path=file_paths[i])}, mc.cores = 2)
Warning message:
In mclapply(seq(file_paths), function(i) { :
all scheduled cores encountered errors in user code
Any suggestion???
Thanks in advance.
Just read everything into one table via 1 spark_read_parquet() call, this way Spark handles the parallelization for you. If you need separate tables you can split them afterwards assuming there's a column that tells you which file the data came from. In general you shouldn't need to use mcapply() when using Spark with R.

Invalid file identifier error in Matlab loop

If I run the example code below, I get an invalid file identifier error in Matlab:
for i = 1:99999
fid = fopen('test.txt','w');
fprintf(fid,'%s', 'Hello World!\r\n');
fclose(fid);
delete('test.txt');
end;
??? Error using ==> fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
The interesting thing is, that if I decrease the number of loops, I don't get the error. I researched the problem, and it seems that none of the usual issues that cause the error (Wrong File Path, Corrupt File, File doesn't exist, File already in use) are the culprits, because it works if I change the loops to 10 instead of 99999.
Upon further research, Matlab Forum Post, it seems the problem might be quota related (I think quotas have to do with the OS where the OS, Windows 10 in my case doesn't allow a program to write files after a certain amount of them have been written by the same program?).
How would one increase the quota? Is there a work around? I use Matlab 2010a on Windows 10.
I have also attempted running Matlab in administrator mode with no success.
I'm assuming permissions are correct and disk space is not a problem, but you should check fopen's output nevertheless to get more info or some try-catch which calls ferror(fid) for additional data (note the absence of the semicolon, obviously).
[fid,msg]=fopen('test.txt','w')
If it IS quota related you should be able to disable it in your hard drive's properties, as shown in the image below (it's in spanish, but you should get the idea). Just right click in the unit and access Properties->Disk Quota->Show Configuration and disable it if it isn't already.
GUI location of the disk quota

How to run PATCHMATCH source code

I would like to inpaint one image with a corrupted part using the patches of another image. in the link below, the authors of PATCHMATCH algorithm has provided the users with the source code. PATCHMATCH algorithm tries to find the nearest patch in the second image to fill the corrupted patches in the first image.
main page of the paper with source code:
http://gfx.cs.princeton.edu/pubs/Barnes_2009_PAR/index.php
and the link of source code:
http://www.cs.princeton.edu/gfx/pubs/Barnes_2009_PAR/patchmatch-2.1.zip
My problem is that I followed the instruction in the readme.txt file and ran build_unix.sh in terminal of Ubuntu 14.04 LTS,but got an error which says:
Unknown MEX argument '-inline'.
Unknown MEX argument '-inline'.
I removed -inline and execute the bash file in terminal and fortunately it worked and got this message:
MEX completed successfully.
MEX completed successfully.
Now my question is how to use this code to inpaint one image corrupted partially by using another image which comes from the same class (e.g.class)
For example:
I do really appreciate it if you could help me out of this problem. I am really in the need of help and have to make this source code run.
I will provide you with more information if needed.
Update: I have come up with an inpainting algorithm using Convolutional Neural Networks, which you can see the result below, I'd like to implement patchmatch algorithm to compare my result with this algorithm. CNN only gets corrupted image as input.

UnauthorizedAccessException on MemoryMappedFile in C# 4

I wanted to play around with using a MemoryMappedFile to access an existing binary file. If this even at all possible or am I a crazy person?
The idea would be to map the existing binary file directly to memory for some preferably higher-speed operations. Or to atleast see how these things worked.
using System.IO.MemoryMappedFiles;
System.IO.FileInfo fi = new System.IO.FileInfo(#"C:\testparsercap.pcap");
MemoryMappedFileSecurity sec = new MemoryMappedFileSecurity();
System.IO.FileStream file = fi.Open(System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
MemoryMappedFile mf = MemoryMappedFile.CreateFromFile(file, "testpcap", fi.Length, MemoryMappedFileAccess.Read, sec, System.IO.HandleInheritability.Inheritable, true);
MemoryMappedViewAccessor FileMapView = mf.CreateViewAccessor();
PcapHeader head = new PcapHeader();
FileMapView.Read<PcapHeader>(0, out head);
I get System.UnauthorizedAccessException was unhandled (Message=Access to the path is denied.) on the mf.CreateViewAccessor() line.
I don't think it's file-permissions, since I'm running as a nice insecure administrator user, and there aren't any other programs open that might have a read-lock on the file. This is on Vista with UAC disabled.
If it's simply not possible and I missed something in the documentation, please let me know. I could barely find anything at all referencing this feature of .net 4.0
Thanks!
I know this is an old question, but I just ran into the same error and was able to solve it.
Even though I was opening the MemoryMappedFile as read-only (MemoryMappedFileRights.Read) as you are, I also needed to create the view accessor as read-only as well:
var view = mmf.CreateViewAccessor(offset, size, MemoryMappedFileAccess.Read);
Then it worked. Hope this helps someone else.
If the size is more than the file length, it gives the UnAuthorized Access exception. Because we are trying to access memory beyond the limits of the file.
var view = mmf.CreateViewAccessor(offset, size, MemoryMappedFileAccess.Read);
It is difficult to say what might be going wrong. Since there is no documentation on the MSDN website yet, your best bet is to install FILEMON from SysInternals, and see why that is happening.
Alternately, you can attach a native debugger (like WinDBG) to the process, and put a breakpoint on MapViewOfFile and other overloads. And then see why that call is failing.
Using the .CreateViewStream() from the instance of MemoryMappedFile removed the error from my code. I was unable to get .CreateViewAcccessor() working w/the access denied error

Resources