TeamGraphix / graphix

measurement-based quantum computing (MBQC) compiler and simulator
https://graphix.readthedocs.io
Apache License 2.0
60 stars 21 forks source link

Completed Parameter Implementation #68

Closed pafloxy closed 5 months ago

pafloxy commented 1 year ago

Before submitting, please check the following:

Then, please fill in below:

Context (if applicable):

Description of the change: Introduced Parameter class for providing symbolic placeholder for parameterised arguments in circuit (rotation-angles) / patterns (measurement-angles).

It is allowed to make numerical operation on the instances of the Parameter class which upadates the symbolic expression inplace, however interaction between multiple instances of the class are not allowed .

Numerical value can be assigned using Parameter.bind() method

th = Parameter('th');
np.sin(th/3)
------------------
>Out: expr = sin(th[/3])
th.bind({th:0.3})
-------------------
>Out: expr = sin(th[/3]), assignment = [ th : 0.3 ]
th.value
------------------
>Out: 0.09983341664682814

Related issue:

45

also see that checks (github actions) pass. If lint check keeps failing, try installing black==22.8.0 as behavior seems to vary across versions.

mgarnier59 commented 1 year ago

Do we validate the behaviour modification of output_nodesin pattern.pyaround line 100? I don't yet understand how it works if the output nodes are specified by the user but if it is handled by the pattern, then I fear this modification will break the code since output_nodes is built iteratively.

shinich1 commented 1 year ago

Do we validate the behaviour modification of output_nodesin pattern.pyaround line 100? I don't yet understand how it works if the output nodes are specified by the user but if it is handled by the pattern, then I fear this modification will break the code since output_nodes is built iteratively.

Thanks for pointing this out. I agreed to this change in the discussion on the issues page, but I suppose you are right, breaking change like this should be avoided. More so because we don’t need this change for the parametrised patterns to work.

mgarnier59 commented 1 year ago

Do we validate the behaviour modification of output_nodesin pattern.pyaround line 100? I don't yet understand how it works if the output nodes are specified by the user but if it is handled by the pattern, then I fear this modification will break the code since output_nodes is built iteratively.

Thanks for pointing this out. I agreed to this change in the discussion on the issues page, but I suppose you are right, breaking change like this should be avoided. More so because we don’t need this change for the parametrised patterns to work.

Maybe the error pointed out by @pafloxy could be resolved by calling the add method directly in __init__.

shinich1 commented 5 months ago

@pafloxy I accidentally deleted the target branch of this PR, sorry! what should we do with this feature? I think many of the changes I asked back when we were working on this are now likely unnecessary (sorry..) and your implementation may fit very nicely in the current version of graphix? if you feel like it, please open a PR to merge into master.

pafloxy commented 5 months ago

Hello @shinich1 , Its alright, I think it would be more convenient to rewrite it with the current version of graphix which would also be more convenient. Also we were reconsidering how we use the parameterised class for yourselves among oursleves so maybe this time we will write it in a different fashion, the Parameter class on overall might not be changed but the way it interacts with rest of graphix should be require some re-thinking based on what we decide :)