Skip to content
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

Custom instruction assembly and circuit append #2173

Merged
merged 8 commits into from
Apr 27, 2019

Conversation

chriseclectic
Copy link
Member

@chriseclectic chriseclectic commented Apr 22, 2019

Summary

  • Adds assemble method to circuit Instruction that is used by assemble_circuits for constructing the QasmQobjInstruction. This can be overloaded by custom Instructions to define their own serialization.

  • Adds optional label property to Gate objects, this can be used by Aer to define different noise models on the same gate types with different labels. Standard gate definitions are unchanged however, so this label can only be use from an opaque gate def eg Gate("id", 1, label="id_cx").

  • Adds UnitaryGate circuit extension and removes Unitary from quantum_info.operators.

  • Updates Snapshot circuit extension to support general snapshot types. The monkey patch circuit.snapshot still only supports statevector though (and because of this the snapshot_type kwarg was removed from this circuit method).

  • Checks for to_instruction method when appending an object in QuantumCircuit.append. This can be used to allow objects to define their own conversion to an Instruction.

  • Defines to_instruction methods for operator objects:

    • Operator.to_instruction appends a UnitaryGate
    • Pauli.to_instruction appends a Pauli gate sequence (IdGate, XGate, YGate,ZGate) for the Pauli
    • QuantumChannel.to_instruction appends a UnitaryGate if the channel is a unitary channel, otherwise it appends an Opaque "kraus" instruction which can be directly simulator by Qiskit Aer.
  • removes loading of monkey patch function names from qiskit circuit extensions. Monkey patching is still done so these methods are still added to QuantumCircuit and CompositeGate, but the functions don't need to be in the top level namespace (I think?)

Partially closes #2162: special cases for non-standard instructions are still required for dag_to_circuit and circuit_to_dag converisons.

Details and comments

@chriseclectic chriseclectic changed the title Add UnitaryGate, Snapshot instr, and allow third party extensions with assemble_circuits [WIP] Add UnitaryGate, Snapshot instr, and allow third party extensions with assemble_circuits Apr 24, 2019
@chriseclectic chriseclectic force-pushed the circuits-assemble branch 3 times, most recently from 7ae3680 to f7c6771 Compare April 26, 2019 15:09
@chriseclectic chriseclectic changed the title [WIP] Add UnitaryGate, Snapshot instr, and allow third party extensions with assemble_circuits Custom instruction assembly and circuit append Apr 26, 2019
# If input is a BaseOperator subclass this attempts to convert
# the object to an Operator so that we can extract the underlying
# numpy matrix from `Operator.data`.
data = data.to_operator().data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like data.

@chriseclectic chriseclectic deleted the circuits-assemble branch May 8, 2019 19:57
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* add assemble method to instruction

* add optional label to Gate

* add UnitaryGate instruction

* add `to_instruction` to circuit.append

* add to_instruction to Pauli

* add to_instruction to Operator

* add to_instruction to QuantumChannel

* update Snapshot instruction

* allow other snapshots with circuit.snapshot

* add optional label to aer gate classes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework assembler to allow third-party providers to integrate their own instructions
2 participants