I am trying to set up a custom multi-agent environment using RLlib, but either I am using the once available online or I am making one, I am being encountered by the same errors as mentioned below. Please help me out.
I have installed whatever they have asked from me in step (a)
I am registering my environment using
def env_creator(env_config):
return SimpleCorridor(env_config)
register_env("corridor", env_creator)
if __name__ == "__main__":
ray.shutdown()
ray.init()
tune.run(
"PPO",
stop={
"timesteps_total": 10000,
},
config={
"env": "corridor", # <--- This works fine!
"env_config": {
"corridor_length": 5,
},
},
)
(pid=266728) Try one of the following:
(pid=266728) a) For Atari support: `pip install gym[atari] atari_py`.
(pid=266728) For VizDoom support: Install VizDoom
(pid=266728) (https://github.com/mwydmuch/ViZDoom/blob/master/doc/Building.md) and
(pid=266728) `pip install vizdoomgym`.
(pid=266728) For PyBullet support: `pip install pybullet`.
(pid=266728) b) To register your custom env, do `from ray import tune;
(pid=266728) tune.register('[name]', lambda cfg: [return env obj from here using cfg])`.
(pid=266728) Then in your config, do `config['env'] = [name]`.
(pid=266728) c) Make sure you provide a fully qualified classpath, e.g.:
(pid=266728) `ray.rllib.examples.env.repeat_after_me_env.RepeatAfterMeEnv`
Is there something else I should be taking care of? This is just a basic environment from the examples I saw. Even the environment I am customizing is facing the same problem. I have initialized the observation space as a tuple so I am not able to use stable baselines for evaluation.
Please Please help me out.
Related
Me and my team just moved from JUnit4 to JUnit5 and we faced with parallelism issues. With 4th version we used -Dcucumber.options="--threads 5" to run in tests several threads, but after deprecation and removing of cucumber options it's obviously doesn't work anymore. I set up (at least I think so) junit platform engine for the project (https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-junit-platform-engine#configuration-options), but when I try to run tests via comand line (using Gradle task), I receive following error:
UnknownClass.Cucumber > UnknownClass.initializationError FAILED
org.junit.platform.commons.JUnitException at EngineExecutionOrchestrator.java:114
Caused by: org.junit.platform.commons.JUnitException at HierarchicalTestEngine.java:57
Caused by: org.junit.platform.commons.JUnitException at DefaultParallelExecutionConfigurationStrategy.java:41
Unfortunately, didn't find something in the internet, maybe someone can help with it?
What we use:
Spring boot 2.7.3
Gradle 7.5.1
Cucumber java, junit, spring, junit-platform-engine 5.7.0
junit-platform-suite-api 1.3.2
Tasks in build.gradle that I have now:
useJUnitPlatform()
systemProperty("cucumber.junit-platform.naming-strategy", "long")
systemProperty("cucumber.execution.parallel.enabled", true)
systemProperty("cucumber.execution.parallel.config.strategy", "fixed")
systemProperty("cucumber.plugin", "html:reports/html")
systemProperty("cucumber.plugin", "pretty")
systemProperty("cucumber.plugin", "junit:reports/junit")
doLast {
javaexec {
mainClass.set("io.cucumber.core.cli.Main")
classpath = cucumberRuntime + sourceSets.test.get().output + sourceSets.main.get().output
}
}
}
tasks {
val consoleLauncherTest by registering(JavaExec::class) {
dependsOn(testClasses)
val reportsDir = file("$buildDir/test-results")
outputs.dir(reportsDir)
classpath = sourceSets["test"].runtimeClasspath
mainClass.set("org.junit.platform.console.ConsoleLauncher")
args("--scan-classpath")
args("--include-engine", "cucumber")
args("--reports-dir", reportsDir)
}
test {
dependsOn(consoleLauncherTest)
exclude("**/*")
}
}
Configuration class:
#CucumberContextConfiguration
#Suite
#IncludeEngines("cucumber")
#SelectClasspathResource("com/example")
#ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example")
#SpringBootTest
#ContextConfiguration(classes = [IntegrationContext::class], loader = SpringBootContextLoader::class)
class Application() {}
Your question is pretty much impossible to answer because you didn't go through the process of making a minimal reproducer. For your next question please read the "Help others reproduce the problem" section in How do I ask a good question?.
With 4th version we used -Dcucumber.options="--threads 5" to run in tests several threads, but after deprecation and removing of cucumber options it's obviously doesn't work anymore.
Project typically include a CHANGELOG and release notes documenting all relevant changes.
What we use:
Spring boot 2.7.3
Cucumber java, junit, spring, junit-platform-engine 5.7.0
junit-platform-suite-api 1.3.2
These dependencies don't converge and aren't quite correct. You'll want to use Cucumber's and JUnit's Bill of Materials to avoid having to specify the version for every module.
If you're using Spring Boot in the recommended way you may also be able to omit the junit-bom altogether.
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation(platform("io.cucumber:cucumber-bom:7.9.0"))
testImplementation("io.cucumber:cucumber-java")
testImplementation("io.cucumber:cucumber-junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-suite")
testImplementation("org.junit.jupiter:junit-jupiter")
}
Tasks in build.gradle that I have now:
So in this build file it appears that you are trying to run Cucumber in 3 different ways. Through the JUnit Platform, through Cucumbers CLI and through the JUnit 5 ConsoleLauncher.
I don't know which solution you are trying use but suppose that you want to use the JUnit Platform, then you look at cucumber-java-skeleton for a working example.
Then afterwards you should clean up your build file. :D
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 have this fixture that stamps out <page-welcome>:
<test-fixture id="fixture-one">
<template>
<page-welcome></page-welcome>
</template>
</test-fixture>
Within <page-welcome>, I import <paper-button> and give it a class of big-btn. It's important this button exists on the <page-welcome> element, so I want to test it with:
test('does the custom cmponent exist', function() {
var test = fixture('fixture-one').shadowRoot.querySelector('.big-btn');
assert.exists(test);
});
It's my understanding that I should be able to use all of the Chai API, and therefore assert.exists should be available.
But why do I get the following error?
assert.exists is not a function
web-component-tester uses chai 3.5.0, which does not include assert.exists.
Note that chai's git history shows the introduction of assert.exists in 4.0.0-canary-2 (it seems undocumented in the release notes). You can install this version of chai as a devDependency without breaking anything:
bower i -D chai
Select the newer/4.x version (currently 4.0.2) when bower prompts for version resolution:
Unable to find a suitable version for chai, please choose one by typing one of the numbers below:
1) chai#^3.2.0 which resolved to 3.5.0 and is required by web-component-tester#6.0.0
2) chai#^4.0.2 which resolved to 4.0.2
Prefix the choice with ! to persist it to bower.json
? Answer
I am making a python script with jython and I need to use the json module that dosent exist in jython 2.5 . Do any of you guys know a way to include a module as a single file that can be moved around with the script without installing it on the host's jython . I was planning on using the simple json module i found on pypi
If it helps.
Try http://opensource.xhaus.com/projects/jyson
A fast JSON codec for jython 2.5, written in java.
Jython 2.7.0 now includes the standard library json module, which is reasonably fast now that it has been ported to Java. I ran the JSON benchmarks in the standard Python benchmark suite:
### json_dump ###
Min: 0.385395 -> 0.634000: 1.65x slower
Avg: 0.388340 -> 0.831400: 2.14x slower
Significant (t=-3.59)
Stddev: 0.00331 -> 0.27605: 83.3334x larger
### json_dump_v2 ###
Min: 2.642799 -> 3.480000: 1.32x slower
Avg: 2.680320 -> 3.715000: 1.39x slower
Significant (t=-6.72)
Stddev: 0.04087 -> 0.34167: 8.3607x larger
### json_load ###
Min: 0.816147 -> 2.266000: 2.78x slower
Avg: 0.832826 -> 2.578800: 3.10x slower
Significant (t=-8.27)
Stddev: 0.01652 -> 0.47203: 28.5677x larger
Other options like GSon, Jackson, or Jyson would likely be faster, given the API of the json module.
I have a simple grails file upload app.
I am using transferTo to save the file to the file system.
To get the base path in my controller I am using
def basePath = System.properties['base.dir'] // HERE IS HOW I GET IT
println "Getting new file"
println "copying file to "+basePath+"/files"
def f = request.getFile('file')
def okcontents = ['application/zip','application/x-zip-compressed']
if (! okcontents.contains(f.getContentType())) {
flash.message = "File must be of a valid zip archive"
render(view:'create', model:[zone:create])
return;
}
if(!f.empty) {
f.transferTo( new File(basePath+"/files/"+zoneInstance.title+".zip") )
}
else
{
flash.message = 'file cannot be empty'
redirect(action:'upload')
}
println "Done getting new file"
For some reason this is always null when deployed to my WAS 6.1 server.
Why does it work when running dev but not in prod on the WAS server? Should I be accessing this information in a different way?
Thanks j,
I found the best dynamic solution possible. As a rule I never like to code absolute paths into any piece of software. Property file or no.
So here is how it is done:
def basePath = grailsAttributes.getApplicationContext().getResource("/files/").getFile().toString()
grailsAttributes is available in any controller.
getResource(some relative dir) will look for anything inside of the web-app folder.
So for example in my dev system it will toString out to "C:\WORKSPACEFOLDER\PROJECTFOLDER\web-app\ with the relative dir concated to the end
like so in my example above
C:\WORKSPACEFOLDER\PROJECTFOLDER\web-app\files
I tried it in WAS 6.1 and it worked in the container no problems.
You have to toString it or it will try to return the object.
mugafuga
There's a definitive way...
grailsApplication.parentContext.getResource("dir/or/file").file.toString()
Out of controllers (ex. bootstrap)? Just inject..
def grailsApplication
Best regards!
Grails, when it's run in dev mode, provides a whole host of environment properties to its Gant scripts and the app in turn, including basedir.
Take a look at the grails.bat or grails.sh script and you will find these lines:
Unix: -Dbase.dir="." \
Windows: set JAVA_OPTS=%JAVA_OPTS% -Dbase.dir="."
When these scripts start your environment in dev mode you get these thrown in for free.
When you take the WAR and deploy you no longer use these scripts and therefore you need to solve the problem another way; you can either
Specify the property yourself to the startup script for the app server, eg: -Dbase.dir=./some/dir .. however
... it usually makes more sense to use the Grails Config object which allows for per-environment properties
Another option:
def basePath = BuildSettingsHolder.settings.baseDir