POJO compilation fails (Algo: GBM, H2o-Version 3.8.1.3, Javac: 1.8.0_45, Mac OSX 10.11.3 / Fedora 23) - javac

I try to locally compile a POJO of a GBM prediction model generated with H2o 3.8.1.3; I follow the instructions in the POJO class:
create a folder
Download the h2o-genmodel.jar into the folder with:
curl http://myh2oinstancesurl:myh2oinstancesport/3/h2o-genmodel.jar > h2o-genmodel.jar
Download the successfully trained GBM model named 154 into the folder with:
curl http://myh2oinstancesurl:myh2oinstancesport/3/Models/154/java > 154.java
Compile the sources in the folder with javac 1.8.0_45 under Max OSX 10.11.3 or Fedora 23:
javac -cp h2o-genmodel.jar 154.java
Result are a bunch of compilation errors:
154.java:24: error: <identifier> expected
public class 154 extends GenModel {
^
154.java:24: error: illegal start of type
public class 154 extends GenModel {
^
154.java:24: error: ';' expected
public class 154 extends GenModel {
^
154.java:25: error: illegal start of expression
public hex.ModelCategory getModelCategory() { return hex.ModelCategory.Binomial; }
^
154.java:25: error: ';' expected
public hex.ModelCategory getModelCategory() { return hex.ModelCategory.Binomial; }
^
154.java:27: error: illegal start of expression
public boolean isSupervised() { return true; }
^
154.java:27: error: ';' expected
public boolean isSupervised() { return true; }
^
154.java:28: error: illegal start of expression
public int nfeatures() { return 14; }
^
154.java:28: error: ';' expected
public int nfeatures() { return 14; }
^
154.java:29: error: illegal start of expression
public int nclasses() { return 2; }
^
...
100 errors
Is there an issue with my procedure? Or is this a bug with my setup? Is there anybody who currently can compile GBM POJOs? Thanks for your responses!

Solved: The problem was that the POJO class name obviously has to be a valid java class name; a purely numeric name is not allowed. Changing the model name resolves the issue.

[ This is not a direct answer to the question, but hopefully a helpful pointer to anyone that finds this question... ]
Since this question was asked, H2O has also added the ability to export a MOJO and use it for making predictions.
An H2O POJO is a code representation of a model, and an H2O MOJO is a data representation of a model.
A MOJO can be used in the same way as a POJO, and MOJOs do not need to be compiled (they are interpreted instead). This is especially useful for very large tree models, where trying to compile them has various technical challenges around gigabytes of code size. So in many cases, the best way to address a compilation issue is to not compile at all.
The online documentation for both H2O POJOs and MOJOs can be found here:
http://docs.h2o.ai/h2o/latest-stable/h2o-genmodel/javadoc/index.html
I hope people find this (delayed) answer helpful.

Related

Is there solution to run this fuction that make say 'Hello' in complier in Dart language

This is the Dart code I made to practice functions:
String sayHello(String name,int age,String country){
print("Hello im $name , $age year old, come from $country");
}
void main()
{
sayHello('king',22,'us');
}
And the error I am getting is:
Error compiling to JavaScript:
Info: Compiling with sound null safety
lib/main.dart:1:9:
Error: A non-null value must be returned since the return type 'String' doesn't allow null.
String sayHello(String name,int age,String country){
^
Error: Compilation failed.
I referenced lots of function grammar about Dart but it didn't work.
My compiler was DartPad. Can I know where is the wrong grammar in my code?
In Dart, this error message indicates that the function may return without a value, even though you declared the function to return a String value.
Just change the return type to void
void sayHello(String name,int age,String country){
print("Hello im $name , $age year old, come from $country");
}

hhvm issues \nFatal error: Uncaught Error: unknown class xhp_x__element in :\nStack trace:\n#0 /Users/user/code/xhp-js-example/example.php(12)

I'm trying to play with xhp and I'm finding that running the one xhp example I could find https://github.com/hhvm/xhp-js-example is issuing an error \nFatal error: Uncaught Error: Found top-level code in :\nStack trace:\n#0 {main} when following the README as is on HHVM 4.71. Removing require_once(__DIR__.'/vendor/autoload.php'); resolves the top-level code error but I'm now stuck with the error \nFatal error: Uncaught Error: unknown class xhp_x__element in :\nStack trace:\n#0 /Users/user/code/xhp-js-example/example.php(12): <unknown>()\n#1 {main}. I've tried to change the code in example.php to the one found here:
class :introduction extends :x:element {
protected function render(): \XHPRoot {
return <strong>Hello!</strong>;
}
}
class :intro-plain-str extends :x:element {
protected function render(): \XHPRoot {
// Since this function returns an XHPRoot, if you want to return a primitive
// like a string, wrap it around <x:frag>
return <x:frag>Hello!</x:frag>;
}
}
echo <introduction />;
echo PHP_EOL.PHP_EOL;
echo <intro-plain-str />;
since that didn't work, I also tried the simple example from here:
<?hh // strict
$user_name = 'Fred';
echo <tt>Hello <strong>{$user_name}</strong></tt>;
but altered to resolve the top-level error by wrapping it in a function and annotating it as follows:
<?hh // strict
<<__EntryPoint>>
function main(): void {
$user_name = 'Fred';
echo <tt>Hello <strong>{$user_name}</strong></tt>;
}
I'd get a very similar error \nFatal error: Uncaught Error: Class undefined: xhp_tt in /Users/user/code/xhp-js-example/example.php:6\nStack trace:\n#0 (): main()\n#1 {main}
Any help with getting these seemingly simple examples to work would be much appreciated since it's very painful and discouraging for trying this tech when the basic examples don't seem to run. this is using the macos package of hhvm on Catalina.
EDIT: I've also tried this without the use of xhp-js, which is included in the example repo and am getting the same error message.
There are a few roadblocks that the OP encountered to get XHP running with HHVM 4.62, as discussed in the comments.
xhp-js and xhp-js-example are both outdated by a few years so they can't compile due to breaking changes to HHVM itself, as the OP saw.
While the XHP syntax is built into Hack, all the standard implementations are provided by xhp-lib, so it is necessary to autoload that in order to use the standard library of tags and tag classes.
New to HHVM 4.62 is mandatory FIXME whitelisting, which requires package writers to explicitly specify allowed HH_FIXME codes in the .hhconfig. These were added to XHP-lib in 4.0.0rc1, so this version is necessary when running on HHVM 4.62.
Therefore, a minimal project with XHP on 4.62 looks like this:
composer.json
{
"require": {
"hhvm": "~4.62",
"hhvm/hhvm-autoload": "^3.1.3",
"facebook/xhp-lib": "~4.0.0rc1"
}
}
hh_autoload.json
{ "roots": [ "src/" ] }
src/example.hack
require_once(__DIR__ . "/../vendor/hh_autoload.hh");
<<__EntryPoint>>
function main(): void {
echo <div>{1 + 2}</div>;
}

How to stop clang AST misinterpreting this type of function declaration as a variable declaration?

I am using clang's abstract syntax tree generation to generate an AST for some source files. It maps out normal functions great, however it trips up on some functions, mislabeling them as variable declarations. When it does this it waits for a semicolon to finish this declaration and so does not map out the rest of the source file following the problem function. Is there a way to make clang realize that it's a function definition, not a variable declaration?
I put a semicolon after the function definition and doing that makes clang ignore the contents of the function, but at least it generates nodes for the code following it in the source file. I'm using the prophy python interface to interact with clang in my scripts, but ran clang manually and found the same thing.
This is an example of a function that clang does map:
int killProcess(int pid)
{
int ret=1;
HANDLE pHandle;
if ((pHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid)) != NULL)
if(!TerminateProcess(pHandle,0)) {
ret=0;
CloseHandle(pHandle);
}
return ret;
}
This is an example of a function which clang thinks is a variable declaration and ignores everything after it if there is no semicolon after the closing brace:
DWORD WINAPI listProcessesThread(LPVOID param)
{
char sendbuf[IRCLINE];
LPROC lproc = *((LPROC *)param);
LPROC *lprocp = (LPROC *)param;
lprocp->gotinfo = TRUE;
sprintf(sendbuf,"[PROC]: Listing processes:");
if (!lproc.silent) irc_privmsg(lproc.sock,lproc.chan,sendbuf,lproc.notice);
if (listProcesses(lproc.sock,lproc.chan,lproc.notice,NULL, FALSE, lproc.full) == 0)
sprintf(sendbuf,"[PROC]: Process list completed.");
else
sprintf(sendbuf,"[PROC]: Process list failed.");
if (!lproc.silent) irc_privmsg(lproc.sock, lproc.chan, sendbuf, lproc.notice);
addlog(sendbuf);
clearthread(lproc.threadnum);
ExitThread(0);
}
The expected results would be that clang knows that this is a function and generates a corresponding AST, however it doesn't. It constructs a VAR_DECL node with the spelling "WINAPI" instead of a "FUNCTION_DECL" node. The error it gives upon running "clang -cc1 -ast-dump processes2.cpp" is:
`-VarDecl 0x5625ad7ab2e0 col:7 invalid WINAPI 'int'
1 error generated.
At the end of its log. The abstract syntax tree up until this point is generated and displayed.
NB: I do not have WINAPI library installed because I am working on a Ubuntu machine.

Ignore Varargs Warnings In Javac

I want to escalate the missing serialversionUID warning to an error and fail my build when it occurs in javac.
I have added the following to my ant task:
<compilerarg value="-Xlint:serial"/>
<compilerarg value="-Werror"/>
However, the build also fails with varargs warnings:
non-varargs call of varargs method with inexact argument type for last parameter;
cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this warning
I tried changing the javac task to
<compilerarg value="-Xlint:-varargs"/>
<compilerarg value="-Xlint:serial"/>
<compilerarg value="-Werror"/>
However, it made no difference. How do I make the compiler ignore these warnings and only fail on the serialversionUID?
I am using Ant 1.9.4 and tried with Javac 1.6u37, 1.7u79 and 1.8u92
Example class:
package com.stackoverflow.compiler;
import java.io.Serializable;
public class Main implements Serializable {
public static void foo(Object... args) {
System.out.println("Test foo");
}
public static void main(String[] args) {
// is args supposed to be an array of objects
// or the only element in an array?
foo(args);
}
}
It seems that the warning you have is not related to the -Xlint:varargs option
According to javac reference the varargs option for -Xlint:
Warns about unsafe usages of variable arguments (varargs) methods, in particular, those that contain non-reifiable arguments
The documentation says that the following code:
public class ArrayBuilder {
public static <T> void addToList (List<T> listArg, T... elements) {
for (T x : elements) {
listArg.add(x);
}
}
}
should produce the warning:
warning: [varargs] Possible heap pollution from parameterized vararg type T
The actual warning I get (using javac 1.8.0_65) is:
warning: [unchecked] Possible heap pollution from parameterized vararg type T
(i.e unchecked instead of varargs)
The warning you got can be caused by code like this:
public static void foo(Object... args) {...}
public static void main(String[] args) {
// is args supposed to be an array of objects
// or the only element in an array?
foo(args);
}
That warning went away only using -Xlint:none option, but then -Xlint:serial does nothing. So it seems what you want is not possible.
I know the question is about javac, but let me still mention that ecj can be configured to meet your requirement: simply say -err:serial on the command line.
With that option this source file
public class Serial implements java.io.Serializable {}
will trigger this compiler output
----------
1. ERROR in /tmp/Serial.java (at line 1)
public class Serial implements java.io.Serializable {}
^^^^^^
The serializable class Serial does not declare a static final serialVersionUID field of type long
----------
1 problem (1 error)
Other warnings are not affected by that option. In particular, you could complete suppress the varargs warning by adding -warn:-varargsCast. This isn't necessary because a warning will never let your build fail. But if you really don't want to see this even as a warning, the full command line would look like this:
ecj -err:serial -warn:-varargsCast Main.java
See the JDT FAQ for using ecj in automated builds, incl. ant.

AssertionError instead of failure

i have developed a test package using SWTbot and ant to build it , when i run it, it finds that there is a failure however in the test report it shows as an error instead of failure:
my code is :
public static void Check_TargetPack(final SWTWorkbenchBot bot,String configuration,
String targetpack) {
boolean exist=false;
String[] h=bot.comboBoxWithLabel("TargetPack").items();
int i=0;
for (i=0;i<h.length;i++){
if (h[i]==targetpack)exist=true;
assertTrue("target pack"+targetpack+" doesn't exist in targetpack list",exist);
};
bot.sleep(2000);
bot.button("Close").click();
}
and the result is
I can see one problem in your code.
You are matching Strings with "==" operator.
You should use following instead
h[i].equals(targetpack)

Resources