Skip to content
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

Simplify ParticleContainer #966

Merged
merged 6 commits into from
Nov 20, 2019
Merged

Simplify ParticleContainer #966

merged 6 commits into from
Nov 20, 2019

Conversation

devmotion
Copy link
Member

This PR simplifies the type parameters of ParticleContainer, and removes the conditional field which by definition was always nothing.

Moreover, instead of appending newly allocated arrays, push! now resizes the existing arrays and sets the new values, which is faster:

using BenchmarkTools

function f(x, n)
    y = zeros(eltype(x), n)
    append!(x, y)
    nothing
end

function g(x, n)
    m = length(x)
    mpn = m + n
    resize!(x, mpn)
    @inbounds for i in (m + 1):mpn
        x[i] = zero(eltype(x))
    end
    nothing
end

a = rand(1_000)

@btime f($(copy(a)), 100) # 339.092 ns (1 allocation: 896 bytes)
@btime g($(copy(a)), 100) # 263.981 ns (0 allocations: 0 bytes)

The empty! function now defines an array of particles whose element type is based on the previously used array instead of always using the abstract element type Particle.

The copy! function of ParticleContainer creates a set of copied particles by list comprehension instead of pushing them individually to an initially empty array.

Moreover, the definition of Trace is simplified by removing the completely uninitialized inner constructor and reordering the fields (making it easier to create new instances without specifying a task).

@cpfiffer
Copy link
Member

I'm really glad to see some of this stuff updated. The particle stuff has always been a little rickety.

Anyone know why tests aren't running for this PR?

@mohamed82008
Copy link
Member

I think there is a problem with tests on all our PRs.

Copy link
Member

@yebai yebai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks correct to me. It might be helpful to run some tests on the PR before merging, say after the Zygote related dependency mess is settled.

src/core/container.jl Show resolved Hide resolved
@yebai
Copy link
Member

yebai commented Nov 19, 2019

@devmotion The CI is now fixed on the master branch. Can you try to rebase master into this PR? Once all tests pass, I'm happy to merge it.

@devmotion
Copy link
Member Author

I rebased on master, but as observed above tests aren't running. Skimming through other PRs it seems that tests don't run for PRs from forks?

@yebai yebai closed this Nov 19, 2019
@yebai yebai reopened this Nov 19, 2019
@yebai yebai closed this Nov 19, 2019
@yebai yebai reopened this Nov 19, 2019
@yebai
Copy link
Member

yebai commented Nov 19, 2019

Yep; seems that's true. I don't know how to activate CI on forks. Since you're a repo developer now, do you want to create a new branch inside this repo?

@devmotion
Copy link
Member Author

Sure, I can do that. I just noticed that apparently the actions are run on my fork but not on the main repo: https://github.com/devmotion/Turing.jl/actions

@yebai
Copy link
Member

yebai commented Nov 19, 2019

Sure, I can do that. I just noticed that apparently the actions are run on my fork but not on the main repo: https://github.com/devmotion/Turing.jl/actions

That is equivalent - happy to merge once the actions based CI passes.

@devmotion
Copy link
Member Author

It's not completely clear to me from the documentation, but maybe the issue for PRs could be solved by replacing lines such as

on: [push] # [push, pull_request]

with on: [push, pull_request]. To run the Travis CIs for all PRs, one should probably enable Build pushed pull requests in the settings of Travis.

@yebai yebai closed this Nov 19, 2019
@yebai yebai reopened this Nov 19, 2019
@yebai
Copy link
Member

yebai commented Nov 19, 2019

Thanks, Travis CI is now turned on. I’m not sure about the actions based CI though, cause turning both push and pull request on causes duplicate builds in the past.

@devmotion
Copy link
Member Author

I guess we'll face the same issue with Travis CI and end up with duplicate tests for forks from the main repo. However, I think that can be avoided by adding

branches:
  only:
    - master

to .travis.yml (at least that's what Google told me 😄).

@devmotion
Copy link
Member Author

devmotion commented Nov 19, 2019

@yebai
Copy link
Member

yebai commented Nov 19, 2019

That looks quite promising. Would you like to give it a try in this PR? It seems I can't push to this PR easily.

@yebai yebai merged commit e7decc1 into TuringLang:master Nov 20, 2019
@devmotion devmotion deleted the container branch November 20, 2019 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants