I can tell whether my job is using static allocation, however I want to actually change my job to use it. How do I do this?
Ensure your compute function has the configure decorator and includes the STATIC_ALLOCATION profile like so:
from transforms.api import Input, Output, configure, transform
#configure(profile=["STATIC_ALLOCATION"])
#transform(
...
)
def my_compute_function(...):
...
Related
I'm generating different .pyx files and turning them to C++ .so libraries. So I got an example generatedLib.pyx like this:
from libcpp.vector cimport vector
def cinit(self): pass
cdef public void someFunction(vector[...]& inputs):
...
The public function always has same signature, except for the name. I somehow wanna call this public function using python interpreter because I prefer to write tests in Python rather than C++. I cannot do it directly of course. I cannot define this function as def as well since its parameter is of C++ vector type.
I have came up with an idea to have a wrapper function
def wrapperSomeFunction(input: list)
{
# convert Python list to c++ vector
someFunction(v)
# convert c++ vector back to python list and return
}
I can import the generatedLib as python module and call this wrapper just fine, it requires however, to append it to my generatedFile.pyx file contents every time I wanna test it before I build it. I would rather look for alternative solutions.
Is there some way I can build a separate .pyx which will have this wrapper inside and will be able to call my generatedLib.so? Or perhaps something else I didn't think of?
I use FastApi with SqlAlchemy as context manager
#contextmanager
def get_session(): # need to patch all over tests files
session_ = SessionLocal()
try:
yield session_
except Exception as e:
session_.rollback()
router.py
#router.get('/get_users'):
def get_users(): # No dependencies
with get_session() as session:
users = session.query(Users).all()
return users
I need to override get_session during all my tests (I use pytest)
I could do it with #patch and patch all test. But it's not most effective way because i need to use decorator to patch in each test file, correct specify full path.
I wonder is there quick way to do it in one place or maybe use fixture?
You could try the approach in this answer to a similar question: define a pytest fixture with arguments scope="session", autouse=True, patching the context manager. If you need, you can also provide a new callable:
from contextlib import contextmanager
from unittest.mock import patch
import pytest
#pytest.fixture(scope="session", autouse=True, new_callable=fake_session)
def default_session_fixture():
with patch("your_filename.get_session"):
yield
#contextmanager
def fake_session():
yield ... # place your replacement session here
As a side note, I would highly recommend using FastAPI's dependency injection for handling your SQLAlchemy session, especially since it has built in support for exactly this kind of patching.
I want to persist a trained model in CNTK and found the 'persist' functionality after some amount of searching. However, there seems to be some error in importing it.
from cntk import persist
This is throwing ImportError.
Am I doing something the wrong way? Or is this no longer supported? Is there an alternate way to persist a model?
persist is from an earlier beta. save_model is now a method of every CNTK function. So instead of doing save_model(z, filename) you do z.save_model(filename). Load_model works the same as before but you import it from cntk.ops.functions. For an example, see: https://github.com/Microsoft/CNTK/blob/v2.0.beta7.0/Tutorials/CNTK_203_Reinforcement_Learning_Basics.ipynb or https://github.com/Microsoft/CNTK/blob/v2.0.beta7.0/bindings/python/cntk/tests/persist_test.py
The functionality has moved to cntk functions. The new way is mynetwork.save_model(...) where mynetwork represents the root of your computation (typically the prediction). For loading the model you can just say mynetwork = C.load_model(...)
I am trying to work with JSON objects with DynamoDB and am having difficulty.
I'm trying to follow the tutorial:
http://aws.amazon.com/blogs/aws/dynamodb-update-json-and-more/
I wanted to use toJSONPretty(); on my object but the method is not recognized. I don't think I have the right gradle dependencies. I"m currently using:
compile 'com.amazonaws:aws-android-sdk-core:2.2.0'
compile 'com.amazonaws:aws-android-sdk-ddb:2.2.0'
compile 'com.amazonaws:aws-android-sdk-ddb-mapper:2.2.0'
Previously, my dynamo client was set up using the imports:
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
But looking at code from Dynamo/JSON tutorials, I see the import:
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
This seems to be required if you want to use the type DynamoDB as it:
DynamoDB dynamo = new DynamoDB(new AmazonDynamoDBClient(...));
I don't understand the difference between these libraries or how they relate to each other. Help!
The DynamoDB class is a higher-level abstraction of the AmazonDynamoDB API. It you create it with an instance of the AmazonDynamoDB inteface or a Regions object. AmazonDynamoDBClient implements the AmazonDynamoDB interface. Even if you pass a Regions object, an instance of a class that implements AmazonDynamoDB is created behind the scenes. Then, you get a Table so that you can perform data-plane operations like GetItem and PutItem. The Item class is one that has a toJSONPretty method. To sum up, the DynamoDB class uses an implementation of the AmazonDynamoDB interface behind the scenes to provide you with Items that you can call toJSONPretty() on.
There are multiple draw_if_interactive() expressions in the pyplot module but I can't find this function's definition anywhere in the module.
From intuition and readings, it's an easy guess that the function enables on-demand plotting but where can I read its definition? Thanks.
The function is actually in the backend code. The actual implementation depends on your backend. For example the function with the TkAgg backend is in backend_tkagg.py:
def draw_if_interactive():
if matplotlib.is_interactive():
figManager = Gcf.get_active()
if figManager is not None:
figManager.show()
Same kind of functions seem to be for other backends, they use the matplotlib.is_interactive to determine if this is an interactive session and then use the backend specific drawing commands to draw the image.