-
Notifications
You must be signed in to change notification settings - Fork 22
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
clifford.py #257
Closed
AbdullahKazi500
wants to merge
1
commit into
amazon-braket:main
from
AbdullahKazi500:AbdullahKazi500-patch-4
Closed
clifford.py #257
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Tuple, Any | ||
from abc import ABC, abstractmethod | ||
import uuid | ||
import numpy as np | ||
|
||
class AbstractProgramContext(ABC): | ||
@abstractmethod | ||
def add_gate_instruction(self, gate_name: str, target: Tuple[int], *params: Any): | ||
pass | ||
|
||
class OpenQASMProgram: | ||
def __init__(self, source: str, inputs: dict): | ||
self.source = source | ||
self.inputs = inputs | ||
|
||
class GateModelTaskResult: | ||
def __init__(self, **kwargs): | ||
self.__dict__.update(kwargs) | ||
|
||
class CliffordSimulator(OpenQASMSimulator): | ||
def create_program_context(self) -> AbstractProgramContext: | ||
return CliffordProgramContext() | ||
|
||
def parse_program(self, program: OpenQASMProgram) -> AbstractProgramContext: | ||
is_file = program.source.endswith(".qasm") | ||
interpreter = Interpreter(self.create_program_context()) | ||
return interpreter.run( | ||
source=program.source, | ||
inputs=program.inputs, | ||
is_file=is_file, | ||
) | ||
|
||
class CliffordProgramContext(AbstractProgramContext): | ||
def add_gate_instruction(self, gate_name: str, target: Tuple[int], *params: Any): | ||
# Implement translation of OpenQASM instructions into Clifford simulator instructions | ||
print(f"Adding {gate_name} gate to targets {target} with params {params}") | ||
|
||
# Example usage | ||
if __name__ == "__main__": | ||
# OpenQASM Program | ||
qasm_source = """ | ||
OPENQASM 2.0; | ||
include "qelib1.inc"; | ||
qreg q[2]; | ||
h q[0]; | ||
cx q[0], q[1]; | ||
""" | ||
openqasm_program = OpenQASMProgram(source=qasm_source, inputs={}) | ||
|
||
Instantiate Clifford Simulator | ||
clifford_simulator = CliffordSimulator() | ||
|
||
Parse the OpenQASM Program | ||
program_context = clifford_simulator.parse_program(openqasm_program) | ||
|
||
Gate Instructions to Program Context | ||
program_context.add_gate_instruction("H", (0,),) # Example instruction for adding a Hadamard gate | ||
program_context.add_gate_instruction("CX", (0, 1),) # Example instruction for adding a CNOT gate |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to actually run a program; what the issue asks for is a concrete implementation of a Clifford simulator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @speller26 any tips or resources on this from a previous build that you can share I am trying to follow this paper here
https://arxiv.org/abs/2303.10788
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance, it looks like the paper you shared is for circuit cutting rather than simulation. Good examples for the latter are Stim and Qiskit's Clifford.