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

clifford.py #257

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions clifford.py
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):
Copy link
Member

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

Copy link
Author

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

Copy link
Member

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.

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