-
Notifications
You must be signed in to change notification settings - Fork 131
Transpile parallel experiment sub circuits #680
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
Transpile parallel experiment sub circuits #680
Conversation
I think it's important to add tests that specifically check this new behavior. Especially as a safety net, for the case that someone modifies the code. |
b421bb0
to
55413ce
Compare
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 high-level comments. Overall I think 2 stage transpile is reasonable direction especially for this class since we could run into the situation where different kind of experiment instances with different run options are combined.
I'm also interested in validation of parallel circuit when component experiment contains no-adjacent qubit pairs, i.e. first transpile may inject swaps and this may conflict with another combined instance. In this case parallel experiment will be no longer helper function, indeed it may result in unexpected outcome, since this combine logic doesn't take care of equivalence of execution circuit, i.e. if there is swap circuit ahead of the experiment circuit, that will start from non-zero init state. We need to write validator, or, just limit coupling map of component experiment, i.e. base experiment.
Parallel Experiment will now transpile sub experiments according to their individual transpile options before combining them. The combined circuits will then be transpiled again according to any options set in the parallel experiment transpile options.
Update CompositeExperiment.set_transpile_options to recursively set transpile options for each of the component experiments so that these options are not ignored for batch experiments.
bbba8ee
to
fb1eaaa
Compare
mapped_qargs = [ | ||
circuit.qubits[qargs_map[sub_circ.find_bit(i).index]] for i in qargs | ||
] | ||
except KeyError as ex: |
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 remind me the discussion about coupling map for QV. Sometimes transpiler couples two qubits with swapping via ancillary qubits, this will cause a problem, for example, when sub_circ
is mapped to the non-adjacent qubits. The simplest solution to this would be automatically generate valid coupling map in the base experiments not to allow such experiment configurations, i.e. ancillary qubits should be explicitly defined in constructor argument qubits
. If you don't limit the coupling map, please implement the logic and add the test for this edge case.
class EntangleExperiment(BaseExperiment):
def __init__(qubits, backend):
super().__init__(qubits, backend=backend):
def circuits(self):
qc = QuantumCircuit(2)
qc.cx(*self.qubits)
return [qc]
backend = SomeFakeBackend() # this should be some Falcon 27Q device
exp1 = EntangleExperiment(qubits=[0, 4], backend=backend)
exp2 = EntangleExperiment(qubits=[2, 5], backend=backend) # if you set 1, 2 instead you'll run into another edge case
pexp = ParallelExperiment([exp1, exp2])
pexp.circuits() # do some validation for this.
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 independent of parallel experiment and this sort of validation should happen in base experiment for each individual component experiment.
I just tried testing something towards this but it was much more difficult than expected and ran into a lot of unexpected transpiler errors with the coupling pass, so I think this needs to be done later. The general issue is Terra does not like truncated coupling maps, it will raise a bunch of transpiler errors about CouplingError: 'coupling graph not connected'
Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
* Update ParallelExperiment to transpile sub experimetns Parallel Experiment will now transpile sub experiments according to their individual transpile options before combining them. The combined circuits will then be transpiled again according to any options set in the parallel experiment transpile options. * recursively set composite exp transpile options Update CompositeExperiment.set_transpile_options to recursively set transpile options for each of the component experiments so that these options are not ignored for batch experiments.
Summary
Parallel Experiment will now transpile sub experiments according to their individual transpile options before combining them. The combined circuits will then be transpiled again according to any options set in the parallel experiment transpile options.
Details and comments
This is applying the same logic from #667 for batch experiment to the more complicated case of parallel experiments.
This will require slight modification if #677 is merged first, or vice versa.