Ray fails to unpickle remote function due to import issue? - pickle

Is there import pattern you are supposed to avoid for this?
2020-03-26 16:06:01,535 WARNING worker.py:1058 -- Failed to unpickle the remote function with
function ID ebb720e21fedc91d9da76f8176bc702d2ac788a7. Traceback:
Traceback (most recent call last):
function = pickle.loads(serialized_function)
class BaseModel(tf.keras.models.Model):
AttributeError: module 'tensorflow' has no attribute 'keras'

Try importing tensorflow within your function or class.

Related

hardhat 'pragma solidity' marked as unexpected identifier

I have been working on my ethereum project when face with issue new contracts stops compiling with error message:
blockchain/contracts/Utils.sol:2
pragma solidity ^0.8.9;
^^^^^^^^
SyntaxError: Unexpected identifier
I simply can not create a new contract anymore. It looks like there is some break in the environment.
Have you ever face with this issue? Do you have any thoughts what is wrong here?
Hardhat config is:
import { HardhatUserConfig } from "hardhat/config";
import "#nomicfoundation/hardhat-toolbox";
const config: HardhatUserConfig = {
solidity: "0.8.9",
};
export default config;
The issue was in import in .ts file.
My current import for test is shown below:
import { expect } from "chai";
import { ethers } from "hardhat";
import { utils, BigNumber } from "ethers";
import { time, loadFixture } from "#nomicfoundation/hardhat-network-helpers";
import "../contracts/Utils.sol";
Remove import "../contracts/Utils.sol"; from import solves the issue.
It is redundant import, hardhat is able to evaluate type of the contract just by its name in the factory. The root cause though is unclear.
In Hardhat, this error occurs while running .sol Hardhat this error occurs while running .sol contract instead of .js deployment script

How to modify the code so that i do not have to uninstall pycharm?

I have run the code as part of exception handling in python, during a session on Plural-sight but now even if a write a incorrect code the result is OK.
For example : hello world without print statement gives me exit code 0
Could you please advice on it?
code :
try:
import msvcrt
def getkey():
return msvcrt.getch()
except ImportError:
import sys
import tty
import termios
def getkey():
fd=sys.stdin.fileno()
original_attributes =termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, original_attributes)
return ch
You need to make sure that the indentation of your code is correct first.
For example get_key function should be defined in both: the try case and in the catch, in the catch case you indented it correctly under the catch statement, but for the try case you made it on the same level of indentation as the try itself, for the interpreter it means that the function definition is not related to the try you wrote, therefore it throws an error as you should not add code after between the try and catch statement.
a rewrite of your program
try:
import msvcrt
def getkey():
return msvcrt.getch()
except ImportError:
import sys
import tty
import termios
def getkey():
fd=sys.stdin.fileno()
original_attributes =termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, original_attributes)
return ch
This code says now, if we tried to import the library msvcrt and succeeded, then we will define a function get_key using the library, if failed; then we will define it again without using the library.

Angular 6 with lowdb - not getting it to work

