-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix ssa tracking in parser #15
Conversation
pytket_qir/parser.py
Outdated
) | ||
# WASM function call parameters. | ||
param_regs = [] | ||
instr_arg = instr.func_args[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can instr.func_args
be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK might be worth raising an exception in case. Done.
# Comparing commands as I get a type error while comparing circuits. | ||
# TypeError: unhashable type: 'instancemethod'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why? Is this a bug in pytket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not too sure. If I run the assertion on circuit equality, I have got the following error:
> assert condition_circuit == exp_condition_circuit
E AssertionError: assert [Reset q[0]; ... Reset q[0]; ] == [Reset q[0]; ... Reset q[0]; ]
E (pytest_assertion plugin: representation of details failed: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/pprint.py:176: TypeError: unhashable type: 'instancemethod'.
E Probably an object has a faulty __repr__.)
qir_test.py:269: AssertionError
However, the assertion works in the debugger and returns False
(although circuits are seemingly identical):
(Pdb) assert condition_circuit == exp_condition_circuit
*** AssertionError
(Pdb) condition_circuit == exp_condition_circuit
False
(Pdb)
But it succeeds if I compare commands explicitly.
condition_circuit_1 = condition_com_1.op.op.get_circuit() | ||
condition_circuit_1_coms = condition_circuit_1.get_commands() | ||
|
||
exp_condition_com_1 = multiple_conditionals_circuit.get_commands()[10] | ||
exp_condition_circuit_1 = exp_condition_com_1.op.op.get_circuit() | ||
exp_condition_circuit_1_coms = exp_condition_circuit_1.get_commands() | ||
|
||
non_condition_circuit_1 = Circuit(6, 6) | ||
exp_non_condition_circuit_1 = Circuit(6, 6) | ||
non_condition_circuit_1 = Circuit(6, 262) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this blow-up in circuit size (from 6 to 262) necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, otherwise I get the error that the circuit doesn't hold enough unitids.
for com in condition_circuit_1_coms:
if not isinstance(com.op, Conditional):
> non_condition_circuit_1.add_gate(com.op, com.args)
E RuntimeError: Circuit does not contain unit with id: c[257]
pytket_qir/parser.py
Outdated
) | ||
# WASM function call parameters. | ||
param_regs = [] | ||
if instr.func_args is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be the empty list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that is silly. Thanks. Done.
* Update README.md * Main (#13) * Update changelog. * Bump version. * Fix typo. * Update deps (#14) * Update changelog. * Bump version. * Fix typo. * Update changelog.rst * Update pytket. * Fix ssa tracking in parser (#15) * New test files. * New test files for combined branching and classical operations. * Logging functionality to keep track of the set registers. * Flatten registers to avoid circuits being non-simple. * A new test to interleaved branching and classical ops. * Include the case for dealing with the assignment of a WASM input register. * Better exception throw. * Create and log register for WASM input. * Better argument definiton. * A new test to mix WASM call and branching. * Keep track of new test files. * Black autoformatting. * Correct typo. * Create and store a register to hold the condition bit for branching. * Retrieve condition bit if register is in the log. * Update tests to new bit register indexation induced by flatten_registers. * Fix mypy warning. * Update fixtures to new bit indexation. * Correct assertions. * Raise an exception if argument list is empty. * Check if condition reg has previously been set. * A new test for select in a branch. * Keep track of test files. * Better layout. * Check for list emptiness. * Support rt record functions (#16) * A translation dict from pytket classical ops to pyqir. * Udpate tests and fixtures. * Transform asserts into exceptions. * More defensive programming. * Handling 0-sized registers. * Better naming. * Zero-pad if size mismatch. * Black autoformatting. * Import and use the Command type for convenience method. * Better naming. * More generic naming. * A new class to hold QIR generation functionality. * A method to discriminate registers for ops. * First integration of the circuit_to_module method. * Correct use of the new class. * Rearrange expected file to new generation order. * Black autoformatting. * Fixes to mypy warnings. * Fix mypy warnings. * More types to the parameters for WASM calls. * Fix mypy warning. * Update conftest and test files to new functionalities. * More imports to classical register arithmetic. * Get size if object is a genuine register. * Refactor function to make better use of other functionality. * Black autoformatting. * Rename and use function. * Make file name argument non-optional. * A new test to classical reg2reg arithmetic. * Black autoformatting. * Fix mypy warning. * Fix mypy warning. * Black autoformatting. * A helper function to create an ssa variable from a bit register. * Black autoformatting. * Assert bit register size. * Assert in_width variable rather than sizes. * Better import layout. * Make use of the newly defined reg2ssa_var function. * Add and update test files. * Update fixtures and tests for reg2const arithmetic. * A new import to match against set bit registers for reg2const arithmetic. * Move external logic to keep track of ssa variables set from regs into generator class. * A new class member. * New class members to keep track of set regs and ssa vars. * Better naming and use of class member. * Handle setting registers to const value. * Black autoformatting. * Add type annotation to fix mypy warning. * Fix lint and formatting warnings and errors. * New files for architectural redesign. * Remove now obsolete file. * Correct import. * Black formatting. * Integrate external functions as class methods. * Move custom exception in utils. * Update test files to new bit register initialisation. * Correct bit register initialisation. * Integrate latest pyqir release and reinstate tests on many platforms. * Remove now useless wheels. * Update pytket_qir/gatesets/base.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Singularise name. * More descriptive module name. * Black autoformatting. * More explicit emptiness checks. * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Better custom exception naming. * Expend the range of cases caught by the assertion. * Remove potentially useless type ignore. * A new enum to define size of WASM input/ouput ints. * Black autoformatting. * No need for an optional argument. * Black autoformatting. * Assert type. * Assert input/output WASM types if file is passed in. * Fix mypy warning. * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Correct emptiness check. * Handle case were the input to WASM function call is inexistent. * Define and use WASM int types. * Cast and use the bit register as a list. * Handle case when input is not present, set empty bit register. * Pass optionally newly defined WASM int type. * Black autoformat. * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Use pyqir QIR int types definition throughout. * Remove now useless folder. * Remove unused field. * Create a singleton enum to hold WASM function name. * Fix mypy warning. * Explicit union of types. * Test correct handle of no input WASMOp. * Black autoformatting. * Update to new pyqir and pytket releases. * Correct test file names. * Update dependencies and test files. * More stringent test. * Remove useless Optional types. * Complete set of test files. * Create and use a new variable to hold the types of the WASM call parameters. * Update test files. * A new method to retrieve the tag. * Functionality to handle (tagged) runtime function calls. * First test to check handling of runtime functions. * Fix merge conflicts. * Correct error name. * Remove now unnecessary files. * Remove unnecessary comment. * Ignore backed up files. * Better docstring and comment. * Better assertion and debugging commented lines removal. * If register is empty, initialise to 0 as presumably set later. * Correct test files for register initialisation to 0. * Black autoformatting. * Rebase command to target gateset if isn't present. * Clean up and indent correctly. * Define a new field for the base gateset. * Define the base gate set. * Update obsolete test. * Black autoformatting. * Add a new test file. * Fix type check error on CI. * Fix type checking error. * Update pytket_qir/gatesets/pyqir/pyqir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Comment on the behaviour of the rebase method. * Move fixture logic into test. * No need to parse the inputs. * Raise an exception if the bit register is empty. * Update to latest pytket. * Test to empty register for SetBits op. * Handle cases where ops are passed with empty registers. * A new test for empty classicalexpbox. * More imports to handle runtime functions support and tags. * A new method to retrieve tags. * Handle (tagged) runtime functions. * New tests to the runtime function support and tags. * New test files for tagged and untagged runtime functions. * Correct formatting of expected tag string. * Import to use single dispatch. * Import a type for runtime functions argument matching. * Replace assertions with predicate calls. * Handle case for local vs. constant operands. * Update tests and test files. * Import and use custom exceptions. * Support for select and zext. * Remove useless assertions. * Test for the newly supported functionality. * Black autoformatting. * Correct assertions. * Git track new test files. * Fix mypy warnings. * Delete useless file. * Attempt to fix failing test on Windows. * Black autoformatting. * Another attempt. * Another attempt. * Try to understand why wrong list retrieval in Windows. * Update to latest pytket. * Test retrieval of assigned values. * Black autoformatting. * Correct assertions. * Remove unnecessary type casting. * Black autoformatting. * Correct test to use pyqir const generation functionality. * First attempt to test the rt function generation. * Remove now obsolete file. * New tests and test files for runtime functions support. * Update dependencies and temporary use of locally built wheel. * Use the new Type type. * Define new operation parameters to support runtime functions. * More imports to generate runtime functions. * Replace imports from extensions to imports from single module. * Remove nonecessary import. * Rename and more import. * More conventional class name. * Redefinition of class attribute. * Add bits to the rebasable circuit. * No parameters for barriers. * Correct call to function and correct parameter ordering. * Return a constant type. * Correct and use defined types. * Use defined type. * Use class attribute. * Create and log ssa var for arithmetic output. * Support for runtime function generation. * Correct type. * A new parameter to pass the module from which types the gateset is defined. * Better parameter naming. * Better naming. * Better definition of naming extension. * Module handling if provided. * More imports and redefinitons. * Pass and handle module. * Correct call to function. * New custom exception and renaming. * Import redefiniton. * Update test files. * Black autoformatting. * Fix mypy warnings. * Temporary disable testing on Ubuntu and Windows until pyqir release. * Run testing on new test files. * Attempt to solve CI failure. * Another attempt. * Bypass poetry install. * New test * Define read_result instruction as a gate. * One more import to handle read_result support. * Support for read_result instruction as a copy bit. * Test to new read_result support. * Another attempt to run tests on CI. * Another try. * Another try. * New test files for read_result support. * New import for read_result support. * No parameters for CopyBits. * Support for read_result function. * A new test for read_result support. * Test run. * Revert back to published pyqir version. * Revert imports. * Better int type definitions. * Revert function arguments to right signature. * Can't be used as type. * Revert changes to old pyqir version. * Revert changes to previous pyqir version. * Update tests and test files to previous pyqir functionality. * Revert to previous testing runs. * Black autoformatting. * Remove useless wheel. * Remove unnecessary commented line. * Better naming. * Black autoformatting. Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Validation tests (#17) * Make file name argument non-optional. * A new test to classical reg2reg arithmetic. * Black autoformatting. * Fix mypy warning. * Fix mypy warning. * Black autoformatting. * A helper function to create an ssa variable from a bit register. * Black autoformatting. * Assert bit register size. * Assert in_width variable rather than sizes. * Better import layout. * Make use of the newly defined reg2ssa_var function. * Add and update test files. * Update fixtures and tests for reg2const arithmetic. * A new import to match against set bit registers for reg2const arithmetic. * Move external logic to keep track of ssa variables set from regs into generator class. * A new class member. * New class members to keep track of set regs and ssa vars. * Better naming and use of class member. * Handle setting registers to const value. * Black autoformatting. * Add type annotation to fix mypy warning. * Fix lint and formatting warnings and errors. * New files for architectural redesign. * Remove now obsolete file. * Correct import. * Black formatting. * Integrate external functions as class methods. * Move custom exception in utils. * Update test files to new bit register initialisation. * Correct bit register initialisation. * Integrate latest pyqir release and reinstate tests on many platforms. * Remove now useless wheels. * Update pytket_qir/gatesets/base.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Singularise name. * More descriptive module name. * Black autoformatting. * More explicit emptiness checks. * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Better custom exception naming. * Expend the range of cases caught by the assertion. * Remove potentially useless type ignore. * A new enum to define size of WASM input/ouput ints. * Black autoformatting. * No need for an optional argument. * Black autoformatting. * Assert type. * Assert input/output WASM types if file is passed in. * Fix mypy warning. * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Correct emptiness check. * Handle case were the input to WASM function call is inexistent. * Define and use WASM int types. * Cast and use the bit register as a list. * Handle case when input is not present, set empty bit register. * Pass optionally newly defined WASM int type. * Black autoformat. * Update pytket_qir/qir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Use pyqir QIR int types definition throughout. * Remove now useless folder. * Remove unused field. * Create a singleton enum to hold WASM function name. * Fix mypy warning. * Explicit union of types. * Test correct handle of no input WASMOp. * Black autoformatting. * Update to new pyqir and pytket releases. * Correct test file names. * Update dependencies and test files. * More stringent test. * Remove useless Optional types. * Complete set of test files. * Create and use a new variable to hold the types of the WASM call parameters. * Update test files. * A new method to retrieve the tag. * Functionality to handle (tagged) runtime function calls. * First test to check handling of runtime functions. * Fix merge conflicts. * Correct error name. * Remove now unnecessary files. * Remove unnecessary comment. * Ignore backed up files. * Better docstring and comment. * Better assertion and debugging commented lines removal. * If register is empty, initialise to 0 as presumably set later. * Correct test files for register initialisation to 0. * Black autoformatting. * Rebase command to target gateset if isn't present. * Clean up and indent correctly. * Define a new field for the base gateset. * Define the base gate set. * Update obsolete test. * Black autoformatting. * Add a new test file. * Fix type check error on CI. * Fix type checking error. * Update pytket_qir/gatesets/pyqir/pyqir.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Comment on the behaviour of the rebase method. * Move fixture logic into test. * No need to parse the inputs. * Raise an exception if the bit register is empty. * Update to latest pytket. * Test to empty register for SetBits op. * Handle cases where ops are passed with empty registers. * A new test for empty classicalexpbox. * More imports to handle runtime functions support and tags. * A new method to retrieve tags. * Handle (tagged) runtime functions. * New tests to the runtime function support and tags. * New test files for tagged and untagged runtime functions. * Correct formatting of expected tag string. * Import to use single dispatch. * Import a type for runtime functions argument matching. * Replace assertions with predicate calls. * Handle case for local vs. constant operands. * Update tests and test files. * Import and use custom exceptions. * Support for select and zext. * Remove useless assertions. * Test for the newly supported functionality. * Black autoformatting. * Correct assertions. * Git track new test files. * Fix mypy warnings. * Delete useless file. * Attempt to fix failing test on Windows. * Black autoformatting. * Another attempt. * Another attempt. * Try to understand why wrong list retrieval in Windows. * Update to latest pytket. * Test retrieval of assigned values. * Black autoformatting. * Correct assertions. * Remove unnecessary type casting. * Black autoformatting. * Correct test to use pyqir const generation functionality. * First attempt to test the rt function generation. * Remove now obsolete file. * New tests and test files for runtime functions support. * Update dependencies and temporary use of locally built wheel. * Use the new Type type. * Define new operation parameters to support runtime functions. * More imports to generate runtime functions. * Replace imports from extensions to imports from single module. * Remove nonecessary import. * Rename and more import. * More conventional class name. * Redefinition of class attribute. * Add bits to the rebasable circuit. * No parameters for barriers. * Correct call to function and correct parameter ordering. * Return a constant type. * Correct and use defined types. * Use defined type. * Use class attribute. * Create and log ssa var for arithmetic output. * Support for runtime function generation. * Correct type. * A new parameter to pass the module from which types the gateset is defined. * Better parameter naming. * Better naming. * Better definition of naming extension. * Module handling if provided. * More imports and redefinitons. * Pass and handle module. * Correct call to function. * New custom exception and renaming. * Import redefiniton. * Update test files. * Black autoformatting. * Fix mypy warnings. * Temporary disable testing on Ubuntu and Windows until pyqir release. * Run testing on new test files. * Attempt to solve CI failure. * Another attempt. * Bypass poetry install. * New test * Define read_result instruction as a gate. * One more import to handle read_result support. * Support for read_result instruction as a copy bit. * Test to new read_result support. * Another attempt to run tests on CI. * Another try. * Another try. * New test files for read_result support. * New import for read_result support. * No parameters for CopyBits. * Support for read_result function. * A new test for read_result support. * Test run. * Revert back to published pyqir version. * Revert imports. * Better int type definitions. * Revert function arguments to right signature. * Can't be used as type. * Revert changes to old pyqir version. * Revert changes to previous pyqir version. * Update tests and test files to previous pyqir functionality. * Revert to previous testing runs. * Black autoformatting. * A new test file for round trip validation. * Check if condition variable as been locally set and use more generic if_ construct. * Simplify gate retrieval and call. * More imports for better condition expressions. * More types to support parsing. * Correct and log register for read_result support. * Better naming. * Avoid flattening registers as a bypass to non-simplicity of circbox. * Simplify and correct use of condition register. * Branching and return terminators as noops. * Update tests. * Validation test against a QIR program that targets base profile. * Black autoformatting. * Fix lint warnings. * Run new validation tests. * Fix incorrect naming. * Correct naming. * Correct type ignore. * Delete binary wheel * Handle parametrised gates. * Correct pattern and cast types. * Better type casting. * Define and use a new custom error. * Set data appropriately as function of the runtime type. * Better import layout. * Update test to new tag. * A new test to check validity on raw and optimised circuit. * New test files. * Fix mypy warnings. * Remove unnecessary branching. * Remove unnecessary error raise. * Address issue for further dev work. Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> * Handle conditionals (#19) * Update dependencies. * Define a new custom error for non-simplicity of circuits. * For better conditional expressions. * Read_result isntruction only stores the reg for the ssa variable. * Better naming. * Better naming. * Handle conditional circuits for measurement conditions. * Handle jump condition. * Return the circuit and the log of ssa registers for conditionals. * Update tests. * Attach the set_cregs log to the circuit output. * Extend the canonical register, log the condition bit and add CopyBit op. * Create a subcircuit with equal number of bits from the current circuit. * Get the condition bit from the log * Check and add extra bits from the subcircuit. * Black autoformatting. * Getting bits from the current target circuit. * Better naming. * Better naming. * Useless import. * Better comment. * Better class member name. * The else condition is resuming the flow of the main circuit to maintain CFG structure. * Update tests. * Raise an error for unsupported rutime function. * In if/else configuration, jump instructions are no-ops. * Update tests and add RUS validation test. * Add test files for RUS validation test. * Fixtures for the cfg analyser tests. * A new module to define a CFG analyser. * Git track test files for new module. * Tests for the new CFG analyser module. * Include tests for the CFG analyser. * More test files for CFG tests. * A new field to hold the condition value if any. * Set the visited field appropriately. * Get and use the current block instance. * Better comments and dicstrings. * Functionality to insert trivial blocks when dual condition is not present. * Update fixtures and tests to new insertion functionality. * Remove useless method. * Add test files. * Refactor the QIR parser and tests to new architectural design. * Module renaming. * Delete now obsolete files. * Better import ordering. * Correct argument passing. * Remove obsolete functionality. * Needed imports for moved tests. * Update tests to new and removed functionality. * Update fixtures. * Define a custom exceptin for the converter. * Update converter and tests for use with optimisation pass. * Update conftest. * Temporary disable validation tests. * Correct import. * Add test files. * More test files. * Fix lint warnings. * Fix type checking warnings. * Code clean up. * Better docstrings and comments. * Refactor to make use of correct data structures. * Better docstring. * More imports to QIR generation. * More imports to QIR generation. * Set the dual mode for the QirConverter from and to QIR. * Better docstring and functionality to create unique bit when a SSA var is created. * Add functionality to convert circuit to QIR. * More functionality for circuit to QIR conversion. * Conversion logic has moved to converter module. * Imports to support circuit to QIR conversion. * A translating dict from few pytket bitwise ops to LLVM instructions. * Better docstring. * Correct type hint. * Correct type hint. * Casting types to fix type checking warnings. * Better syntax. * A method to convert a negated bit to an LLVM xor. * Source an SSA variable with a bit if not already defined else a const. * A method to parse recursively the guard logical expression and convert to LLVM instructions. * A method to populate a pyqir module with a circuit. * Better type casting. * Better layout and syntax. * A method to convert a single circuit command to a LLVM instruction. * Update tests to new functionality. * Fix failing tests. * Functional tests. * Commit new test files. * Store the last created ssa variable as condition for next circuit. * Refactor the parser for more logical parsing. * Use the last created ssa variable as condition. * Correct test files. * Fix type warnings and black autoformatting. * Fix type checking warning. * More tests to logical expressions and unskip WASM generation ones. * Update changelog. * Bump pytket_qir version. --------- Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com>
This PR addresses the addition of logging functionality for ssa variables (registers) created and used in branches operations. It also checks for cases where
select
are used in branches where inputs are defined outside the scope of the branch.
Lastly, it provides support for the
__quantum__qir__read_result
function.