generated from CQCL/pytemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
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: Abstract WORDSIZE to specify maxwidth on qasm conversion #204
Merged
qartik
merged 5 commits into
main
from
203-incorrect-bitwidth-for-qasm-input-with-pytket-1300
Jul 16, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
90f1e25
fix: Abstract WORDSIZE to specify maxwidth on qasm conversion
qartik a979fbc
fix: generate cvar with data_type dependent on WORDSIZE
qartik bc44201
chore: update deps
qartik 2855da2
fix: fail early on WASM calls with more than 32-bit registers
qartik 414de00
fix: require pecos supporting 64-bits, emit i32/i64 cvars for compati…
qartik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2023 Quantinuum LLC All rights reserved. | ||
# Copyright (c) 2023-2024 Quantinuum LLC All rights reserved. | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file. | ||
# | ||
|
@@ -10,11 +10,17 @@ | |
|
||
import json | ||
import logging | ||
import sys | ||
from copy import deepcopy | ||
from importlib.metadata import version | ||
from typing import TYPE_CHECKING, Any, TypeAlias | ||
|
||
from typing_extensions import assert_never | ||
from pytket.qasm.qasm import QASMUnsupportedError | ||
|
||
if sys.version_info >= (3, 11): | ||
from typing import assert_never | ||
else: | ||
from typing_extensions import assert_never | ||
|
||
import pytket | ||
import pytket.circuit as tk | ||
|
@@ -45,7 +51,10 @@ | |
"version": "0.1.0", | ||
"metadata": {"source": f'pytket-phir v{version("pytket-phir").split("+")[0]}'}, | ||
} | ||
UINTMAX = 2 ** (64 if pytket.__dict__.get("bit_width_64", False) else 32) - 1 | ||
|
||
WASM_WORDSIZE = 32 | ||
WORDSIZE = 64 if pytket.__dict__.get("bit_width_64", False) else 32 | ||
UINTMAX = 2**WORDSIZE - 1 | ||
|
||
Var: TypeAlias = str | ||
Bit: TypeAlias = list[Var | int] # e.g. [c, 0] for c[0] | ||
|
@@ -477,6 +486,9 @@ def extract_wasm_args_and_returns( | |
only_args = command.args[:-slice_index] | ||
# Eliminate conditional bits from the front of the args | ||
input_args = only_args[len(only_args) - op.n_inputs :] | ||
if any(arg.index[0] >= WASM_WORDSIZE for arg in input_args): | ||
msg = "WASM support is limited to at most 32-bit registers" | ||
raise QASMUnsupportedError(msg) | ||
return ( | ||
dedupe_bits_to_registers(input_args), | ||
dedupe_bits_to_registers(command.bits), | ||
|
@@ -544,7 +556,7 @@ def get_decls(qbits: set["Qubit"], cbits: set[tkBit]) -> list[dict[str, str | in | |
decls += [ | ||
{ | ||
"data": "cvar_define", | ||
"data_type": "u32", | ||
"data_type": f"i{WORDSIZE}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing to i64 as the default as per the spec. Tested with previous version of pytket to check that i32 works as well. |
||
"variable": cvar, | ||
"size": dim, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
64-bit support added in https://github.com/PECOS-packages/PECOS/releases/tag/v0.6.0.dev2