-
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
add azure option in result recording #189
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bd92ecc
regen QIR
cqc-melf ad9cf66
add azure option in result recording
cqc-melf 046a66a
clean up
cqc-melf 5219631
update version and chagnelog
cqc-melf 6c31a78
regen qir files
cqc-melf 011e756
Merge branch 'main' into melf/fix-resultrecording-in-base-profile
cqc-melf 614391c
Update pytket/qir/conversion/azurebaseprofileqirgenerator.py
cqc-melf 6d0b9ce
requested changes
cqc-melf 288eac9
Revert "requested changes"
cqc-melf 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__extension_version__ = "0.18.0rc0" | ||
__extension_version__ = "0.19.0" | ||
__extension_name__ = "pytket-qir" |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright 2019-2024 Quantinuum | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import pyqir | ||
|
||
from pytket.circuit import ( | ||
Bit, | ||
Circuit, | ||
Qubit, | ||
) | ||
|
||
from .baseprofileqirgenerator import ( | ||
BaseProfileQirGenerator, | ||
) | ||
from .module import tketqirModule | ||
|
||
|
||
class AzureBaseProfileQirGenerator(BaseProfileQirGenerator): | ||
"""Generate QIR from a pytket circuit.""" | ||
|
||
def __init__( | ||
self, | ||
circuit: Circuit, | ||
module: tketqirModule, | ||
wasm_int_type: int, | ||
qir_int_type: int, | ||
) -> None: | ||
|
||
super().__init__(circuit, module, wasm_int_type, qir_int_type) | ||
|
||
# void @__quantum__rt__array_record_output(result) | ||
self.record_output_array = self.module.module.add_external_function( | ||
"__quantum__rt__array_record_output", | ||
pyqir.FunctionType( | ||
pyqir.Type.void(self.module.module.context), | ||
[ | ||
self.qir_int_type, | ||
pyqir.PointerType(pyqir.IntType(self.module.module.context, 8)), | ||
], | ||
), | ||
) | ||
|
||
def conv_measure(self, bits: list[Bit], qubits: list[Qubit]) -> None: | ||
assert len(bits) == 1 | ||
assert len(qubits) == 1 | ||
|
||
def record_output(self) -> None: | ||
|
||
# this will measure all qubits at the end of the circuit | ||
# the result of the measurement will be added to an array and recorded together | ||
|
||
for i in range(len(self.circuit.qubits)): | ||
self.module.qis.mz( | ||
self.module.module.qubits[i], | ||
self.module.module.results[i], | ||
) | ||
|
||
self.module.builder.call( | ||
self.record_output_array, | ||
[ | ||
pyqir.const(self.qir_int_type, len(self.circuit.qubits)), | ||
pyqir.Constant.null( | ||
pyqir.PointerType(pyqir.IntType(self.module.module.context, 8)) | ||
), | ||
], | ||
) | ||
|
||
for i in range(len(self.circuit.qubits)): | ||
self.module.builder.call( | ||
self.record_output_res, | ||
[ | ||
self.module.module.results[i], | ||
pyqir.Constant.null( | ||
pyqir.PointerType(pyqir.IntType(self.module.module.context, 8)) | ||
), | ||
], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Copyright 2019-2024 Quantinuum | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import pyqir | ||
|
||
from pytket.circuit import ( | ||
Bit, | ||
Circuit, | ||
Qubit, | ||
) | ||
|
||
from .module import tketqirModule | ||
from .profileqirgenerator import ( | ||
AdaptiveProfileQirGenerator, | ||
) | ||
|
||
|
||
class AzureAdaptiveProfileQirGenerator(AdaptiveProfileQirGenerator): | ||
"""Generate QIR from a pytket circuit.""" | ||
|
||
def __init__( | ||
self, | ||
circuit: Circuit, | ||
module: tketqirModule, | ||
wasm_int_type: int, | ||
qir_int_type: int, | ||
trunc: bool, | ||
) -> None: | ||
|
||
super().__init__(circuit, module, wasm_int_type, qir_int_type, trunc) | ||
|
||
self.azure_sar_dict["!llvm.module.flags = !{!0, !1, !2, !3}"] = ( | ||
"!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10}" | ||
) | ||
|
||
self.azure_sar_dict[ | ||
'!3 = !{i32 1, !"dynamic_result_management", i1 false}' | ||
] = """!3 = !{i32 1, !"dynamic_result_management", i1 false} | ||
!4 = !{i32 1, !"classical_ints", i1 true} | ||
!5 = !{i32 1, !"qubit_resetting", i1 true} | ||
!6 = !{i32 1, !"classical_floats", i1 false} | ||
!7 = !{i32 1, !"backwards_branching", i1 false} | ||
!8 = !{i32 1, !"classical_fixed_points", i1 false} | ||
!9 = !{i32 1, !"user_functions", i1 false} | ||
!10 = !{i32 1, !"multiple_target_branching", i1 false}""" | ||
|
||
# void @__quantum__rt__array_record_output(result) | ||
self.record_output_array = self.module.module.add_external_function( | ||
"__quantum__rt__array_record_output", | ||
pyqir.FunctionType( | ||
pyqir.Type.void(self.module.module.context), | ||
[ | ||
self.qir_int_type, | ||
pyqir.PointerType(pyqir.IntType(self.module.module.context, 8)), | ||
], | ||
), | ||
) | ||
|
||
def conv_measure(self, bits: list[Bit], qubits: list[Qubit]) -> None: | ||
|
||
assert len(bits) == 1 | ||
assert len(qubits) == 1 | ||
|
||
qubit_index = qubits[0].index[0] | ||
|
||
self.module.qis.mz( | ||
self.module.module.qubits[qubit_index], | ||
self.module.module.results[qubit_index], | ||
) | ||
|
||
ssa_measureresult = self.module.builder.call( | ||
self.read_bit_from_result, | ||
[ | ||
self.module.module.results[qubit_index], | ||
], | ||
) | ||
|
||
self._set_bit_in_creg(bits[0].reg_name, bits[0].index[0], ssa_measureresult) | ||
|
||
def record_output(self) -> None: | ||
|
||
self.module.builder.call( | ||
self.record_output_array, | ||
[ | ||
pyqir.const(self.qir_int_type, len(self.circuit.c_registers)), | ||
pyqir.Constant.null( | ||
pyqir.PointerType(pyqir.IntType(self.module.module.context, 8)) | ||
), | ||
], | ||
) | ||
|
||
for creg in self.circuit.c_registers: | ||
reg_name = creg[0].reg_name | ||
self.module.builder.call( | ||
self.record_output_i64, | ||
[ | ||
self._get_i64_ssa_reg(reg_name), | ||
self.reg_const[reg_name], | ||
], | ||
) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
My understanding is that we don't want to do wasm for azure.
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.
I think that's a fair assumption for now at least.