-
Notifications
You must be signed in to change notification settings - Fork 121
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
Comments
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. |
@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 |
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. |
@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? |
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. |
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! |
Thanks @Morcu! That would be fantastic. Please go ahead and open the PR in the Braket algorithm library. |
This was added to the algorithm library with amazon-braket/amazon-braket-algorithm-library#139. Thank you to @Morcu and @ykharkov for the work getting this written and merged! The An example notebook is here: |
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.
The text was updated successfully, but these errors were encountered: