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 'custom' challenge, allowing users to grade custom unitaries #50

Closed
wants to merge 2 commits into from

Conversation

frankharkins
Copy link
Collaborator

@frankharkins frankharkins commented Jun 15, 2022

Changes

This PR adds the ability to create questions that check circuits have a specific unitary, without needing to make PRs to either this repo or the server repo. The question creator encrypts the target unitary using the server's public key, and the person answering their question sends the encrypted target unitary to the server along with their submission.

To do

  • Add check to limit the number of qubits

Example

  1. Question creator encrypts solution unitary:

    >>> from qiskit.circuit.random import random_circuit
    >>> from qiskit.quantum_info import Operator
    >>> from qc_grader.challenges.custom import encrypt_solution
    >>> qc = random_circuit(2, 6, seed=1)
    >>> u = Operator(qc).data
    >>> solution = encrypt_solution(u)
    
    String below describes the Python `dict` containing your encrypted unitary. Paste this as the `solution` argument into `grade_custom_unitary`:
    
    {'unitary': 'gAAAAABiqdbCUCiftiEKmr8AcFLghTYrigqhU2qlZ7WP4N8Xa-K2_dNIGpTviqtmJemYZcVFR_-i_calPwpEiW1dlm-M-sVIpMwvaMHiQlN33LStYgYOTNX67RJlaaC2LqDa7feq0VT4lN8Rs3tdY7UNYupslPPxf2I8RDfJU5dEoL5VNzwCbV_nJqUKFE-DYhvvyrO53Diuwee9tgP8EqiP_nycUkBgeIaQ2yEZ6eSTr1mTFBvmENnDO641rqrY0exEUmq44NOkf3_97GAoXsVIOsoKWj9uTEKArPzOgFS0AROkbGrhU7J6jFrzQkxObReD6A99O6Le8Obelj2uUzv76KkY5fH3qHVlQNiE9mNh2lHXVAXr6bZF3nAFYoEd_Oc5T82fxW3mxr7AUAkkls7sM80TCwyNHUuXwPFMxsreMuaX0NrS7k4=', 'key': '\x7fè·\x8d\x19\x9f`¯{\x13FhÞæ_ë\x82C\x8cçÿ\x1fñzù7~[\x04KJs[\x1eç\x13\x82ün\x86\x15\x13\x9c\x0cú£\x12ævg\x950¤q\x10¶Ù\x1có\x90u%º\x8bß\x83¿§äÜá÷úd×Ø\x95âBÅgäpºø6\x8c\x03\x13!N\x14c©G\x9d¾Ûm»\x01ï>jð\x90º\x84Ì¡4øJ\x082{\x86\x0f\x0c\x18a.ì\x91÷¹\x08E8ý\x7fNý\x84¥ü±\x11à"´q\x9ce8Ö¸#&\x95\x81å\x12\x9fÄ\r\x90cÌß^4¶\x10*ß\x0f\x04@~íe\x87on\x8ffme\x1bÁèyn\xa0\x1e<G¡ý}\x01ÿÍǬү9l¾¶#þ6ù°¨Jþ¹>üÄ\x99âØ\x00§À]\x88]\x8d¹\x8c c¡\x9bSS\x10Ð\x9e\x83?c:r\r\x7fOaÛa2\x9dÇj¤rÍ£-9'}
    
  2. The question creator can then create a function:

    from qc_grader.challenges.custom import grade_custom_unitary
    def my_grader_question(qc):
        grade_custom_unitary(
            qc,
            solution={  # This is the output of encrypt_solution(u)
                'unitary': 'gAAAAABiqdbCUCiftiEKmr8AcFLghTYrigqhU2qlZ7WP4N8Xa-K2_dNIGpTviqtmJemYZcVFR_-i_calPwpEiW1dlm-M-sVIpMwvaMHiQlN33LStYgYOTNX67RJlaaC2LqDa7feq0VT4lN8Rs3tdY7UNYupslPPxf2I8RDfJU5dEoL5VNzwCbV_nJqUKFE-DYhvvyrO53Diuwee9tgP8EqiP_nycUkBgeIaQ2yEZ6eSTr1mTFBvmENnDO641rqrY0exEUmq44NOkf3_97GAoXsVIOsoKWj9uTEKArPzOgFS0AROkbGrhU7J6jFrzQkxObReD6A99O6Le8Obelj2uUzv76KkY5fH3qHVlQNiE9mNh2lHXVAXr6bZF3nAFYoEd_Oc5T82fxW3mxr7AUAkkls7sM80TCwyNHUuXwPFMxsreMuaX0NrS7k4=',
                'key': '\x7fè·\x8d\x19\x9f`¯{\x13FhÞæ_ë\x82C\x8cçÿ\x1fñzù7~[\x04KJs[\x1eç\x13\x82ün\x86\x15\x13\x9c\x0cú£\x12ævg\x950¤q\x10¶Ù\x1có\x90u%º\x8bß\x83¿§äÜá÷úd×Ø\x95âBÅgäpºø6\x8c\x03\x13!N\x14c©G\x9d¾Ûm»\x01ï>jð\x90º\x84Ì¡4øJ\x082{\x86\x0f\x0c\x18a.ì\x91÷¹\x08E8ý\x7fNý\x84¥ü±\x11à"´q\x9ce8Ö¸#&\x95\x81å\x12\x9fÄ\r\x90cÌß^4¶\x10*ß\x0f\x04@~íe\x87on\x8ffme\x1bÁèyn\xa0\x1e<G¡ý}\x01ÿÍǬү9l¾¶#þ6ù°¨Jþ¹>üÄ\x99âØ\x00§À]\x88]\x8d¹\x8c c¡\x9bSS\x10Ð\x9e\x83?c:r\r\x7fOaÛa2\x9dÇj¤rÍ£-9'
            }
        )
    
  3. Then the student can check their answer using this new function. E.g. Using qc from before:

    >>> my_grader_question(qc)
    Grading your answer. Please wait...
    
    Congratulations 🎉! Your answer is correct.
    

Copy link

@elorrtu5746 elorrtu5746 left a comment

Choose a reason for hiding this comment

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

Thank you for this great feature, I was actually looking to create something like that myself!
I would love to see detailed documentation on how educators can use this feature to set up grading for their questions since I haven't seen anything like that.

@vabarbosa
Copy link
Collaborator

closing. the changes are out of date, but we should definitely revisit the approach in a future refactor of the grading platform

@vabarbosa vabarbosa closed this May 30, 2024
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.

3 participants