# Non-trivial conversions (Python to Julia)

**URL:** <https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665>\
**Category:** New to Julia\
**Tags:** quantum, optimization\
**Created:** [April 19, 2022, 12:20am UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665 "2022-04-19T00:20:43Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [April 19, 2022, 12:20am UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/1 "2022-04-19T00:20:43Z")

</div>

Greetings Watchers,

**Disclaimer** : Please maintain some level  
of professionalism/community by attempting  
to share your general thought process, feel  
free to follow-up with me for clarification or  
simply scroll/click along if you are neither  
interested nor able to spend a little time  
sharing your thoughts. Spare us the lectures  
about MWEs, they are useful tools but not a  
catchall especially for high-level or theoretical  
questions. However, if you could provide one  
that is instructive – it may benefit all.

I am attempting to convert two non-trivial  
functions from Python to Julia:

```julia
qubovert.utils.qubo_to_quso
qubovert.utils.quso_to_qubo

```

The first function replaces boolean  
variable inputs (0,1) within quadratic  
functions with spin variable inputs  
(-1,1). The second function does the  
opposite.

Are there any among you who might be  
able to share your general thought or  
process for converting these functions  
from Python to Julia? Otherwise, if you  
could point us to some resources that  
explain the rudiments, this could benefit  
all those watching.

Thanks,

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [April 19, 2022, 12:37am UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/2 "2022-04-19T00:37:04Z")

</div>

> [@YummyPampers2](#):
>
> **Disclaimer** : Please maintain some level  
> of professionalism/community by attempting to  
> answer the question presented, following-up for  
> clarification or simply passing along if you  
> are neither interested nor able to answer. Do  
> not lecture me about MWEs, this is not the only  
> way to address/approach problem sets or  
> theoretical questions. However, if you could  
> provide one that is instructive, I would  
> appreciate it.

Nah. I think this is a low effort question that doesn’t respect the time or efforts of the people on this forum answering questions, and it seems you’ve actually put less effort into your question than you put into trying to dissuade people like me from asking you to phrase your question in a more productive way.

While MWE’s are fantastic tools, you are right they’re not the only way to approach questions. However, putting no effort into even linking to the relevant package, or explaining what these functions do, and not demonstrating any effort on your part to understand how you could have done this yourself and then outlining where you ran into trouble, I think is a bad thing and posts like this should not be encouraged.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 19, 2022, 12:43am UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/4 "2022-04-19T00:43:36Z")

</div>

Write unit tests in Python, translate them to Julia, fix the issues they show in Julia. Just did that over Easter…

---

<div class="post-metadata">

**Author:** ![ImreSamu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imresamu/32/20677_2.png) [@ImreSamu](https://discourse.julialang.org/u/ImreSamu)\
**Post date:** [April 19, 2022, 12:44am UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/5 "2022-04-19T00:44:27Z")

</div>

> [@YummyPampers2](#):
>
> I am attempting to convert two non-trivial  
> functions from Python to Julia:
> 
> ```julia
> qubovert.utils.qubotoquso
> qubovert.utils.qusotoqubo
> 
> ```

for the other readers:  
as I see - the python implementations is `quso_to_qubo`

> <https://github.com/jtiosue/qubovert/blob/master/qubovert/utils/_conversions.py#L279-L342=>

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [April 19, 2022, 12:44am UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/6 "2022-04-19T00:44:56Z")

</div>

@ufechner7 – This is exactly what I was looking for.  
Such a simple answer, that allows me to build from the  
rudiments. Thank you!

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [April 19, 2022, 1:07pm UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/8 "2022-04-19T13:07:29Z")

</div>

> [@Workflow for converting Python scripts](https://discourse.julialang.org/t/workflow-for-converting-python-scripts/32737/3):
>
> My recipe for converting from one language to another is quite simple, at least when the second language is able to fully wrap the first one, which is the case for Julia thanks to PyCall. This is what I usually do when I go from Python -\> Julia: Create a script/workflow which you want to port to Julia, this can be something easy like calling a function, or more complex, like full analysis chain. Smaller steps are easier though. Write unit tests and/or high level tests in Julia to have an autom…

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [April 19, 2022, 1:36pm UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/10 "2022-04-19T13:36:19Z")

</div>

Thank you for your insights. I believe your  
intention was to help. You will notice that  
two high-level responses were provided  
from those who seem more familiar with  
the topic which were the guidelines I was  
looking for – with no MWEs nonetheless.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [April 19, 2022, 3:31pm UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/11 "2022-04-19T15:31:33Z")

</div>

> [@Mason](#):
>
> Nah. I think this is a low effort question that doesn’t respect the time or efforts of the people on this forum answering questions, and it seems you’ve actually put less effort into your question than you put into trying to dissuade people like me from asking you to phrase your question in a more productive way.

It seems to me the user has been around for some time here and I’ll assume he has a very bad day. But this

> [@YummyPampers2](#):
>
> I appreciate your humility and also  
> your basic reading comprehension.

is either a translation problem of a non native speaker or inappropriate (correct me if I’m wrong).

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 19, 2022, 3:42pm UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/12 "2022-04-19T15:42:25Z")

</div>

There might have been some communication issues, but I like the answer marked as solution, it also helps me to use an improved approach in the future.

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [April 19, 2022, 6:32pm UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/13 "2022-04-19T18:32:07Z")

</div>

@goerch – Not a translation or non-native English  
speaker problem. The entire statement was directed  
to @Eben60, the contributor who provided the fullest  
solution/thought process without incident.

Yes – perhaps the other user, was a little upset about  
something else. But I appreciated the time he spent  
sharing his opinions.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [April 19, 2022, 6:39pm UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/14 "2022-04-19T18:39:39Z")

</div>

@YummyPampers2,

I’m not a native speaker, but in my understanding your comment seems to dispute the abilities of readers of this group and this I don’t like very much.

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [April 19, 2022, 6:42pm UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/15 "2022-04-19T18:42:33Z")

</div>

@goerch – That was NOT my intention.  
Your question or post read as if, you were  
saying that I incorrectly heralded the  
person who provided the most comprehensive  
thought process.

Also, I do not know anyone who would reply to  
my posts. My assumption is that those who  
contribute can provide overarching direction,  
a MWE (if appropriate), or ask for clarification.

---

<div class="post-metadata">

**Author:** ![bernalde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernalde/32/4267_2.png) [@bernalde](https://discourse.julialang.org/u/bernalde)\
**Post date:** [April 22, 2022, 4:42pm UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/16 "2022-04-22T16:42:27Z")

</div>

On a related issue, if you are interested in the reformulation of optimization problems into QUBO, you should check our package [toQUBO.jl](https://github.com/psrenergy/ToQUBO.jl) where we have implemented the transformation of binaries to spins and many more things. Feel free to leave any comments regarding your use case and we can talk about that more in depth. Moreover, if you want to contribute to it, we can always use more hand 🙂

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [April 24, 2022, 5:32am UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/17 "2022-04-24T05:32:24Z")

</div>

This was very helpful! I appreciate that you  
were not deterred by the disclaimer.

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [April 24, 2022, 5:55am UTC](https://discourse.julialang.org/t/non-trivial-conversions-python-to-julia/79665/18 "2022-04-24T05:55:25Z")

</div>

Thank you – I will continue the  
stream there. I actually reached  
out to the members previously for  
a closed issue.