I'm trying to create an Electron app with Angular 6 that uses lowdb as a local database.
It's all very new to me and it's trial and error, but I don't seem to be able to figure out how to overcome the following error:
I've installed lowdb in my application by using the commands
npm install --save lowdb (edit: forgot to mention I did this already)
and
npm install --save #types/lowdb
I've created a service to communicate with this "local database".
import { Injectable } from '#angular/core';
import lowdb from 'lowdb';
import { default as FileAsync } from 'lowdb/adapters/FileAsync';
import { CurrentUserModel } from '../models/current-user';
#Injectable({
providedIn: 'root'
})
export class LowdbService {
private db: lowdb.LowdbAsync;
constructor() {
this.initDatabase();
}
set( field: string, value: any ) {
this.db.set( field, value ).write();
}
private async initDatabase() {
const adapter = new FileAsync( 'db.json' );
this.db = await lowdb( adapter );
this.db.defaults( { user: CurrentUserModel } );
}
}
But when I include the service in the constructor of a component I get errors.
ERROR in ./src/app/services/lowdb.service.ts
Module not found: Error: Can't resolve 'lowdb' in '/Users/paul/Projects/application-name/src/app/services'
ERROR in ./src/app/services/lowdb.service.ts
Module not found: Error: Can't resolve 'lowdb/adapters/FileAsync' in '/Users/paul/Projects/application-name/src/app/services'
ℹ 「wdm」: Failed to compile.
ERROR in src/app/services/lowdb.service.ts(2,12): error TS1192: Module '"/Users/paul/Projects/application-name/node_modules/#types/lowdb/index"' has no default export.
src/app/services/lowdb.service.ts(3,14): error TS2305: Module '"/Users/paul/Projects/application-name/node_modules/#types/lowdb/adapters/FileAsync"' has no exported member 'default'.
As far as I can see I'm doing the same as mentioned in this Github comment and this Stackoverflow comment. I can't find any more documentation though.
Can somebody help me out?
Update
Using import * as lowdb from 'lowdb' seemed to solve my initial errors. But it resulted in a few other errors. See below.
ERROR in ./node_modules/graceful-fs/polyfills.js
Module not found: Error: Can't resolve 'constants' in '/Users/paul/Projects/project-name/node_modules/graceful-fs'
ERROR in ./node_modules/graceful-fs/graceful-fs.js
Module not found: Error: Can't resolve 'fs' in '/Users/paul/Projects/project-name/node_modules/graceful-fs'
ERROR in ./node_modules/graceful-fs/fs.js
Module not found: Error: Can't resolve 'fs' in '/Users/paul/Projects/project-name/node_modules/graceful-fs'
ERROR in ./node_modules/graceful-fs/legacy-streams.js
Module not found: Error: Can't resolve 'stream' in '/Users/paul/Projects/project-name/node_modules/graceful-fs'
First of all, if you installed just #types/lowdb, that is only typings for that library, you need to install the library itself via:
npm install --save lowdb
Then, looks like there is no default export so import lowdb from 'lowdb'; also won't work. Try is like this:
import { LowdbAsync } from 'lowdb';
import * as lowdb from 'lowdb';
import * as FileAsync from 'lowdb/adapters/FileAsync';
private db: LowdbAsync<any>; // TODO provide correct schema instead of any
private async initDatabase() {
const adapter = new FileAsync('db.json');
this.db = await lowdb(adapter);
this.db.defaults({ user: any });
}
Or you can try removing those typings (as they might be outdated) and do what their docs says:
https://github.com/typicode/lowdb/tree/master/examples#browser
import low from 'lowdb'
import LocalStorage from 'lowdb/adapters/LocalStorage'
(but when you take a look at #types/lowdb, there is no such default export so again, the typings might be outdated)
As for your other issue, take a look here:
https://github.com/typicode/lowdb/issues/206#issuecomment-324884867
typicode commented on 25 Aug 2017
#DickyKwok I think it's impossible. Can you answer this, #typicode?
I confirm, to save to disk using FileSync or FileAsync adapters you need to have access to Node fs API.
Looks like you should use LocalStorage adapter instead.
Another similar issue here: How can I use node "fs" in electron within angular 5
You could also try the solution proposed in one of answers there:
https://github.com/ThorstenHans/ngx-electron
constructor(private _electronService: ElectronService) {
this.fs = this._electronService.remote.require('fs');
}
Looks like your lowdb is missing in node_modules.
try
npm install lowdb

how to call GEOSDistance_r from geos library

I am trying to speed the spatial distance calculation between polygons and points/polygons by calling the GEOS library directly. However I couldn't find any help how to call this function correctly. Can anyone please point me to the location where I can find the reference for this function or point out where I have done incorrectly?
working example:
from shapely.geos import lgeos
points_geom = np.array([x._geom for x in points])
polygons_geom = np.array([x._geom for x in polygons])
lgeos._lgeos.GEOSContains_r(lgeos.geos_handle,polygons_geom[0],points_geom[0])
Not working:
lgeos._lgeos.GEOSDistance_r(lgeos.geos_handle,polygons_geom[0],points_geom[0])
TypeError Traceback (most recent call last)
<ipython-input-138-392cb700cfbc> in <module>()
----> 1 lgeos._lgeos.GEOSDistance_r(lgeos.geos_handle,polygons_geom[0],points_geom[0])
TypeError: this function takes at least 4 arguments (3 given)
GEOSDistance_r takes 4 arguments, you're only passing three:
extern int GEOS_DLL GEOSDistance_r(GEOSContextHandle_t handle,
const GEOSGeometry* g1,
const GEOSGeometry* g2, double *dist);
(from https://github.com/OSGeo/geos/blob/5a730fc50dab2610a9e6c037b521accc66b7777b/capi/geos_c.h.in#L1100)
You're using shapely's private interface to GEOS, which it looks like uses ctypes, so you'll need to use the ctypes invocation to pass a double by reference:
import ctypes
dist = ctypes.c_double()
lgeos._lgeos.GEOSContains_r(
lgeos.geos_handle, polygons_geom[0], points_geom[0], ctypes.byref(dist))
dist = dist.value

Can't import any java classes

HelloWorld.ceylon
import java.util { HashMap } //Error:(1, 8) ceylon: package not found in imported modules: java.util (define a module and add module import to its module descriptor)
void run() {
print("test");
}
module.properties
module CeylonHelloWorld "1.0" {
import java.base "8";
}
I get an exception in HelloWord.ceylon file
When I try that code, I get:
Incorrect syntax: mismatched token CeylonHelloWorld expecting initial-lowercase identifier
In module.ceylon.
The name of a module is supposed to be of form foo.bar.baz (initial-lowercase identifiers separated by periods).
Like mentioned by Gavin you will have to use a legal module name, when I change your code to use the module name "java8test" I get the following output when compiling:
$ ceylon compile java8test
warning: It looks like you are using class files from a Java newer than 1.7.
Everything should work well, but if not, let us know at https://github.com/ceylon/ceylon-compiler/issues.
In the near future, the Ceylon compiler will be upgraded to handle Java 1.8.
./source/java8test/run.ceylon:1: warning: import is never used: 'HashMap'
import java.util { HashMap }
^
2 warnings
Note: Created module java8test/1.0.0
Which is all as expected.
module.ceylon
module holaCeylon "1.0.0"{
import java.base "7"; // versión 7 JDK
}
package.ceylon
shared package holaCeylon;
Now we go back to the run.ceylon file and import the java.util.HashMap Java library.
run.ceylon
import java.util { HashMap }
shared void run(){
print("Importando librerias de Java en Ceylon");
value romanos = HashMap<String,Integer>();
romanos.put("I", 1);
romanos.put("V", 5);
romanos.put("X", 10);
romanos.put("L", 50);
romanos.put("C", 100);
romanos.put("D", 500);
romanos.put("M", 1000);
print(romanos.values());
print(romanos.keySet());
}
Output:
salida
Code:
http://codemonkeyjunior.blogspot.mx/2015/03/ceylon-interoperabilidad-con-java.html