-
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
refactor: Simplify some internals of qiskit_to_tk
conversion
#382
Conversation
qiskit_to_tk
and tk_to_qiskit
In fact I think its better to do the type annotations updates for the whole repo in a separate PR. Clutters the diff quite a bit. See #383 |
qiskit_to_tk
and tk_to_qiskit
qiskit_to_tk
conversion
qiskit_to_tk
conversionqiskit_to_tk
conversion
tkc.add_circuit(circuit, qubits) | ||
else: | ||
raise TypeError( | ||
"Unrecognised type of Instruction.params " |
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'm not so satisfied with this _add_state_preparataion
function. There are at least 3 different ways to create a StatePreparation
or Initialize
object. Couldn't simplify the handling all that much.
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.
Thanks, just a couple of minor suggestions.
known_optype = _known_qiskit_gate[c_gate.base_class] | ||
return known_optype |
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.
known_optype = _known_qiskit_gate[c_gate.base_class] | |
return known_optype | |
return _known_qiskit_gate[c_gate.base_class] |
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.
Done in 37de5e4
else: | ||
if isinstance(prep.params[0], complex): | ||
# convert int to a binary string and apply X for |1> | ||
integer_parameter = int(prep.params[0].real) | ||
bit_string = bin(integer_parameter)[2:] | ||
circuit = _string_to_circuit(bit_string, prep.num_qubits, qiskit_prep=prep) | ||
tkc.add_circuit(circuit, qubits) | ||
else: |
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.
Use elif
and else
here to save indentation?
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.
Thanks, done in 37de5e4
Description
This PR begins a refactor of the
qiskit_to_tk
andtk_to_qiskit
converters. Here I've focussed on refactoring some of the largeCircuitBuilder.add_qiskit_data
method (used as part ofqiskit_to_tk
into separate internal functions. I've added some short docstrings so its hopefully clearer whats going on.There's still a lot to improve in the conversion code but I think it makes sense to do this refactor in several stages to make small fixes like #366 a bit easier.
I've avoided imporvements which involve user facing changes for now. Will add these in a follow up.
Related issues
#313
Checklist