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

Gate Decomposition(#90) Added and Tested #106

Closed
wants to merge 6 commits into from

Conversation

Gmontes01
Copy link
Contributor

I implemented the asked changes in issue Gate Decomposition(#90). I added a step in the qiskit to braket converter which decomposes the qiskit circuit to a form which can be translated to braket using the built in dictionary.

The changes test and handle the prepare_state() method for preparing qubit states

    circuit = QuantumCircuit(1)
    circuit.prepare_state([1/np.sqrt(2), -1/np.sqrt(2)], 0) 
```(note that a given qubit needs to start in the 0 state for the prepare_state() method to work properly)
and tests and handles .u() gates added to qiskit circuits like in the code below

circuit = QuantumCircuit(1)
circuit.u(np.pi/2, np.pi/3, np.pi/4, 0)

and the code can decompose exponential gates like the ones listed below

operator = (Z ^ Z) - 0.1 * (X ^ I)
evo = PauliEvolutionGate(operator, time=0.2)
circuit = SuzukiTrotter().synthesize(evo)

All of these codes have their own tests added to the test_adapter.py file.

Also note the test added to test_adapter.py which checks that all standard gates are decomposed into a circuit which can be 
translated by the hardcoded dictionary.

### Details and comments
Also note that the decomposition maintains the overall phase of the circuit by correcting the phase if the decomposition ends up creating a phase shift. 
I also changed the qiskit to braket gate map to map 'u' and 'u3' to 

gates.Rz(lam),
gates.Ry(theta),
gates.Rz(phi),
gates.PhaseShift((lam + phi) * (0.5)),
gates.X(),
gates.PhaseShift((lam + phi) * (0.5)),
gates.X(),

instead of 

gates.Rz(lam),
gates.Rx(pi / 2),
gates.Rz(theta),
gates.Rx(-pi / 2),
gates.Rz(phi)

in order to prevent the global phase shift which was taking place in the later code which interfering with my testing of the adapter's handling of the 'u' gate. Also note that this change required me to change the parametric circuit conversion test and its expected value since the test checked the output of translations of the 'u' gate with an expected circuit.

Comment on lines 371 to 377
while not (
{gate.name for gate, _, _ in decomposed_circuit.data}.issubset(
translatable_gates
)
):
old_circuit = decomposed_circuit
decomposed_circuit = old_circuit.decompose()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this always guaranteed to terminate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reasonably this should terminate for circuits that are composed of standard gates, and measure/barrier instructions since the adapter passes the standard gates and paramterized circuit test.

This may pose a potential bug though if my assumption is not correct and I can mitigate it by adding a condition where if decomposing the gate does nothing then the loop breaks.

@Gmontes01 Gmontes01 closed this Jun 11, 2023
@Gmontes01 Gmontes01 deleted the master branch June 11, 2023 18:14
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.

2 participants