Skip to content

Conversation

chriseclectic
Copy link
Collaborator

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.

@chriseclectic chriseclectic changed the title Transpile Parallelexperiment sub circuits Transpile parallel experiment sub circuits Feb 18, 2022
@yaelbh
Copy link
Collaborator

yaelbh commented Feb 20, 2022

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.

@chriseclectic
Copy link
Collaborator Author

@yaelbh I'm going to wait until #667 and #677 are merged before making any further changes to this PR.

Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a 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.

@chriseclectic chriseclectic added this to the Release 0.3 milestone Mar 30, 2022
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.
@chriseclectic chriseclectic removed the needs review needs review label Apr 4, 2022
mapped_qargs = [
circuit.qubits[qargs_map[sub_circ.find_bit(i).index]] for i in qargs
]
except KeyError as ex:
Copy link
Collaborator

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.

Copy link
Collaborator Author

@chriseclectic chriseclectic Apr 4, 2022

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'

@chriseclectic chriseclectic merged commit 604fccc into qiskit-community:main Apr 5, 2022
@chriseclectic chriseclectic added the Changelog: New Feature Include in the "Added" section of the changelog label Apr 25, 2022
paco-ri pushed a commit to paco-ri/qiskit-experiments that referenced this pull request Jul 11, 2022
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants