Fork me on GitHub

Unless you run Clojush with the :use-single-thread option set to true (or at least something truthy), breed will be called for the whole population using multiple threads. See produce-new-offspring. That means breaking one thread probably isn't what you want, and I'm not sure what I'd expect. Try running with :use-single-thread true ?


I might also be able to help you understand what you should be seeing at that point in the code, if you want to ask more specifically what you're looking for. FYI a more recent project,, was developed in part because the Clojush had grown into something a bit ungainly and hard to understand. Depending on your use case, you might want to give it a look. It's younger but under development.

Zahra Ghasemi04:12:11

@lspector Thank you so much for your response. I tested:use-single-thread true and still breakpoint does not work. I will check propeller too. thank you for sending its link. What I am trying to do is to add a section of codes after line 99 of breed.clj ( as below:

(if (= num-parents 2)     
       (let [initial-other-parents (vec (repeatedly      
                                   (+ num-parents 4)     ; selecting parents more than required by 4
                                           (fn []
                                             (loop [re-selections 0
                                                    other (select population argmap)]
                                               (if (and (= other first-parent)
                                                        (< re-selections
                                                           (:self-mate-avoidance-limit argmap)))
                                                 (recur (inc re-selections)
                                                        (select population argmap))
         all-parents (concat (if (nil? first-parent)     ;gathering all created parents 
                                   (vector first-parent))
        eclid-dist (fn [u v]                            ;defining a function to calculate distances
          (->> (mapv - u v)
               (mapv #(Math/pow % 2))
               (reduce +)
        find-largest-dist-pair (fn [vec-map]   ;defining a function to return two vectors (parents) with the                                                         ;largest distance
          (apply max-key second
                 (for [[[k0 v0] & r] (iterate rest vec-map)
                       :while r
                       [k1 v1] r]
                   [[k0 k1] (eclid-dist v0 v1)])))
         final-parents (find-largest-dist-pair (:error all-parents)) ;selecting two parents with the largest distance
        op-fn (:fn (get genetic-operators operator))                     ; extracting the operator
        child (apply op-fn (concat final-parents                         ; creating child
                                   (vector (assoc argmap
                                                  :population population))))]
sorry if the codes look unprofessional. I am quite new to Clojure. I tested functions (eclid-dist and find-largest-dist-pair) for a simple example and it works, but when I add these lines to breed and run it with lein, I get some errors, and debugging does not work for me. I do not know how to deal with it. I was thinking of getting values one step before the change with spit and assigning them to variables and running it line by line manually, but due to lots of dependencies, it was not successful as well. That would be great If you could please guide me on how to resolve that. Thanks.


(Continued the discussion in DMs. The issue was a syntax error in the let bindings.)


Ah, I see the idea and I think it's an interesting one to try. It looks to me like there might just be some missing brackets or something... but it's hard to tell without the full function definition. Can you paste the full thing here?


Please use threads. 🙏


I'd like to generate some dummy data in a db, run some tests and then delete the dummy data. Since I use cider to run tests, what could be done to automate those dummy data insertions and deletions in the db before and after I execute the tests?


Put all the logic in a transaction, run the tests in it and roll it back in the end


Take a look at use-fixtures too, some examples here: I've never used it personally but might help you with the setup/teardown

👀 1

So if I have a deftest block, how can I put it in a transaction?


use-fixtures looks like what I might need


If you don't use a fixture, you don't put the entire deftest in the transaction, you have to do it manually for the tests you want (you wrap the body of each test with with-transaction)


That's how I imagined too.. Manually testing, but I will give use-fixtures a try


Yeah, use-fixtures should help reduce some clutter (but I'm not sure how flexible it is, e.g. can you use it only in some tests of a namespace?)


Does not seem so, but I think for my current usecase, this is exactly what I need, thanks a ton!

👍 1

You can also use an in memory fb for tests and delete the tables before each test

👍 1

I've never done that to be honest... What are the pros compared to e.g. using a dev instance of your actual db?


You don’t need a special db instance just for tests and it’s also easier to make sure the state is consistent across test runs. It should also be faster

👌 1