Repository navigation
API suggestion: from diffeqpy import de - #24
Conversation
|
I just realize pytest's IO capture kicks in so you can't see UndefVarError in Travis. Easiest way to produce it is to checkout this PR and do For example, it prints |
|
If it was a warning then I would just Surpressor.jl it. As an error, that seems fragile. |
|
Well it's an error in Julia side: julia> using DifferentialEquations
julia> :CompoundConstantRateJump in names(DifferentialEquations)
true
julia> DifferentialEquations.CompoundConstantRateJump
ERROR: UndefVarError: CompoundConstantRateJump not definedpyjulia just tries to suppresses it (but somehow it leaks out): def isafunction(julia, julia_name, mod_name=""):
code = "isa({}, Function)".format(julia_name)
if mod_name:
code = "isa({}.{}, Function)".format(mod_name, julia_name)
try:
return julia.eval(code)
except:
return False |
|
I always found it odd that Julia doesn't error if you don't remember to get rid of an export statement. That fact will now bite us if we rely on making sure all exports are correct, since this would be the only library that would show the error in its tests... |
|
I agree that exporting undefined variable being not an error in Julia is strange. Personally, I hope it become so in the future. But I think, ideally, it is better to try not export undefined variable even in current Julia situation. For example, newbie user may be puzzled when tab completion yields undefined variables: julia> using DifferentialEquations
julia> Compo<TAB>
CompositeAlgorithm CompoundConstantRateJump
CompositeException
julia> CompoundConstantRateJump
ERROR: UndefVarError: CompoundConstantRateJump not definedWell, I know it's just a nitpicking :) Anyway, I think it is solvable in pyjulia side: JuliaPy/pyjulia#159 |
|
Is there a stopgap solution somewhere here? I want to merge the syntax changes but don't want it to be broken |
Also let solve be an alias of pysolve.
|
Implemented a quick-and-dirty solution: ad28915 |
| # Suppress many UndefVarError printed out. | ||
| # See: https://github.com/JuliaPy/pyjulia/issues/159 | ||
| # https://github.com/JuliaDiffEq/diffeqpy/pull/24 | ||
| try: |
There was a problem hiding this comment.
so what exactly is this doing?
There was a problem hiding this comment.
The problematic part in pyjulia is
self.api.jl_call2(self.api.show, stderr, exoc)in Julia.check_exception (https://github.com/JuliaPy/pyjulia/blob/2eb704c33d6f639b41300023e16f910b5945600e/julia/core.py#L416-L432) which is called unconditionally before raise JuliaError. The JuliaError is suppressed by try-except in pyjulia module loader but call to Base.show above is not.
What I'm doing here is to monkey-patch self.api so that self.api.show points to Julia's identity function instead of show.
Wait, identity does not take two arguments. Why does it work?! I should probably use other function. Fixing it...
There was a problem hiding this comment.
I guess fix this up to something that's supposed to work (?) and we're good?
| @@ -1,9 +1,7 @@ | |||
| import diffeqpy | |||
| from .. import de | |||
There was a problem hiding this comment.
It's Python's relative import syntax. from .. import de is equivalent to from diffeqpy import de here. I just use it whenever I can, since it's easier to rename the package, for example.
Using identity "worked" somehow in the sense it suppresses UndefVarError messages. But identity cannot be called with two arguments. It is probably safer to use tuple function here.
|
So I fixed the potential issue I mentioned in https://github.com/JuliaDiffEq/diffeqpy/pull/24/files/ad289154df70a632c9f853f7123f1440c742122a#r184837524, put some comments, and tweak the code a little bit. Should be good to go. |
This patch introduces tiny changes in API for a bit of Python-user friendliness:
from diffeqpy import deinstead ofimport diffeqpy; de = diffeqpy.setup()de.solveinstead ofde.pysolveI suggest to not pull this patch at the moment since
import diffeqpy.deprints out a lot ofUndefVarError(...)messages presumably due toexport <undefined variable name>which, I think, would scare users.I'm actually not sure if this change worth a trouble for fixing the
UndefVarError(...)messages. That would require going over many files in DifferentialEquations.jl projects. But probably fixing theUndefVarErrorproblem makes sense anyway since it's kind of a bug in DifferentialEquations.jl anyway (though I suppose it's not harmful)?