-
Notifications
You must be signed in to change notification settings - Fork 29
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
Params should be reference classes #5
Comments
I agree with the problem. I think BiocParallelParam (and derived) should be reference classes, so a little bit more extensive change. |
Here's a trivial start of implementing a param class hierarchy as reference classes. I mostly did this to figure out how to write reference classes. Seems pretty straightforward once you know the conventions for initializers and callSuper and such. BiocParallelParamRef <- setRefClass("BiocParallelParamRef",
contains="VIRTUAL",
fields=list(.controlled="logical", workers="integer"),
methods=list(initialize=function(.controlled=TRUE, workers=0, ...) callSuper(.controlled=.controlled, workers=as.integer(workers), ...)))
SerialParamRef <- setRefClass("SerialParamRef",
contains="BiocParallelParamRef")
# Only difference is it reports 2 workers
DummyParallelParamRef <- setRefClass("DummyParallelParamRef",
contains="BiocParallelParamRef",
methods=list(initialize=function(...) callSuper(.controlled=TRUE, workers=2, ...)))
x <- DummyParallelParamRef$new()
print (x$workers) |
I'm now experimenting with reference classes here: https://github.com/DarwinAwardWinner/BiocParallel/blob/refclass/R/BiocParallelParam-refclass.R Anyone with knowledge of how reference classes are actually supposed to be written should feel free to critique me. |
I've just done some more work toward implementing ref classes here: https://github.com/DarwinAwardWinner/BiocParallel/tree/refclass However, I'm having trouble getting the package to load with my modifications, so I can't test it. The problem is that in the .onLoad function the calls to both
However, I put in print statements like |
Well, I just replaced the onLoad body with If someone could help me debug the onLoad problem, we can incorporate this soon. |
You can debug by adding
Then when you say |
So, I've done some testing, and the onLoad error only occurs for me when R is run with |
After further testing, I have determined that the package can only be loaded after loading the "scales" package. I have no idea why. |
On 05/14/2013 05:11 PM, Ryan Thompson wrote:
Something is not being initialized correctly in the methods package; I think A <- setRefClass("A") Try experimenting with a simpler rather than more complicated (by adding scales)
Computational Biology / Fred Hutchinson Cancer Research Center Location: Arnold Building M1 B861 |
Well, I got things to work in R 3.0.0: 6087e62 |
My fix also works in R 2.15.3. |
this is a work-around that should be addressed by narrowing to a simple reproducible example that can be reported to the R-devel mailing list. |
Yes indeed, I will do that when I have the chance. Since the bug only seems to occur in the onLoad function of a package, should I just create a minimal package that triggers the bug and send a download link to the R-devel list? |
Hmm. It seems that I am not constructing reference objects correctly. I thought you had to do So basically I am only seeing the bug because I was doing it wrong. Is it still worth reporting? |
Actually never mind. I'm getting inconsistent results, so now I don't know what's going on. I will investigate further, but for now, disregard my previous comment. |
Looks like the solution is to use I'll try this out and see if it fixes things. |
Ok, I switched it over: c9a5c03 Everything seems to work now. |
On 05/27/2013 05:36 PM, Ryan Thompson wrote:
OK great, thanks for pursuing this; I'll merge this in the next two days. Martin
Computational Biology / Fred Hutchinson Cancer Research Center Location: Arnold Building M1 B861 |
Ok, in the mean time, I will work on eliminating any warnings related to missing documentation and other cleanup. I'll post here when I think it's ready to merge. |
Ok, I'd say it's ready to merge. With this and my other pull request, there are no more warnings from R CMD check. |
Should have closed this with the pull request; thanks. |
Looking at how bpstart and bpstop work, it looks like one must do:
If one simply does
bpstart(param)
, then param will still be set to an object representing a stopped cluster, and the reference to the started cluster will be lost (possibly leaking resources by leaving a bunch of new processes running but inaccessible).I think we could make bpstart and bpstop work without assignment by storing the reference to the backend inside an environment in the object, since environments are pass-by-reference.
What do you think?
The text was updated successfully, but these errors were encountered: