Open btracey opened 6 years ago
Hi @btracey,
can you please provide the output of go version
and go env
?
After replacing your displayPlot
with
// Wrap function for plotting as a PNG
func displayPlot(p *plot.Plot) display.Data {
// This seems to be the best way to plot in jupyter at the moment?
w, err := p.WriterTo(8*vg.Inch, 8*vg.Inch, "png")
if err != nil{
panic(err)
}
var b bytes.Buffer
writer := bufio.NewWriter(&b)
w.WriteTo(writer)
return display.PNG(b.Bytes())
}
it worked fine for me (go version go1.10.3 linux/amd64).
The error you reported is very deeply connected with Go runtime, and I am trying to imagine what kind of bug could produce it - my guess is that, unless you hit a compiler bug, only assembler or C code can cause it.
Update: attempting to display the plot as PDF on my system produced a corrupted PDF. So there may be something strange in that part. I will run more tests - in the meantime, it would help if you provide the information I asked above, and also the outcome of re-running your example with my modified displayPlot
brendan:~$ go version
go version go1.10.3 darwin/amd64
brendan:~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/brendan/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/brendan/Documents/mygo"
GORACE=""
GOROOT="/Users/brendan/gover/go"
GOTMPDIR=""
GOTOOLDIR="/Users/brendan/gover/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/l6/mhj4qjrj4437b_lgfz9pm1rw0000gn/T/go-build522914795=/tmp/go-build -gno-record-gcc-switches -fno-common"
Thanks :) So it's Mac OS X.
The plugin
module that gophernotes uses to import third party packages is very new on Mac OS X - in go 1.10 and 1.10.1 it was quite bugged.
I will do some more tests on it because I am not convinced it is completely stable yet.
It appears to be a problem with multiple cells running at the same time. If I execute each cell individually, the code reliably completes. If I have multiple cells queued at a time (for instance in "restart and run all"), then it reliably panics. (This is with the suggested change)
Here is the updated .ipynb with your changes
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import (\n",
" \"bufio\"\n",
" \"bytes\"\n",
" \n",
" \"golang.org/x/exp/rand\"\n",
" \n",
" \"gonum.org/v1/gonum/stat\"\n",
" \"gonum.org/v1/gonum/stat/distmv\"\n",
" \"gonum.org/v1/gonum/mat\"\n",
" \"gonum.org/v1/plot\"\n",
" \"gonum.org/v1/plot/plotter\"\n",
" \"gonum.org/v1/plot/vg\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"// First, let's generate fake data. Set dimension and number of fake points\n",
"nDim := 5\n",
"nSamples := 2000"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"// First, let's generate a random positive definite covariance matrix.\n",
"dat := make([]float64, nDim*nDim)\n",
"for i := range dat {\n",
" dat[i] = rand.Float64()\n",
"}\n",
"a := mat.NewDense(nDim, nDim, dat)\n",
"sigma := mat.NewSymDense(nDim, nil)\n",
"sigma.SymOuterK(1,a)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"// Construct the multivariate normal distribution.\n",
"mu := make([]float64, nDim)\n",
"for i := range mu{\n",
" mu[i] = rand.Float64()\n",
"}\n",
"dist, ok := distmv.NewNormal(mu, sigma, nil)\n",
"if !ok{\n",
" panic(\"bad covariance matrix\")\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"// Sample the distribution to get data\n",
"samples := mat.NewDense(nSamples, nDim, nil)\n",
"for i := 0; i < nSamples; i++ {\n",
" dist.Rand(samples.RawRowView(i))\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"// Wrap function for plotting as a pdf\n",
"func displayPlot(p *plot.Plot) display.Data {\n",
" // This seems to be the best way to plot in jupyter at the moment?\n",
" w, err := p.WriterTo(8*vg.Inch, 8*vg.Inch, \"png\")\n",
" if err != nil{\n",
" panic(err)\n",
" }\n",
" var b bytes.Buffer\n",
" writer := bufio.NewWriter(&b)\n",
" w.WriteTo(writer)\n",
" return display.PNG(b.Bytes())\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Plot the first two dimensions\n",
"pts := make(plotter.XYs, nSamples)\n",
"for i := range pts{\n",
" pts[i].X = samples.At(i,0)\n",
" pts[i].Y = samples.At(i,1)\n",
"}\n",
"scat, err := plotter.NewScatter(pts)\n",
"if err != nil{\n",
" panic(err)\n",
"}\n",
"p, _ := plot.New()\n",
"p.Add(scat)\n",
"data := displayPlot(p)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Display(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Go",
"language": "go",
"name": "gophernotes"
},
"language_info": {
"codemirror_mode": "",
"file_extension": ".go",
"mimetype": "",
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.10.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sorry, I don't know if this is a gopherdata issue or something else. I tried to see if this bug was fixed in go1.11beta1 . I'm getting errors the import statement because of the version skew. I tried deleting all of the .so files that get added into $GOPATH/src/gomacro_imports
, but they're still happening.
repl.go:5:5: error loading plugin "/Users/brendan/Documents/mygo/src/gomacro_imports/golang.org/x/exp/rand/rand.so": plugin.Open("/Users/brendan/Documents/mygo/src/gomacro_imports/golang.org/x/exp/rand/rand.so"): plugin was built with a different version of package internal/cpu (previous failure)
I also tried deleting all of the data in $GOPATH/pkg
and am now getting
repl.go:5:5: error loading package "golang.org/x/exp/rand" metadata, maybe you need to download (go get), compile (go build) and install (go install) it? cannot import, possibly version skew (unknown export format version -1 ("i\x00\xb6\x06\xc6\t?/Users/brendan/Documents/mygo/src/golang.org/x/exp/rand/rand.go\x00\x06Uint64\x04Seed\x04seed\x06Source\x06rng·3\tPCGSource\x03src\areadVal\areadPos>/Users/brendan/Documents/mygo/src/golang.org/x/exp/rand/exp.go")) - reinstall package
I did try re-go-getting, and also installing ,and also installing packages that import golang.org/x/exp/rand
. Doesn't seem to work.
Hmm... you can try the following to restore a sane state after upgrading Go:
$GOPATH/pkg
go clean -cache
go get
, as for example go get golang.org/x/exp/rand
and go get gonum.org/v1/plot/...
There is no need to delete the files in $GOPATH/src/gomacro_imports
because they are always recreated at each import
I believe the issue was that I also had to recompile gopherdata. (i.e. clean out $GOPATH/bin
as well).
I've tried it a couple of times and it seems to be fixed in 1.11beta1. It would be good if someone else could check though.
I reliably get the following kernel panic when running the attached notebook. This is starting the jupyter program new and running the cells in order.
Jupyter program:
And the panic: