-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: Improved handling of controlled gates in converters #391
Conversation
else: | ||
base_tket_gate: OpType = _known_qiskit_gate[c_gate.base_gate.base_class] | ||
|
||
base_op: Op = Op.create(base_tket_gate, params) # type: ignore |
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.
Maybe I can get around this type: ignore
. Mypy doesn't seem happy with the fact that base_op
is defined on two branches.
The _get_unitary_box
function has return type Unitary1qBox | Unitary2qBox | Unitary3qBox
. Not sure if mypy is able to find out that these unitary boxes inherit from Op
.
@@ -865,6 +867,21 @@ def test_controlled_unitary_conversion() -> None: | |||
assert np.allclose(u_qc, u_tkc) | |||
|
|||
|
|||
def test_qcontrol_box_conversion_to_qiskit() -> 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.
I think I will add tests for a wider range of controlled operations
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 please.
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.
Conversion doesn't work properly for various parameterized gates. Will update the handling and add tests.
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.
@@ -865,6 +867,21 @@ def test_controlled_unitary_conversion() -> None: | |||
assert np.allclose(u_qc, u_tkc) | |||
|
|||
|
|||
def test_qcontrol_box_conversion_to_qiskit() -> 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.
Yes please.
tests/qiskit_convert_test.py
Outdated
DecomposeBoxes().apply(circ1) | ||
DecomposeBoxes().apply(circ2) | ||
assert circ1 == circ2 | ||
assert compare_unitaries(circ1.get_unitary(), circ2.get_unitary()) |
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 this check of unitary equivalence may be redundant given the previous line
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, can remove this. However, I think we should add a test that compares the unitary of the tket circuit with the unitary of the qiskit circuit (adjusted for endianness).
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.
added in 05dd936
tests/qiskit_convert_test.py
Outdated
DecomposeBoxes().apply(circ1) | ||
DecomposeBoxes().apply(circ2) | ||
assert circ1 == circ2 | ||
assert compare_unitaries(circ1.get_unitary(), circ2.get_unitary()) |
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, can remove this. However, I think we should add a test that compares the unitary of the tket circuit with the unitary of the qiskit circuit (adjusted for endianness).
Description
This PR adds support for handling the
control_state
of a controlled operation in theqiskit_to_tk
andtk_to_qiskit
converters. The control state is now handled directly instead of addingX
gates on the control qubits.I've also taken the liberty of refactoring out the "
QControlBox
building" from theCircuitBuildier.add_qiskit_data
method in the same spirit as #382I've also reworked some internals of how unitary gates are converted to and fro. Handling of controlled unitary boxes was added in #372 .
I think it'd be fairly easy to add the other direction into this PR too (see #378)(I think its best to do this separately).Original PR adding control state handling with X gates -> #118
Related issues
#378
#313
closes #178
Checklist