A future represents an asynchronous computation obtained by use of async.
#voice-chat-text-1
1 messages ยท Page 35 of 1
I don't like that
Hello
cx is very repetitive
Is cx more common in other languages as well?
ctx is more common I think
I've definitely seen cx somewhere else but don't remember where
@Circuit.gatemethod
def Identity(self,
qubit_indices: int | Collection[int]) -> None:
# Create an Identity gate
identity = I
# Apply the identity gate to the specified qubit(s)
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.append(identity(self.qr[index]))
else:
self.circuit.append(identity(self.qr[qubit_indices]))
AF what do you think about the comments?
I am going for a more detailed and well documented approach.
first one is wrong
Why?
you're not creating it
It's the pointer to the method that creates the identity gate.
second comment should be the doc comment of the entire function
It is, this is a subclass.
I don't repaste the docs for subclasses (docstring I mean).
comment why not what
what's written in the comment is implied by the function and doc comment of the base class
Well, would you remove it entirely?
And if so, do you personally find it as readable and comprehensive?
Apply the identity gate to the specified qubit(s) describes what happens below
not why certain design decisions where made
Well, yes, but isn't comment also to explain what a few lines of code are doing so you don't necessarily have to read every line?
Like I interpret it as answering why we're iterating a loop and appending the object to the circuit.
Is that wrong?
having to write a comment is always a hint that you're doing something wrong
Yeah, but even when I have perfectly readable code I find it nice to add some comments.
this should probably be a separate function with argument f
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.append(f(self.qr[index]))
else:
self.circuit.append(f(self.qr[qubit_indices]))
I honestly feel naked without it.
Linux doesn't have viruses. It has security vulnerabilities.
in that function explain why you if and why Collection
That's fair.
How so?
I don't follow.
tbf in that isolated function it wouldn't even require an explanation
simple enough, and types are right there
Linux, but chaos monkey. Randomly introduces problems you have to learn to fix.
Nub.
I see. I'll update the codebase then (to not refer to method pointers as Create gate and remove comments accordingly).
(I can't explain this concisely enough; there exist some better worded and better illustrated sources on that topic)
@Circuit.gatemethod
def RX(self,
angle: float,
qubit_index: int) -> None:
# Create an RX gate with the specified angle
rx = Rx(rads=angle)
self.circuit.append(rx(self.qr[qubit_index]))
What about this one?
I get what you mean.
One would try to compensate for clarity with comments.
# add 1 to x
x = x + 1
Ergo, given adequate clarity comments are not needed.
outer thing should mention that it's not degrees
Oh that's not needed (we always pass in radians).
I haven't seen anyone pass in degrees.
why does Rx constructor have it named rads
radians.
a bit inconsistent but okay
It's from cirq.
I'm only wrapping it here.
Would you keep the comment or remove it?
Technically it's an object (proper instance).
the comment doesn't add anything
@proper junco you can have examples/tests directories
a bit more persistent form of scratch files
in Rust, cargo has ./examples/ support
for running stuff in the context of the project but outside src/main.rs
./tmp
rrrrrr
I often have a gitignored /tmp/ at the root of a project for stuff that's definitely not needed afterwards
ignore venv entirely
there are many points of customisation in there, probably don't just blindly copy it if you're making a project that others will use
ensemble joke
everyone participates
Huh. This is a thing https://www.limitless.ai/#pendant
I'd rather buy another x86-64 computer for that
Just clip a RaspberryPI to your shirt
implant it
there are different arduinos
some are proper ARM
some are microcontrollers
(those two might overlap)
What about this one?
@Circuit.gatemethod
def MCX(self,
control_indices: int | Collection[int],
target_indices: int | Collection[int]) -> None:
control_indices = [control_indices] if isinstance(control_indices, int) else control_indices
target_indices = [target_indices] if isinstance(target_indices, int) else target_indices
# Create a Multi-Controlled X gate with the number of control qubits equal to
# the length of control_indices
mcx = cirq.ControlledGate(sub_gate=X, num_controls=len(control_indices))
# Apply the MCX gate controlled by all control indices to each target index
for target_index in target_indices:
self.circuit.append(
mcx(*map(self.qr.__getitem__, control_indices), self.qr[target_index])
)
A handful of the tools the presenter mentioned are Mac only
whole 8 ports not installed
Greetings The Annoyed!
I've seen executables compiled for aarch64 run on x86-64
like
what
how
default ARM
I think
yes, RISC
@mild flume inherited
H4s support less memory than H3s but at a higher speed
H4s have a CPU with AVX support which means being able to run MongoDB >4.4
Forgot that was a thing
MongoDB making AVX mandatory is such a problematic choice given how many hobbyists pick mongo for simplicity (only to end up in a situation where they don't have necessary hardware for it)
@proper junco you will almost always need a ipython kernel running
even conversion to html involves it
VSC has Jupyter support
jupyterlab is more complex
it's an extension of jupyter
you can put examples in something like Sphinx
or mkdocs
I'd expect both allow running them as inline tests
TeX is hard to read
when not rendered
it's optimised for writing not reading
@proper junco yes
in some Markdown cases it's supported
e.g mdbook
there's also an interesting question of how to embed diagrams
in my experience, all simple text to diagram software produces terrible results
like totally abhorrent at times
not something you would ever want to put where others can see
(or even where you yourself can see)
mermaid is close to being adequate
Create diagrams and visualizations using text and code.
generic is markup
technically it is markup too, it's not in opposition
I don't like this
why does it overlap
rrrrrrrrrrrr
draw.io prevents such overlaps by default
by cutting out a part of the line
oh wait
I need to send the whole picture
the part on the top right specifically
what would a software equivalent of hypochondria be
healtchecks causing performance issues?
@mild flume "made to rival Arnold C"
Try MIT OCW 6.092
@proper junco
"every IO object has a file descriptor" rather
pidfd is very recent
like only 5 years
hmm
2015
In video game development, programmer art refers to temporary assets added by the programmer to test functionality.
With this type of graphics, speed is a priority and aesthetics are secondary (if they are given any consideration at all). In fact, programmer art might be intentionally bad, to draw attention to the fact that the graphics are me...
that's the MS Paint joke
That's sick looking
Python is somewhat hard to write esoterically
because not free-form
lambda is ugly not esoteric
unlike C
#include <stdio.h>// Usage: find k (<=n) roots of polynomial f such that deg f=n; Input: n c_0 c_1 ... c_n | c_i: double
#include <math.h>// Output: roots:k x:x_1 f:f(x_1) x:x_2 f:f(x_2) ... x:x_k f:f(x_k) | x, f: double | roots are ordered
#include <float.h>// non-descenging. Note that roots can be repeated due to divisibility of f by (x-root)^k where k > 1!
#define P(o)if(B o T){for(u i=2048;i;--i){d m=(b+t)/2;*((d*[]){&b,&t})[0 o a(n,c,m)]=m;}return b;}// (c) afeistel 2020~2025
typedef double d;typedef unsigned short u;d a(u n,d*c,d x){d r=0;for(u i=n;i;--i)r=(r+c[i])*x;return r+c[0];}d s(u n,d*c
,d b,d t){d B=a(n,c,b);d T=a(n,c,t);P(<=)P(>=)return NAN;}u h(u n,d*c,d*g,u*r){while(n&&!c[n])g[--n]=NAN;if(n==0)return-
0;for(u i=1;i<=n;++i)c[i]*=i;h(n-1,c+1,g+1,r);for(u i=1;i<=n;++i)c[i]/=i;g[0]=-DBL_MAX;u j=0;for(u i=0;i<*r+1;++i){d t=i
<*r?g[i+1]:DBL_MAX;d B=a(n,c,g[i]);d T=a(n,c,t);if(B<=0&&0<=T||B>=0&&0>=T)g[j++]=s(n,c,g[i],t);}for(u i=j;i<n;++i)g[i]=-
NAN;*r=j;return 0;}int main(){u n;scanf("%hd",&n);d c[n+1];for(u i=0;i<n+1;++i)scanf("%lf",c+i);d g[n];u r;h(n,c// stuff
,g,&r);printf("roots:%d\n",r);for(u i=0;i<r;++i){printf("x:%f\nf:%f\n",g[i],a(n,c,g[i]));}return 0;}// cmake C 99 x86_64
This is ugly to me.
Too messy.
damn bro even copyrighted it
esoteric often implies ugly but not the other way around
this is just minified
not really esoteric
In my experience from watching the OCW courses, the one thing I've learned is always assume the audience knows nothing and explain everything as clearly and efficiently as possible.
I feel the same applies to code style.
I needed to fill empty spaces because pre-processor directives aren't collapsable
You don't want to rant like I did before in your comments, or restate everything, but it does help every few lines.
And it does make the code seem prettier.
real problem with this code is that it's quadratic in implementation
because it doesn't use complex numbers
I'm not discussing performance though.
Just the visual appearance of it.
(if not clear, this is intentional)
also guys don't listen to the js nerds who use arrow functions for everything
if you want something that's actually esoteric:
([]+![])[+!![]]+([]+![])[!![]+!![]]+([]+[][[]])[!![]+!![]+!![]+!![]+!![]]+([]+![])[!![]+!![]+!![]]+([]+![])[+!![]]+([]+{})[!![]+!![]+!![]+!![]+!![]+!![]+!![]]+([]+![])[+![]]+([]+![])[!![]+!![]+!![]+!![]]+([]+[][[]])[!![]+!![]+!![]+!![]+!![]]+([]+![])[!![]+!![]+!![]]+([]+!![])[+![]]+([]+![])[!![]+!![]+!![]+!![]]+([]+![])[!![]+!![]]
JS
It's so crazy how you can leverage the weird stuff
gangster babushka
This was more than half of my professors.
Add a cat and some vegetables to clean and that's a proper siti.
Rust allows some quite unusual stuff with lambdas
(e.g. solution to https://parrrate.github.io/exercises/exercises/get_functions.html)
@mild flume you can try solving that one ^, it's relatively simple
I should probably make a PR to rustlings adding something like that
Alisa what do u gain from this
pygame 2.6.0 (SDL 2.28.4, Python 3.10.14)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "/nix/store/pbimfaxwiyagpkylc739nprkyyqziv2l-python3.10-replit-python-dap-wrapper-1.8.0/bin/.dap-python-wrapped", line 43, in <module>
_main()
File "/nix/store/pbimfaxwiyagpkylc739nprkyyqziv2l-python3.10-replit-python-dap-wrapper-1.8.0/bin/.dap-python-wrapped", line 39, in _main
runpy.run_path(target_as_str, run_name="__main__")
File "/nix/store/rwxj49zghamyhy07b67yhiq64bmznvmm-python3-3.10.14/lib/python3.10/runpy.py", line 289, in run_path
return _run_module_code(code, init_globals, run_name,
File "/nix/store/rwxj49zghamyhy07b67yhiq64bmznvmm-python3-3.10.14/lib/python3.10/runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/nix/store/rwxj49zghamyhy07b67yhiq64bmznvmm-python3-3.10.14/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "edter_run.py", line 10, in <module>
wm.add_window(window)
TypeError: Manager.add_window() missing 1 required positional argument: 'window'
import edter
import pygame as pg
import edter.WindowManager
window = "edter"
wm = edter.WindowManager.Manager
wm.add_window(window)
pg.init()
screen = pg.display.set_mode((1280, 720))
clock = pg.time.Clock()
running = True
focussed = True
pg.display.set_caption(window)
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
pg.display.flip()
clock.tick(60)
if __name__ == "__main__":
pass
missing ()
wm = edter.WindowManager.Manager()
making code readable for everyone is idealistic goal, which can't be achieved without damaging some other properties of the code
Comments that contradict the code are worse than no comments.
first line on comments from pep8
dont worry nobody uses pep8 , not even the std lib in python follows pep8 ๐
if you can't ensure it's in sync with code, it will get wrong eventually
The Python standard library is conservative and requires limiting lines to 79 characters
some parts of pep8 are just recommendations, but some are enfornced in codebases
many codebases, including the standard library
# this function returns the square root of x
def sqr(x):
return x*x
๐ contradictory comments!
this happens in real codebases
in the past it was just from people chasing "comment everything" metrics
and now it's also because of AI tools
I mean yeah, not to the T, but some of the stuff there I genuinely like.
ChatGPT by default is trained to comment everything
called it
I don't like to make my own style, I would like to be consistent with what's considered best practice, BUT I want it to be very comprehensive to absolute beginners as well.
which means if it doesn't understand the code, it will make a wrong comment
I don't use that, I write my own comments.
Noooo...
because appearance of the comment existing is more important to the AI than its contents
I prefer black over any alternative apart from, maybe, ruff
(ruff an lint style and is separate from black iirc, but quite close to it)
ruff also nice
@proper ridge no
it also has ( separate
this no adequate formatter does:
(a
b
c
)
No what?
newline before ) but without newline after (
this style gets ugly, often, due to its tendency to waste space
(a
b
c
d)
also not aligned to tab width
isort by default uses that style
and it's terrible if you import many things from a deeply nested module
def foo(
bar,
baz,
) -> spam:
return eggs
can you share your clang-format settings?
it's an altered version of some base template
https://gist.github.com/afeistel/200a6ddea5d426bce95473583c682fec
most settings come from the template
(I don't fully know what each setting does)
there definitely is some redundancy from specifying both the blanket rule and specific to same value
spasibooooooooo
๐
now i need to recall where to tweak the settings
was i supposed to put this in a .clangd file per project 
fields that are different compared to the template:
AccessModifierOffset, AlignAfterOpenBracket, AlignArrayOfStructures, AlignEscapedNewlines, AlignOperands, AlignTrailingComments, AllowShortBlocksOnASingleLine, AllowShortFunctionsOnASingleLine, AlwaysBreakTemplateDeclarations, BinPackArguments, BinPackParameters, BraceWrapping, BreakBeforeBinaryOperators, BreakBeforeConceptDeclarations, BreakBeforeBraces, CompactNamespaces, EmptyLineBeforeAccessModifier, PackConstructorInitializers, FixNamespaceComments, IncludeBlocks, IndentCaseLabels, IndentRequires, InsertTrailingCommas, KeepEmptyLinesAtTheStartOfBlocks, LambdaBodyIndentation, NamespaceIndentation, SeparateDefinitionBlocks, SpaceAfterTemplateKeyword, SpaceBeforeCtorInitializerColon, SpaceBeforeInheritanceColon, SpaceBeforeRangeBasedForLoopColon, SpacesInLineCommentPrefix, BitFieldColonSpacing, TabWidth
@proper ridge users need to know how to use the code;
so if there's anything influences the use (i.e. specific corner cases, performance considerations, etc.), that should be in docs;
if someone bothers to go and read the code, they probably can read the code, so you're not expected to guide them through it with comments; guide with code itself; write comments when it helps yourself
I see.
tricky places is what deserves non-meme comments
which in Rust would be unsafe blocks
in languages in general, that includes whenever you call C with some invariant considerations
I like to be verbose, but I also agree with you, so I'm sort of on the fence.
another impact of comments is that they slow down the reader
On one hand I really like the style of the code with comments, on the other I fully get I should just remove the comments.
and that's the good thing when code is non-trivial
That's true, but when written clearly wouldn't they enhance comprehension?
I guess I don't understand what constitutes as non-trivial.
comprehension comes from addition, not repetition or reduction
non-language-enforced invariants
, performance
nix seems to provide some conveniences
just don't go wasting your time on configuring it
btw dont do this
use it as a tool, not a higher goal, I'd say
i never use cloud services anymore since there's no telling when the provider will just delete your stuff without notice
I use NixOS to make it so I don't have to fuck around with installing shit
Just make a nice config file and use it. And then don't fuck with it.
use cloud services provided by three separate countries which are in a perpetual cold war with each other, so they can't cooperate to shut you down all at once
I then containerize everything that isn't defined on that config file
@Circuit.gatemethod
def RX(self,
angle: float,
qubit_index: int) -> None:
self.circuit.append(Rx(rads=angle)(self.qr[qubit_index]))
@Circuit.gatemethod
def RY(self,
angle: float,
qubit_index: int) -> None:
# Create an RY gate with the specified angle
ry = Ry(rads=angle)
self.circuit.append(ry(self.qr[qubit_index]))
Top or bottom?
bottom
Yall are so contradictory HEHEHEHE
lower one without a comment
I have docstrings.
inherited
So, you all prefer this?
@Circuit.gatemethod
def RX(self,
angle: float,
qubit_index: int) -> None:
rx = Rx(rads=angle)
self.circuit.append(rx(self.qr[qubit_index]))
concretion inheritance is bad
well, honestly, anything other than TI-84 Plus BASIC was a mistake
in Python, Java-style interface implementation involves class inheritance because yes
I've been using Gleam and Haskell more than python these days...so I may be biased.
docker works fine enough for me, so I don't yet have a reason to use nix
Docker costs money, use Podman instead.
yes
Haskell has classes which are same as Rust traits
and in Rust method docs on implementation are inherited from the trait definition
I use podman in CI
or buildah, to be more specific
eh, i just use it to do math /shrugs
do monads
@Circuit.gatemethod
def CX(self,
control_index: int,
target_index: int) -> None:
cx = cirq.ControlledGate(sub_gate=X, num_controls=1)
self.circuit.append(cx(self.qr[control_index], self.qr[target_index]))
@Circuit.gatemethod
def CY(self,
control_index: int,
target_index: int) -> None:
# Create a Controlled-Y gate with a single control qubit
cy = cirq.ControlledGate(sub_gate=Y, num_controls=1)
self.circuit.append(cy(self.qr[control_index], self.qr[target_index]))
```?
don't explain, just do
So, top one?
(that was a response to Clari)
Oh apologies.
monads explanation should start with:
NOT THOSE MONOIDS, DIFFERENT MONOIDS
people trying to explain monads through monoids, in majority, end up using the wrong definiton of what a monoid is
monad is a wrapper right?
monad is just monoid in category of endofunctors tbh
what is an endofunctor?
NOT THAT MONOID
functor from a category to the same category
GPT makes this when I ask for best practice
@Circuit.gatemethod
def CX(self, control_index: int, target_index: int) -> None:
# Create a controlled-X gate with one control.
cx = cirq.ControlledGate(sub_gate=X, num_controls=1)
# Append the CX gate to the circuit, targeting the specified qubits.
self.circuit.append(cx(self.qr[control_index], self.qr[target_index]))
I imagine this is definitely not best practice.
in Python terms, function from any type to some type
as a type generic
for any T that's a type, list[T] is a type too
so a monad is a functor within a category
the only category interesting in programming for monads is type category
(in most languages; not in Rust, not in C++)
template types?
templates behave as type->type functions too, yes
so we don't need monads if we have templates?
I have been trying to learn Go. I suck at Go and I suck at Git, so I've been doing the "Build your own git in go" thing that CodeCrafters has to Git Good at both.
functors are just a mathematical description of what a thing like a C++ template is
how can you suck at Go? it's just dressed up C
I suck at C too
even has the goto keyword ๐
I never needed it, so I never practiced it
Java has goto reserved
still waiting
As a result I am just as good with Go and C as I am with .NET and Scala.
therefore a monad == template type
with some operations
for SomeTemplate to be a functor, it also needs to provide a function that can:
given SomeTemplate<A> and std::function<B, A> produce SomeTemplate<B>
and that's why i use flatpacks instead of appimages. if someone wants to contact me on ms teams i pull out my mac.
@Circuit.gatemethod
def X(self,
qubit_indices: int | Collection[int]) -> None:
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.append(qml.PauliX(wires=index))
else:
self.circuit.append(qml.PauliX(wires=qubit_indices))
@Circuit.gatemethod
def Y(self,
qubit_indices: int | Collection[int]) -> None:
# Create a Pauli-Y gate
y = qml.PauliY
# Apply the Y gate to the specified qubit(s)
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.append(y(wires=index))
else:
self.circuit.append(y(wires=qubit_indices))
```?
ffs it's 35 degrees (sane units not freedom units) out
normal around here is 25 degrees
at least in july
I'm wrapping it, so I don't need to pass f to do it.
I don't like to use functools.partial.
Feels weird.
f = qml.PauliY
So you prefer the bottom one?
*method
I will sometimes call methods functions for the exact same reason I'll call directories folders, or containers VMs.
I just want to see the world burn.
def run_gate(self, f: ???, qubit_indices: int | Collection[int]) -> None:
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.append(f(wires=index))
else:
self.circuit.append(f(wires=qubit_indices))
@Circuit.gatemethod
def X(self,
qubit_indices: int | Collection[int],
f) -> None:
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.append(f(wires=index))
else:
self.circuit.append(f(wires=qubit_indices))
```?
Ok...
Then I'd need partial to implement x, y, z etc.
you don't need to change that much
like literally just refactor the code
and pass in values as you do alreadty
I mean I don't get why do this.
though repetition sometimes is okay, in this case it's really excessive
it's a common behaviour that can trivially be refactored all across the code
applicative (extension of functor) adds to this:
A -> SomeTemplate<A>
SomeTemplate<A>, SomeTemplate<B>, std::function<C, A, B> -> SomeTemplate<C>
monad (extension of applicative) adds:
SomeTemplate<SomeTemplate<A>> -> SomeTemplate<A>
But then I'd need to define new methods, like non_parameterized_single_qubit_gate, parameterized_single_qubit_gate, non_parameterized_controlled_gate, and parameterized_controlled_gate.
And have the methods I have (X, Y, etc.) be functools.partial.
if it's repeated at least three times, then refactor
By refactor you mean define partial for them?
How would I maintain the same interface if I don't have a method for each gate?
Partial seems like the only way.
some have the exact same interface
Users need to do circuit.X(0), circuit.Y(0), etc.
there is a common shared interface which is the if structure
I need X and Y to still be methods themselves.
what you do around and deep inside is separate
I don't think I fully understand.
>>> list_map([1, 2, 3], lambda a: a + 1)
[2, 3, 4]
>>> list_pure(1)
[1]
>>> list_map2([1, 2], [3, 4], lambda a, b: a * b)
[3, 4, 6, 8]
>>> list_join([[1, 2], [3, 4]])
[1, 2, 3, 4]
Name=Aseprite
Exec=Aseprite
Terminal=false
Type=Application
Categories=Graphics```
Isn't this what you meant AF?
def non_parameterized_single_qubit_gate(self,
gate: OpType,
qubit_indices: int | Collection[int]) -> None:
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.add_gate(gate, [index])
else:
self.circuit.add_gate(gate, [qubit_indices])
X = partial(non_parameterized_single_qubit_gate, gate=OpType.X)
Y = partial(non_parameterized_single_qubit_gate, gate=OpType.Y)
Z = partial(non_parameterized_single_qubit_gate, gate=OpType.Z)
H = partial(non_parameterized_single_qubit_gate, gate=OpType.H)
S = partial(non_parameterized_single_qubit_gate, gate=OpType.S)
T = partial(non_parameterized_single_qubit_gate, gate=OpType.T)
```?
mau i know what are you doing
async def future_map(a, f):
return f(await a)
async def future_pure(a):
return a
async def future_map2(a, b, f):
reutrn f(*await asyncio.gather(a, b))
async def future_join(a):
return await await a
AF suggested sth. I'm trying to see if I understood it correctly.
keep going mate
you can have a more strictly typed specialisation of partial to have it simpler to understand in code
Other way I can think of is to literally define X, Y, Z, H, S, and T as partials in my ABC from the get-go, with gate="X", and then make a dict for what the keys match to what (like here it's OpType.X for TKET) and then just implement the non_parameterized_single_qubit_gate in the subclass.
(I don't know the scope of the whole thing, so can't make suggestions more concrete than "this shouldn't be repeated", even if that one non-specific suggestion is very strong)
It's what you see there, nothing more.
I can use partial like I said to not repeat the same code over and over but maintain the same interface as I have now (where users can call circuit.X() blah blah).
Is that what you meant?
Though with partial how would I write docstrings?
initially it was about just a straightforward refactor like this:
def a():
for item in something:
do(1)
def b():
for item in something:
do(2)
def c():
for item in something:
do(3)
def common(x):
for item in something:
do(x)
def a():
common(1)
def b():
common(2)
def c():
common(3)
I see, so instead of partial you want to call it explicitly.
Same thing as partial does I imagine.
Though yours allows me to add docstring.
which would reduce DIFFERENT_SIGNATURES * 6 to DIFFERENT_SIGNATURES (6 being X,Y,Z,H,S,T)
in terms of the number of times that part gets repeated
reduce in a simple dumb way; reduce further later if needed
common must not have a and b mentioned at all
What would you think about
class Base(ABC):
def __init__(self,
blahblah) -> None:
....
@abstractmethod
def common(self,
x) -> None:
...
def a(self) -> None:
common("a")
def b(self) -> None:
common("b")
class Subclass(Base):
def common(x) -> None:
gate_mapping = {"a": OpType.X, "b":OpType.Y}
gate_mapping[x]()
def a(self) -> None:
common(OpType.X)
Well, the goal is to not repeat a in the subclass.
there is no reason displayed there for why mapping is necessary
Reason being that you would avoid explicitly defining .a() and .b() and endure repetitive code. Instead, you would set .a() and .b() in Base and just define how they are implemented in each subclass by defining a mapping for what they need in place of x.
!zen
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
is OpType.X common for all implementations of Base?
Harder to read (feels more complex), but would have least number of lines.
Each subclass would need a different value for "a" so no.
Hence the need for the dict in each subclass.
Added in version 3.4.
Source code: Lib/enum.py...
just not with a string
Why not?
With the string set in Base, I don't have to repeat a and b in Subclass.
Literal["X"] | Literal["Y"] | Literal["Z"] | Literal["H"] | Literal["S"] | Literal["T"]
Oh, you mean for the type hint.
Gotcha.
Lemme try this.
!e
from enum import StrEnum, auto
class Axis(StrEnum):
X = auto()
Y = auto()
Z = auto()
H = auto()
S = auto()
T = auto()
print(Axis.Y)
print(Axis.Y == "y")
print(type(Axis.Y))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | y
002 | True
003 | <enum 'Axis'>
another option
Which is better?
depends on whether you want to allow plain str to be accepted
convenience vs strictness
Plain str is passed so yes.
But I want it to show not any str in the type hint like you had.
Just X, Y, Z, H, S and T.
!e
from enum import StrEnum, auto
class Axis(StrEnum):
X = auto()
Y = auto()
Z = auto()
H = auto()
S = auto()
T = auto()
print(isinstance(Axis.Y, str))
print(isinstance("y", Axis))
print(Axis("y"))
try:
Axis("other")
except Exception as e:
print(e)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | True
002 | False
003 | y
004 | 'other' is not a valid Axis
interface with Literal["x"] | ...,
implementation with class Axis(StrEnum)
So, I want to pass for instance "X", and interpret it as a string and check it in my dict. I want to know how I can properly type hint it though.
Is this correct?
NON_PARAMETERIZED_SINGLE_QUBIT_GATES = Literal("Identity") | Literal("X") | Literal("Y") | Literal("Z") | Literal("H") | Literal("S") | Literal("T")
Probably not?
By the way, how would this impact performance? We are adding a few additional steps in return for removing dozens of lines (Thousands actually).
MAPPING = {
Axis.X: ...,
Axis.Y: ...,
...: ...,
}
AxisLike = Axis | Literal("x") | Literal("y") | Literal("z") | Literal("h") | Literal("s") | Literal("t")
def example(axis: AxisLike):
op = MAPPING[Axis(axis)]
What's Axis here?
.
using that to get 'other' is not a valid Axis error message for free
I will do that check myself to add it as an error. I just want to know how to type hint it properly instead of just str.
!e
from enum import StrEnum, auto
class Axis(StrEnum):
X = auto()
Y = auto()
Z = auto()
H = auto()
S = auto()
T = auto()
match Axis.Y:
case Axis.X: print("X")
case Axis.Y: print("Y")
case Axis.Z: print("Z")
case too_lazy_to_do_the_rest: print("what")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
Y
similar to PathLike
I am so sorry, I'm having a hard time understanding this.
just checking that match works
No I get the match part. I don't get what Axis is.
Axis.X, ..., Axis.T are all the possible instances of Axis
Why can't we just use Literals instead?
conversion to Axis checks that str is valid
Feels clearer that it must be either X, Y, Z, H, S, or T.
and Literal unions get somewhat big
So why have them in the first place then?
hard to look at when type hints are involved
I don't get why we'd keep both.
Literal union for inputs to allow both Axis.X and "x" to work
if that's ever necessary
even if we only allow "x" as input, conersion to Axis.X on the inside still makes sense
(see the error message)
My neanderthal brain understands having an explicit check with if not in ["X", "Y", "Z"] better.
If I have a hard time understanding it, I fear others will too. Trying to keep it as simple as possible.
Using a frozenset right now.
or that
Lemme finish this example, and show you, and if all good I'll update the codebase.
lists of length >1 were slower than sets for in check last time I measured
I see.
I mean 1 is not really a list HEHEHE
this is not the case when you're working in something like Rust
where iteration is faster than hashing for a larger number of elements
For the meantime, could you have a look at this method please? I think it's written very very poorly, and since I'm changing the entire qickit.circuit module now it'd be nice to fix this too.
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
.gatemethod() one.
It handles the stuff repeated in almost all methods.
Really useful, but right now written poorly.
instance validation is critical, and having it repeated the way it is might be problematic later on
Should I add Axis as a new type to my custom types?
!e
from numbers import Real
print(isinstance(1, Real))
print(isinstance(1.0, Real))
print(isinstance(1j, Real))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | True
002 | True
003 | False
Change it to Real?
depends on what properties you rely on
Just being a float.
!e
float(1j)
:x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 1, in <module>
003 | float(1j)
004 | TypeError: float() argument must be a string or a real number, not 'complex'
hmm
Yeah, complex shouldn't be allowed.
it can just assert floatness by converting it
Like try and catch type of thing?
!e
from contextlib import contextmanager
@contextmanager
def type_error(message):
try:
yield
except TypeError as e:
raise TypeError(message) from e
with type_error("test"):
float(1j)
:x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 6, in type_error
003 | yield
004 | File "/home/main.py", line 11, in <module>
005 | float(1j)
006 | TypeError: float() argument must be a string or a real number, not 'complex'
007 |
008 | The above exception was the direct cause of the following exception:
009 |
010 | Traceback (most recent call last):
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/JBC7NP445NUBH7OS42YHYXS2EA
^ read the whole traceback of this
Go for concurrent stuff
Rust's type system isn't that new
OCaml+Haskell
well, that's just the same as with Java
some companies just use Java
because Java
Yeah, but I like C# more.
it is the better Java, as a language
JVM has more than just Java, so that keeps it alive outside Enterpriseโข๏ธ
CLR has, like
C#
F#
that's all
there is also Zig
C-adjacent
It says this is not a valid type:
NON_PARAMETERIZED_SINGLE_QUBIT_GATES = Literal("I") | Literal("X") | Literal("Y") | Literal("Z")\
| Literal("H") | Literal("S") | Literal("T")
(if you're planning to use C, nowadays you will into Zig as a toolchain)
I'll put it on my to learn list, thank you so much for the suggestion!
Name's hard to pronounce for most guys.
@lethal wadi "you don't need to use someone else's recursion if you can create your own"
lambda f: (lambda x: f(x(x)))(lambda x: f(x(x)))
(this blows up in python because not lazy)
I'd expect it's just /home/<user>/.local's version/override of /usr/local/share
So I got bored and asked various AI chat bots what they know about the PyDis (us) server:
https://www.perplexity.ai/search/are-you-aware-of-the-python-di-oOTfRnZ4Q8GxmZUy38KA0A
https://chatgpt.com/share/98859c90-49b1-4552-96ec-a253475012d3
https://www.phind.com/search?cache=sctwwvggbq1jf2i3v6036146
https://paste.pythondiscord.com/KERQ - Copilot's response
Also asked Claude, however they were not aware of the server.
Also, Copilot is slow as balls
Kind of surreal, I hadn't thought about us being knowable in this way
!e
print((lambda: lambda f: lambda: (lambda: lambda x: lambda: f()(x()(x))())()(lambda: lambda x: lambda: f()(x()(x))())())()(lambda: lambda g: lambda: lambda x: lambda: 1 if x() == 0 else x() * g()(lambda: x() - 1)())()(lambda: 5)())
:white_check_mark: Your 3.12 eval job has completed with return code 0.
120
it's all scraped by Common Crawl and given to companies like OpenAI
True true
I still thought it was neat
I wasn't joking about Copilot being slow. It's painful
i need to top up my bank account.. keep forgetting to do that ๐ฆ
at least it works
Can you do mine while you're at it?
Fair
!e
print((lambda: lambda f: lambda: (lambda: lambda x: lambda: f()(x()(x))())()(lambda: lambda x: lambda: f()(x()(x))())())()(lambda: lambda g: lambda: lambda x: lambda: 1 if x() == 0 else x() * g()(lambda: x() - 1)())()(lambda: 10)())
:white_check_mark: Your 3.12 eval job has completed with return code 0.
3628800
number of seconds in 6 weeks
do it yourself
!e
print((lambda: lambda f: lambda: (lambda: lambda x: lambda: f()(x()(x))())()(lambda: lambda x: lambda: f()(x()(x))())())()(lambda: lambda g: lambda: lambda x: lambda: 1 if x() == 0 else x() * g()(lambda: x() - 1)())()(lambda: 100)())
:white_check_mark: Your 3.12 eval job has completed with return code 0.
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
Were you expecting it to run out of memory or run out of space on the stack?
either stackoverflow or run out of time
it can compute factorial of 498
with default recursion limit
!e
print(2^(2^(2^2)))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
0
**
smh
:white_check_mark: Your 3.12 eval job has completed with return code 0.
3 2
!e
a, b = 2, 3
a **= b
b **= a
a **= b
print(a, b)
:x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 5, in <module>
003 | print(a, b)
004 | ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
integer string conversion?
yes
!e
import sys
sys.set_int_max_str_digits(1_000_000)
a, b = 2, 3
a **= b
b **= a
a **= b
print(a, b)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
1490749437483138602749298211171890771944932002222732590141543150107638430827697168860956299898208768103383042046125717680414504697162830849320642009933279918750145665098665006053232645457813304543557399402358472032673076270064074329561491188566191463794294838536284169187739762000994109181808567947703682261682667228562787084156635145887021676629723250075409894003982070022751911345085675862741997584195018068831851550656130586870150217387848281225134870058383913316670978064259909133330326265994405905843435830546918990810719009756056980229251142270914390981954951931287504270375643147681497200025450647062697740871740746391686103284614204877967678645586519738538636861361934498229220397924369801928214662429187086948360592388739423228612588402796532245819260742523155023617433434220689799427245248123190634942336603754173227848918146046320690524243866538622093549131543860879095813716209917240043402157927581271454973351431877111195879385579412993417719750515556196130302689769269190567711820432568
... (truncated - too long)
Full output: https://paste.pythondiscord.com/ORVUWXBZQZ6UWU73CTUXXEEPZQ
๐
@mortal stone graphical front-end
not bash/sh/ash/zsh/others
though if you have plain sh might as well install something else
word wrap off
word wrap on
what
(there's 6 thousand more characters that are in the line)
@atomic hinge https://chromeos.dev/en/productivity/terminal
@mortal stone reminder that Git Bash exists
from what I understand, only sh is somewhat guaranteed to be present
on Linux
(or generally OSes attempting to be POSIX-compatible)
bash is ootb on most distros
"you've said you're high; but recommending comments is too much"
all I've said today about refactoring is literally just in the books
it's literally basic software architecture theory
you need to test 3542132832.249878 rats to get one rat with an IQ of 7
Kevlin Henney
It is all to easy to dismiss problematic codebases on some nebulous idea of bad practice or bad programmers. Poor code, however, is rarely arbitrary and random in its structure or formulation.
Systems of code, well or poorly structured, emerge from systems of practice, whether effective or ineffective. To improve code quality, it m...
I'm already past the stage of following those rules too strictly
however bad Clean Code, the book, may be, towards the beginning it has some okay parts, including on splitting methods, names and comments
just don't read the examples it gives
it's really not about any outstanding ability
just, like
read a book
even if it's bad, it'll cover most of this stuff anyway
I'd expect even ChatGPT 3.5 can do this
it's one of the most non-creative parts of altering architecture
I prefer my tabs at 2.54 spaces
cm to inch
time to embed a whole dissertation-sized excuse into docs
(still writing that Rust thing)
Hello everyone ๐
@mild flume I just bought everything I could be interested in and could buy
there's nothing left no more interested in gaming really
Yeah that's what I did. I think my actually played games was like... 50%?
NFTs are more wasteful
Valorant is unplayable for me
which is good
R6 for a long time had no marketplace
I think they do now
but you can't, like, buy a game from selling skins if I understand correctly
I don't think discord decorations are overpriced
don't want, don't spend


I don't like the aesthetics of those decorations

there's nothing interesting for me to buy if I was able to
but I'm fine with their prices
which is NaN
That would be incredible
470ml for whoever was asking
Outline on its way to become the preferred markdown editor for me
the only wysiwig I'm okay with
because it's just markdown when you type it
on the website it's better than I remember it seeing previously
Yeah it's much prettier
This button only works with Discover and other AppStream application stores. You can also use your distribution's package manager.
apt-get install markdownpart
Linux commands are like "it's called 'less' because 'less is more' and it shows you more" ๐
Can I get an attaboy?
attaboy
I coded till 4 AM
Thank youu!
My left side of the brain burns.
I'm gonna go, have ALOT to change tomorrow. Hopefully it'll be an easy change (unlikely, I'll probably break sth in the process).
heck
AF, thank you so so much for the guidance, I bothered you for literally 5 hours, really really sorry.
Bless you and that 300IQ of yours.
maybe it's just lying
Cya @proper ridge ๐
Babye dear Alex!
"pretend you don't see it"
I can't speak in the VC ๐ฆ
!voice
Voice verification
Canโt talk in voice chat? Check out #voice-verification to get access. The criteria for verifying are specified there.
gotta wait for 3 days ;-;
@mild flume that makes me thing maybe my body produces ADHD meds on its own
HA
I'm new to learning python. Got any tips?
!resources
Resources
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
practice
Jupyter might be part of the bundle
oh, thanks.
VSC cred forwarding recently started misbehaving for me
tbf it wasn't fully expected to work because it's not using user-password
In that list you got linked, I recommend "A Byte of Python"
And if you have any questions or need something explained, don't hesitate to ask!
thing's still unstable
thank you so much! Will do. ๐
i code on a whiteboard
I'm scared of you.
I have low-profile keys with increased movement height (compared to what laptops have) so it doesn't feel too far from normal
What language did you guys start your coding journey with?
Right now it just says server update which has been on my pending list
i think technically either wolfram or labview
or c++
I've never heard of those...
pretty sure wolfram then c++ then labview
lines removed, lines added?
neither have i. didn't know they were languages for a long long time
or wiped
git diff whiteboard
must have been my UI prototype idea for my hangman game
I started with C++ but quit it midway after I spent 30 minutes bugging a semicolon. I want to cry.
@lethal wadi I learned Wolfram very early too; more than 10 years ago
by that time I only knew a bit of Pascal
all my classmates
*debugging
C++ ๐ซถ
I think Panda3D has kind of an interesting back-story
It was made by Disney for Disney Quest, which was like a short-lived indoor themepark they made based around video games
teach me your ways.
truly a progress in 8 years up to that point:
learned primitive arithmetic and I/O in Pascal with text-only IDE,
downloaded Java in the times of Oracle being even more cringe than now,
wrote one line of Java,
wrote some C,
wrote a lot of Wolfram, learned 2D and 3D plots, equation solving, and other stuff
wait, how many of you all are working in a company?
this won't guide but it will tell what not to do:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++
thank you
for later on, when you're getting into advanced stuff
clangd + C++20 + codeium
me when
vim + gcc + C++14 + copium
hopefully the company will give up on everything pre-Ubuntu20 soon
I'm thinking of turning vim keybindings on in Kate
maybe there's a way to embed the entire Vim into it
atleast use C++17
this way you also get all the LSPs
some parts need to be built with C++14
thankfully I don't have to deal with those
can anyone tell me how to use proxies with aiohttp ?
any environment I work in assumes smart pointer availability
because i search it up on google i did not find anything that can help me
are you having issues with headers? or do you need websocket support?
or are you using it as a client?
as a client
yes
async def get(session, url, header, proxy):
valid_proxy = set_proxy_to_dict(proxy)
async with session.get(url, headers=header, proxy=valid_proxy) as response:
return await response.json()
async def post(session, url, data, header, proxy):
valid_proxy = set_proxy_to_dict(proxy)
async with session.post(url, data=data, headers=header, proxy=valid_proxy) as response:
return await response.json()
no proxy_auth?
i tried this but not working
I want to talk on vc too!! Mods, lend me your power! SHOW ME THE WAY! [lightning strike]
three days
;-;
It'll go by faster than you think
Yea there's an environment variable you can set to disallow global pip installs
docker run -it --rm python:3.12
aiohttp.client_exceptions.ClientOSError: [WinError 64] The specified network name is no longer available i got this error
connecting to proxy by IP?
yes
PIP_REQUIRE_VIRTUALENV=true
yes
it better, I'm going insane... I thought I'd be able to discuss ideas and ask things right as I join... ;-;
only 259200 seconds
is that means that the proxy not working or what ?
Wait, you can forward discord messages now?
That's worse
Ah right, cool
you guys wanna hear a joke?
i found the solution thanks
It's for a good reason, I promise. We had what I call hit and run trolls, folks who would join the server, join VC, scream at the top of their lungs or play incredibly loud noises, and then leave. It was happening about a dozen times a day. And that's not an exaggeration
.pyc is bytecode, yes
I understand.... I hate trolls too... It's my B'day in 3 days, so it'll be the perfect gift, lol!
my birthday is rn ๐
Happy birthday!!
where's the ๐ฅ
give me strength to deal with the weird shit that happens here.
thanks ๐ป
I don't understand where the collaborative part of this app comes in
https://appflowy.io/
wanna hear a joke?
Yesterday, I was abducted by a group of mimes... they did UNSPEAKABLE things to me.
@lethal wadi there is a good self-hosted alternative to Notion: Outline
but it's not that
Outline is a good Markdown editor
wysiwig Markdown
like you literally type Markdown and you see the result inline instantly
and Outline has real-time sync
as for this, no idea
It's getting late, I should go... Good night, you guys!
Outline has Mermaid support allegedly
Create diagrams and visualizations using text and code.
it's markdown code block, yes
Mermaid is bundled by default, TeX is bundled by default
I prefer draw.io
draw.io exports SVG
so that's okay-ish for embedding
theming is hard
I prefer clicking and dragging because that ends up producing better looking results
text to diagram just isn't there yet
the emoji count at the correct number
Yeah that sounds the worst
!d import
7.11. The import statement
import_stmt ::= "import" module ["as" identifier] ("," module ["as" identifier])*
| "from" relative_module "import" identifier ["as" identifier]
("," identifier ["as" identifier])*
| "from" relative_module "import" "(" identifier ["as" identifier]
("," identifier ["as" identifier])* [","] ")"
| "from" relative_module "import" "*"
module ::= (identifier ".")* identifier
relative_module ::= "."* module | "."+
```...
Similar names: 2to3fixer.import
that
!d import the common test dummy
"why is there so much of me"
so there's part I should cut out from this
and it should be usable

Honestly it's not that hard to reach the requirements
:white_check_mark: Your 3.12 eval job has completed with return code 0.
(1+0j)
@Circuit.gatemethod
def MCRZ(self,
angle: float,
control_indices: int | Collection[int],
target_indices: int | Collection[int]) -> None:
control_indices = [control_indices] if isinstance(control_indices, int) else control_indices
target_indices = [target_indices] if isinstance(target_indices, int) else target_indices
# Create a Multi-Controlled RZ gate with the number of control qubits equal to
# the length of `control_indices` with the specified angle
mcrz = cirq.ControlledGate(sub_gate=Rz(rads=angle), num_controls=len(control_indices))
# Apply the MCRZ gate controlled by all control indices to each target index
for target_index in target_indices:
self.circuit.append(
mcrz(*map(self.qr.__getitem__, control_indices), self.qr[target_index])
)
@Circuit.gatemethod
def MCU3(self,
angles: Collection[float],
control_indices: int | Collection[int],
target_indices: int | Collection[int]) -> None:
control_indices = [control_indices] if isinstance(control_indices, int) else control_indices
target_indices = [target_indices] if isinstance(target_indices, int) else target_indices
# Create a single qubit unitary gate
u3 = [[np.cos(angles[0]/2), -np.exp(1j*angles[2]) * np.sin(angles[0]/2)],
[np.exp(1j*angles[1]) * np.sin(angles[0]/2), np.exp(1j*(angles[1] + angles[2])) * \
np.cos(angles[0]/2)]]
# Define the U3 gate class
class U3(cirq.Gate):
def __init__(self):
super(U3, self)
def _num_qubits_(self):
return 1
def _unitary_(self):
return np.array(u3)
def _circuit_diagram_info_(self, args):
return "U3"
# Create a Multi-Controlled U3 gate with the number of control qubits equal to
# the length of `control_indices` with the specified angle
mcu3 = cirq.ControlledGate(sub_gate=U3(), num_controls=len(control_indices))
# Apply the MCU3 gate controlled by all control indices to each target index
for target_index in target_indices:
self.circuit.append(
mcu3(*map(self.qr.__getitem__, control_indices), self.qr[target_index])
)
!e
a = 1
b = list(1)
:x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 2, in <module>
003 | b = list(1)
004 | ^^^^^^^
005 | TypeError: 'int' object is not iterable
def _parameterized_controlled_gate(self,
gate: Literal["RX", "RY", "RZ", "U3"],
angles: float | Collection[float],
control_indices: int | Collection[int],
target_indices: int | Collection[int]) -> None:
angles = [angles] if isinstance(angles, (int, float)) else angles
control_indices = [control_indices] if isinstance(control_indices, int) else control_indices
target_indices = [target_indices] if isinstance(target_indices, int) else target_indices
# Define the gate mapping for the parameterized controlled gates
gate_mapping = {
"RX": qml.RX(angles[0], wires=0).matrix(),
"RY": qml.RY(angles[0], wires=0).matrix(),
"RZ": qml.RZ(angles[0], wires=0).matrix(),
"U3": qml.U3(theta=angles[0], phi=angles[1], delta=angles[2], wires=0).matrix()
}
# Apply the controlled gate controlled by all control indices to each target index
for target_index in target_indices:
self.circuit.append(
qml.ControlledQubitUnitary(
gate_mapping[gate],
control_wires=control_indices,
wires=target_index
)
)
i have no idea sir
@proper jungle is your pfp of squid games?
maybe this time it's not the right choice to unify the methods
I'm just watching a video about it, would be a cool coincidence ashdahdahs
R{X,Y,Z} expect data different from U3
conditionals are often not the right way to abstract
there are simple cases where abstraction is obvious
Sandi Metz
I've been thinking about the consequences of the "wrong abstraction." ย My RailsConf 2014 "all the little things" talk included a section where I asserted: > duplication is far cheaper than the wrong abstraction And in the summary, I went on to advise: >
U3 might need to be a separate method
it is a special case, from what I see there
woah so many tabs
anything under 1000 is few
rn trying to figure out if there's a way to provide an iterator with __length_hint__ to self.circuit.extend
map doesn't define it, generator comprehensions don't define it either
u've got 1000 tabs open at a single time? :0
there was a screenshot somewhere there with "you're about to close 49XX tabs, are you sure?"
code rearrangement
trying to simplify how it's structured
by factoring out common elements
Cool, what's the code about?
something quantum-related
Dont we need quantum computers to do quantum-computing stuff?
It is not squid games look at the background
It's hard to see due to the llama crown
But based on what you've said and the culture library in my brain:
La casa de papel?
@versed elk wait are you a c++ dev
for proper quantum computing, yes, you need that
but it's cheaper to model and test it on a conventional computer first, while you're still developing
Why do you ask? *genuine fear
!rule 9
!rule 1
1. Follow the Python Discord Code of Conduct.
!rule 2
2. Follow the Discord Community Guidelines and Terms of Service.
Police fast as lightning
(you ask still for ask for non-contractual collaboration)
e.g. if you have an open-source project
Anyway, the only thing I have with C++ is that I have researched extensevely C, C++ and C# characteristics and pros and cons yesterday, I never written even a CHARACTER in any of them (yet, probly)
Wish you luck in your find for a collaborator o/ ^^
I saw it
but I didn't knew it until I researched
for language similar to C, there's Zig
for C++, Rust
for C#, Java
I'm somewhat aware of the general characteristics now
Wrapping gate-based quantum computing packages for a singular interface.
In Layman terms, writing code that can be translated to Qiskit, Cirq, PyTKET, Pennylane or CUDA-Quantum packages.
Bro, I NEVER heard of that Zig language in my ENTIRE LIFE, and I've been ocasionally doing broad researches about programming for several months now, from what deep rabbit butterfly horse snake hole of the earth did this language just appereaded that suddenly I stand upon it in 5 different ocasions?
part of Zig's popularity is its build system
you can use Zig to build parts of C/C++/Rust
It's like life was just a simulation and suddenly
*Insert new language
*Insert new language into everyone's memory as if it existed from X years ago
*Create new videos and make as if they were posted months ago
*No one will suspect
as a replacement for both the linker and the larger build framework (both at make-like and cmake-like layers)
first time I interacted with Zig beyond reading/watching was in around October-November 2023
@slow terrace ChatGPT is bad for review
I feel like the world will now try to gaslight me into believing it was always there since I was born
World gaslighting me:
you'll have to re-review the review it produced
HMMMM
for me ChatGPT and alike are just a waste of time
like a toy
I read and test code way more often than I write it
I'm completely fine with increasing the time I write code by 2~3 times
I'm ready for Java
@slow terrace you can build your own AI tools on top of it, yes, and that's actually quite useful
I tried it for the first time a week ago, it was ALOT FUN, in the first hour, later I was kinda "Okay, we reached your limits babe ๐ "
like
ChatGPT helps you => find a way to embed it into your IDE/dev process in a way different than what Copilot does
It may have passed to me a lot of missinformation about how windows works, but thaaaat's a surprise for later
As I have no knowledge to know it right now
and then you realise Rust's development began 18 years ago
*Think for a moment
Rust was in pre-1.0 for 9 years
That's unexpected based on what I see about Rust, when I see it
Zig has been in pre-1.0 for 8 years so far
I would think it was 5-10 years old
(Realizing 2015 is almost 10 years ago as I was just about to say, "Ohhh. then it WAS almost 5 years ago")
there are some specific advances that made Rust gain popularity
the most important being around 2018 with the stabilisation of async-await
the primer half of the life or the latter?
hmmmmmmmmmmm
and Zig, what the hell happened with it, why it suddenly (seemingly) sprouted out of nowhere?
^ this
also thanks to some specific projects that use it
examples: tigerbeetle, bun
oh, this like sole-handedly carried it?
not entirely
what they do? (generally)
I'm going to sleep soon
tigerbeetle is a financial transactional database
bun is a JavaScript runtime/toolchain
as a replacement for Node.js
toolchain?
tools for building, testing, packaging
hmmmmmmmmmm
Python made async/await strict keywords in the same year
@ashen willow you're using raw HTML, right? or are you using a framework?
dropdown like this?
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select
(I haven't heard what the question actually was, only heard dropdown)
where do you expect it to show up?
somewhere else on the site or overlayed on top?
Brb, gonna grab a snack.
scroll down to second example
<dialog>
<button autofocus>Close</button>
<p>This modal dialog has a groovy backdrop!</p>
</dialog>
<button>Show the dialog</button>
::backdrop {
background-image: linear-gradient(
45deg,
magenta,
rebeccapurple,
dodgerblue,
green
);
opacity: 0.75;
}
const dialog = document.querySelector("dialog");
const showButton = document.querySelector("dialog + button");
const closeButton = document.querySelector("dialog button");
// "Show the dialog" button opens the dialog modally
showButton.addEventListener("click", () => {
dialog.showModal();
});
// "Close" button closes the dialog
closeButton.addEventListener("click", () => {
dialog.close();
});
this is the code they provide for the example
dialog is somewhat new
chrome/opera: since 2014
edge: since 2020
firefox/safari: since 2022
as a single file:
<style>
::backdrop {
background-image: linear-gradient(
45deg,
magenta,
rebeccapurple,
dodgerblue,
green
);
opacity: 0.75;
}
</style>
<dialog>
<button autofocus>Close</button>
<p>This modal dialog has a groovy backdrop!</p>
</dialog>
<button>Show the dialog</button>
<script>
const dialog = document.querySelector("dialog");
const showButton = document.querySelector("dialog + button");
const closeButton = document.querySelector("dialog button");
showButton.addEventListener("click", () => {
dialog.showModal();
});
closeButton.addEventListener("click", () => {
dialog.close();
});
</script>
uwuser
โ @ashen willow can now stream until <t:1720794475:f>.
def _non_parameterized_single_qubit_gate(self,
gate: Literal["I", "X", "Y", "Z", "H", "S", "T"],
qubit_indices: int | Collection[int]) -> None:
# Define the gate mapping for the non-parameterized single qubit gates
gate_mapping = {
"I": qml.Identity,
"X": qml.PauliX,
"Y": qml.PauliY,
"Z": qml.PauliZ,
"H": qml.Hadamard,
"S": qml.S,
"T": qml.T
}
# Apply the gate to the specified qubit(s)
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.append(gate_mapping[gate](wires=index))
else:
self.circuit.append(gate_mapping[gate](wires=qubit_indices))
def _parameterized_single_qubit_gate(self,
gate: Literal["RX", "RY", "RZ"],
angle: float,
qubit_index: int) -> None:
# Define the gate mapping for the parameterized single qubit gates
gate_mapping = {
"RX": qml.RX,
"RY": qml.RY,
"RZ": qml.RZ,
}
self.circuit.append(gate_mapping[gate](angle, wires=qubit_index))
def _non_parameterized_controlled_gate(self,
gate: Literal["X", "Y", "Z", "H", "S", "T"],
control_indices: int | Collection[int],
target_indices: int | Collection[int]) -> None:
control_indices = [control_indices] if isinstance(control_indices, int) else control_indices
target_indices = [target_indices] if isinstance(target_indices, int) else target_indices
# Define the gate mapping for the non-parameterized controlled gates
gate_mapping = {
"X": qml.PauliX(0).matrix(),
"Y": qml.PauliY(0).matrix(),
"Z": qml.PauliZ(0).matrix(),
"H": qml.Hadamard(0).matrix(),
"S": qml.S(0).matrix(),
"T": qml.T(0).matrix()
}
# Apply the controlled gate controlled by all control indices to each target index
for target_index in target_indices:
self.circuit.append(
qml.ControlledQubitUnitary(
gate_mapping[gate],
control_wires=control_indices,
wires=target_index
)
)
def _parameterized_controlled_gate(self,
gate: Literal["RX", "RY", "RZ"],
angle: float,
control_indices: int | Collection[int],
target_indices: int | Collection[int]) -> None:
control_indices = [control_indices] if isinstance(control_indices, int) else control_indices
target_indices = [target_indices] if isinstance(target_indices, int) else target_indices
# Define the gate mapping for the parameterized controlled gates
gate_mapping = {
"RX": qml.RX(angle, wires=0).matrix(),
"RY": qml.RY(angle, wires=0).matrix(),
"RZ": qml.RZ(angle, wires=0).matrix(),
}
# Apply the controlled gate controlled by all control indices to each target index
for target_index in target_indices:
self.circuit.append(
qml.ControlledQubitUnitary(
gate_mapping[gate],
control_wires=control_indices,
wires=target_index
)
)
def _single_qubit_gate(self,
gate: Literal["I", "X", "Y", "Z", "H", "S", "T", "RX", "RY", "RZ"],
qubit_indices: int | Collection[int],
angle: float | None = 0) -> None:
# Define the gate mapping for the non-parameterized single qubit gates
gate_mapping = {
"I": [OpType.noop],
"X": [OpType.X],
"Y": [OpType.Y],
"Z": [OpType.Z],
"H": [OpType.H],
"S": [OpType.S],
"T": [OpType.T],
"RX": [OpType.Rx, angle/np.pi],
"RY": [OpType.Ry, angle/np.pi],
"RZ": [OpType.Rz, angle/np.pi]
}
# Apply the gate to the specified qubit(s)
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.add_gate(*gate_mapping[gate], [index])
else:
self.circuit.add_gate(*gate_mapping[gate], [qubit_indices])
import math as maths # for the UK users
def _non_parameterized_single_qubit_gate(self,
gate: Literal["I", "X", "Y", "Z", "H", "S", "T"],
qubit_indices: int | Collection[int]) -> None:
# Define the gate mapping for the non-parameterized single qubit gates
gate_mapping = {
"I": OpType.noop,
"X": OpType.X,
"Y": OpType.Y,
"Z": OpType.Z,
"H": OpType.H,
"S": OpType.S,
"T": OpType.T
}
# Apply the gate to the specified qubit(s)
if isinstance(qubit_indices, Collection):
for index in qubit_indices:
self.circuit.add_gate(gate_mapping[gate], [index])
else:
self.circuit.add_gate(gate_mapping[gate], [qubit_indices])
def _parameterized_single_qubit_gate(self,
gate: Literal["RX", "RY", "RZ"],
angle: float,
qubit_index: int) -> None:
# Define the gate mapping for the parameterized single qubit gates
gate_mapping = {
"RX": OpType.Rx,
"RY": OpType.Ry,
"RZ": OpType.Rz,
}
# Apply the gate to the specified qubit
self.circuit.add_gate(gate_mapping[gate], angle/np.pi, [qubit_index])
@delicate wren Do you think this is a good change?
I merged these two to the one above.
%homework 3 Question 4
phi_0 = 5.5e+4; % m^2s^-2 for 500hPa
f_0 = 1e-4; % coriolis parameter at 45N s^-1
U_0 = 10; % average Zonal wind, ms^-1
A = 8e+6; % Wave Amplitude
k = (pi/2)*(10^(-6)); % wavenumber m^-1
x = linspace(-4000000,4000000,1000);
y = linspace(-1000000,1000000,1000);
[X,Y] = meshgrid(x,y);
phi = phi_0 - f_0.*U_0.*Y + f_0.*A.*sin(k.*X);
subplot(1,2,1)
mesh(X,Y,phi)
subplot(1,2,2)
contour(X,Y,phi)
this was the output
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
CC
CC Fortran 77 program to integrate the linearized barotropic
CC vorticity equation at 500hPa for a single latitude, only
CC considering advection by the mean wind and ignoring all
CC variation in y:
CC
CC d/dt vort = -U*d/dx vort - beta*v
CC
CC The model is global in longitude
CC
C
parameter(nx=144) ! same as reanalysis grid
parameter(dt=60*15) ! time step (seconds)
parameter(nt=10*24*4) ! number of time steps
parameter(ntout=4) ! how many time steps to skip on output
parameter(clat=45.0) ! latitude
parameter(re=6.378E6) ! radius of Earth (meters)
parameter(rpi=3.1415926) ! Pi
parameter(omega=7.292E-5) ! angular velocity of Earth
parameter(s=4e6) ! spatial scale of initial disturbance
C
real vortold(nx),vortnew(nx),vort(nx)
real u,temp(nx)
real phi(nx),ddxphi(nx),ddxvort(nx),v(nx)
C
C set up input and output files and data
C
open(13,file="baro_1d_output.dat",status="unknown",
& access="direct",recl=4*nx)
C
C calculate grid spacing from number of grid points and latitude
C
dx=cos(clat*rpi/180.0)*2.0*rpi*re/real(nx)
f0=2.0*omega*sin(45.0*3.14159/180.0)
beta=2.0*omega*cos(45.0*3.14159/180.0)/re
C
irec=1
C
C specify value for u and for initial phi
C
u=15.0
C
do ix=1,nx
x=(ix-nx/2)*dx
gauss=exp(-x*x/(s*s))
phi(ix)=500.0*gauss*sin(10.0*2.0*rpi*real(ix-1)/real(nx))
enddo
phiav=0.0
do ix=1,nx
phiav=phiav+phi(ix)/real(nx)
enddo
do ix=1,nx
phi(ix)=phi(ix)-phiav
enddo
write(13,rec=irec)phi
irec=irec+1
C
fun times
@buoyant wolf yes
the things goes like this: ive started cs journey from last week and my college has java in the first year
is it good
tho im learning python
and how much should I know
of a language
yes absolutely
when it comes to "good" vs "not good" programming languages, they arent necessarily good/bad
a wrench isnt considered bad because you dont use it to hammer a nail
i have this alot of questions on my mind like how many languages do I have to know to work like program or code
yeah
JSON
{"data": {...}
not a language but is used/applied in every language (configuration stuff for example)
stuff like that you learn as you go
until now I am studying python i feel like i understand it really quick
is this the basics?!
I have learnt variables, functions, lists, dictionaries, objects
can i share what I have written myself?
yes for sure, any questions you have with what youve written or those concepts in the screenshot too feel free to ask
this is all what I have learnt topic wise
certainly a start
tan is better tho
whats something thats intimidating you right now that you want to know?
see if you think I won't remember math module function, it's upto you how much you use it
