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

Apparent bug when reading multiple nl files with different external function libraries #13

Open
Robbybp opened this issue Jun 25, 2023 · 0 comments

Comments

@Robbybp
Copy link

Robbybp commented Jun 25, 2023

First, thank you for maintaining this library. I am using ASL with a couple libraries of external functions. In a common workflow, I send several nl files to ASL in a sequence, each with its own set of libraries for external functions, which I communicate via the -i argument in the argv array passed to getstops. When an nl file's libraries include more libraries than the previous nl file, I get a function not available error message.

I have attached two nl files that can be used to produce this error: nlfiles.zip. The following code produces the error:

// asl_issue.cpp
#include <stdio.h>
#include <assert.h>
#include "asl_pfgh.h"
#include "getstub.h"

struct ASL_pfgh;
struct Option_Info;

int instantiate_asl(char *nlfile, char *amplfunc){
  printf("Instantiating ASL with file %s and amplfunc %s\n", nlfile, amplfunc);

  ASL_pfgh *asl = (ASL_pfgh *) ASL_alloc(ASL_read_pfgh);
  assert(asl);

  Option_Info* oi = new Option_Info;

  char *argv[] = { 
    (char *)"program_name",
    (char *)"-i",
    amplfunc,
    nlfile,
    NULL,
  };  
  char *stub = getstops(argv, oi);

  FILE *nl = jac0dim(stub, (int)strlen(stub));
  assert(nl);

  int ret = pfgh_read(nl, ASL_findgroups);

  delete oi; 

  return 0;
}

int main(){
  char nlfile1[] = "file1.nl";
  char amplfunc1[] = "/PATH/TO/.idaes/bin/cubic_roots.dylib";
  char nlfile2[] = "file2.nl";
  char amplfunc2[] = ( 
    "/PATH/TO/.idaes/bin/cubic_roots.dylib"
    "\n/PATH/TO/.idaes/bin/functions.dylib"
  );  

  int ret;
  ret = instantiate_asl(nlfile1, amplfunc1);
  ret = instantiate_asl(nlfile2, amplfunc2);

  return 0;
}

which is compiled with the following:

clang++ -o asl_issue \
    -I/PATH/TO/asl/src/solvers/sys.arm64.Darwin \
    asl_issue.cpp \
    /PATH/TO/asl/src/solvers/sys.arm64.Darwin/amplsolver.a

Here, amplsolver.a is compiled by running $ ./configure && make CFLAGS=-fPIC in the asl/src/solvers directory.

As the above suggests, I have prepared this example using Mac with Apple silicon. However, I have noticed this behavior on Linux as well (but have not tested the above example on Linux).
When I change the above code so that the first instantiate_asl call uses both function libraries, i.e.:

  int ret;
  ret = instantiate_asl(nlfile1, amplfunc2);
  ret = instantiate_asl(nlfile2, amplfunc2);

the program runs without error.

The nl files attached depend on libraries distributed by IDAES. They are typically downloaded by the idaes-pse Python package and put in the $HOME/.idaes/bin directory, via:

$ pip install idaes-pse
$ idaes get-extensions

Let me know if this is in fact a bug. I believe I am using the -i argument correctly.

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

1 participant