-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow full gates to be passed into get method of InstructionScheduleMap #5085
Conversation
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.
Hi @brosand, this looks mostly good. Could you please just add a test of this functionality to test_instruction_schedule_map
.
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.
Does add
work with a gate?
No, |
Would you mind adding this for this and other related functions so it is consistent? Maybe write a little internal helper function to convert to what you need no matter if you get a string or a gate. |
Sounds good, I can do that. |
…uleMap tests(added a corresponding test for each previous test) for gate input
struction
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.
Looks good, just a couple small suggestions.
@@ -105,7 +108,7 @@ def qubit_instructions(self, qubits: Union[int, Iterable[int]]) -> List[str]: | |||
return list(self._qubit_instructions[_to_tuple(qubits)]) | |||
return [] | |||
|
|||
def has(self, instruction: str, qubits: Union[int, Iterable[int]]) -> bool: | |||
def has(self, instruction: Union[str, Gate], qubits: Union[int, Iterable[int]]) -> bool: |
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.
Should this be a Gate
or a Instruction. Same in other places.
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.
This is a question I wanted to discuss with you. Because instructions did not have _to_matrix
functionality I only used gates for my project, but since they inherit instruction
should I just use instructions everywhere instead of Gate
? Is there any reason to limit it to just Gate
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 so because we often input measure
which is an instruction. So we should probably use Instruction
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.
switched to instructions. I am still leaving the as test_has_gate
and so on for each of the normal tests, since I test with a gate, but I assume that's fine because gates are a type of instruction that is easily accessible?
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.
Looks good.
Co-authored-by: Thomas Alexander <thomasalexander2718@gmail.com>
Seems to be failing linting as lines are too long https://dev.azure.com/qiskit-ci/qiskit-terra/_build/results?buildId=20889&view=logs&jobId=7684b0c9-af38-5400-184f-6880bd8a4dd7&j=7684b0c9-af38-5400-184f-6880bd8a4dd7&t=9d95188b-4e59-58d8-f7c4-3f1fbd4209ad, will be good to merge after these are addressed. |
Just a bit of indentation issues 😄 |
Yeah I've been unsure which linter is being used so I have to upload to see if it's right or not, but then I have to wait a while for the azure checks. Should be good now though! |
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.
Looks great, as a future reference you should be able to just use make lint
to run the linter from the root qiskit directory.
Summary
In a project on Quantum Optimal Control, I am creating a new class which inherits InstructionScheduleMap ands generates optimal pulses for target unitary operators. As a result, I need to modify the pipeline for the InstructionScheduleMap.get() function. With this change entire gates can be passed in, with their corresponding unitary matrices, and not just the name of the gate.
Details and comments
These changes are very small, just adding in an if statement to check if the instruction passed into InstructionScheduleMap is a gate or a string, and if it is a gate converting it to a string (maintaining the existing pipeline for InstructionScheduleMap). In addition, there is a slight change to lowering.py, to pass a full gate through instead of just a string.