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

Add random_circuit function for testing #495

Closed
ryanhill1 opened this issue Jan 19, 2023 · 8 comments
Closed

Add random_circuit function for testing #495

ryanhill1 opened this issue Jan 19, 2023 · 8 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ryanhill1
Copy link

Describe the feature you'd like
Function that generates a "random" Braket circuit. I looked through the code base and couldn't find one, but if it already exists it would be great to know where!

How would this feature be used? Please describe.
Mainly for testing purposes in projects that are built using Braket. Would be helpful for verifying coverage over all (or at least many) Braket gates/operations.

Describe alternatives you've considered
Tried converting Cirq random circuit and Qiskit random circuit objects to Braket using the qBraid transpiler, but this method, by nature, generalizes the circuit and so lacks coverage.

@mdpratt mdpratt added enhancement New feature or request help wanted Extra attention is needed labels Feb 13, 2023
@mbeach-aws
Copy link
Contributor

Hi @ryanhill1, thanks for the feature request. You're correct there is not currently a random circuit function in the SDK.

Below is some code to randomly select single-qubit gates and create a circuit. It should be possible to generalize to two-qubit gates. Would this cover your use-case?

import random
from braket.circuits import Circuit, Instruction
from braket.circuits.gates import I,X,Y,Z,H,S,Si,V,Vi,Rx,Ry,Rz, GPi,GPi2


def random_circuit(num_qubits:int, num_instructions:int) -> Circuit:
    gate_set = [I(), X(), Y(), Z(),H(),S(),Si(),V(),Vi()]
    gate_set += [Rx(0.5),Ry(0.5),Rz(0.5), GPi(0.5), GPi2(0.5)]
    
    circ = Circuit()
    for _ in range(num_instructions):
        q = random.choice(range(num_qubits))
        gate = random.choice(gate_set)
        circ.add(Instruction(gate, [q]))
    return circ

print(random_circuit(2,10))

Let me know if this works for you.

@ryanhill1
Copy link
Author

ryanhill1 commented Mar 9, 2023

@mbeach-aws Thanks for your response! Yes, for now this works. Is this feature something your team would be interested in adding? If so, I can help with a draft PR working from your single-qubit gate example above

@mbeach-aws
Copy link
Contributor

Hi @ryanhill1, I think it would actually be more useful here: https://github.com/aws-samples/amazon-braket-algorithm-library which is more focused on Braket sample code. The algorithm library is meant for exactly this type of thing where a user could quickly load up an example circuit, like random circuits.
It would also be cool if there was a notebook explaining a bit about the usefulness of random circuits, like maybe quantum volume, or benchmarking.

@christianbmadsen
Copy link
Contributor

@ryanhill1 are you still interested in drafting a PR here but in the https://github.com/aws-samples/amazon-braket-algorithm-library repository ad @mbeach-aws suggested?

@ryanhill1
Copy link
Author

Hi @christianbmadsen, thanks for reaching out! I've got my hands full at the moment getting the qBraid-SDK ready for Unitary Hack. But after the event is over and the PRs die down I'll have some time and could help with a draft 👍

But if you all had a faster turn-around in mind I'd say go for it, and I can jump back in if any help is needed.

@kshitijc kshitijc added the good first issue Good for newcomers label Sep 14, 2023
@Morcu
Copy link

Morcu commented Nov 30, 2023

Hey @christianbmadsen, @kshitijc and @mbeach-aws,

Just came across this discussion about the random circuit function for Amazon Braket. I really like the idea and I'm keen on helping out with it. The code snippet you shared, @mbeach-aws, looks like a great starting point.

Should I go ahead and open an issue in the Braket Algorithm Library repo to get things rolling? Happy to contribute and collaborate on this!

@kshitijc
Copy link
Contributor

Thanks @Morcu! That would be fantastic. Please go ahead and open the PR in the Braket algorithm library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants