bmqsim

package
v0.0.0-...-c9e6992 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

bmqsim

bmqsim is part of BondMachine project. It is a library and a CLI tool to produce HDL code and test benches to simulate a quantum computer on FPGA using the BondMachine architecture framework. It also provides a sotfware simulator to be used in a CPU. The installation of bmqsim is part of the standard installation of BondMachine framework. Please refer to the BondMachine quick start for the instructions.

Usage

To use the bmqsim CLI tool, you have to choose two things: the backend and the quantum algorithm to simulate. The backend creates target hardware architecture of a specific type and its flavor (the subtype as for example the only real numbers or the complex numbers flavor) if applicable. The quantum algorithm is a file containing the quantum circuit to simulate. Let's begin the latter.

Quantum algorithm

The quantum circuit is a file containing the quantum algorithm to simulate. The file is written in the the same format as the one used by the Basm assembler and has the bmq extension. The file is a sequence of instructions, each one in a line inserted in a block section. To instruct the simulator, outside the block section, you can use the %meta directive to specify the simulator metadata.

The following is an example (program.bmq) of a quantum algorithm file implementing the Bell state:

%block code1 .sequential
	qbits	q0,q1
	zero	q0,q1
	h	q0
	cx	q0,q1
%endblock

%meta bmdef global main:code1

Backend

Once you have the quantum algorithm, you can choose the backend to use. The backend creates the target hardware architecture of a specific type and flavor. The subsequent tables show the available backend and architectures types, their flavors and the relevant command line options:

Architecture type (backend) Command line option Description Flavors
Software --software-simulation Software simulator None
MatrixSeqHardcoded --build-matrix-seq-hardcoded Sequence of matrices hardcoded in the FPGA seq_hardcoded_real, seq_hardcoded_complex
MatrixSeq --build-matrix-seq Sequence of matrices in the FPGA Not yet implemented
FullHardwareHardcoded --build-full-hardware-hardcoded Full hardware with hardcoded matrices Not yet implemented

Each architecture type is associated to a different set of command line options and activates a different simulator backend. Some of the options are common to all the backends, while others are specific to a single backend. The following sections describe the possible backends and the options.

Common options

Option Description
-hw-flavor-list List the available flavors for the chosen hardware architecture.
-hw-flavor Choose the flavor of the hardware architecture.
-save-basm Save the BondMachine Assembly code for the Basm assembler.
-build-app Build the application template to use the selected hardware architecture.
-app-flavor-list List the available flavors for the chosen application template.
-app-flavor Choose the flavor of the application template.
-app-file Choose the file name of the application template.

Software simulator

The software simulator backend is used to simulate the quantum algorithm on a CPU. The program accept a json input file and produces a json output file. The following table shows the command line options specific to the software simulator:

Option Description
-software-simulation-input Choose the input file for the software simulator.
-software-simulation-output Choose the output file for the software simulator.

An example of usage of the software simulator with the Bell state algorithm previously described (program.bmq) is the following:

bmqsim --software-simulation --software-simulation-input input.json --software-simulation-output output.json program.bmq

where input.json, the input file for the software simulator, is:

{
	{"Vector":[{"Real":1,"Imag":0},{"Real":0,"Imag":0},{"Real":0,"Imag":0},{"Real":0,"Imag":0}]}
}

and output.json, the output file produced by the simulator, is:

{
	{"Vector":[{"Real":0.7071067,"Imag":0},{"Real":0,"Imag":0},{"Real":0,"Imag":0},{"Real":0.7071067,"Imag":0}]}
}

Hardcoded sequence of matrices

Loadable sequence of matrices

Full hardware with hardcoded matrices

Other options

Alongside these main options, there are other options that does not depend on the backend chosen. These options are listed in the following table:

Option Description

Examples

Documentation

Index

Constants

View Source
const (
	HLSRealBundle = uint8(0) + iota
	HLSComplexBundle
)
View Source
const (
	CPynqApiComplex = `` /* 4035-byte string literal not displayed */

)
View Source
const (
	CPynqApiReal = `` /* 1448-byte string literal not displayed */

)
View Source
const (
	CppOpenCLComplex = `` /* 8023-byte string literal not displayed */

)
View Source
const (
	CppOpenCLReal = `` /* 3886-byte string literal not displayed */

)
View Source
const (
	HLSCircuitCCComplex = `` /* 2345-byte string literal not displayed */

)
View Source
const (
	HLSCircuitCCReal = `` /* 1531-byte string literal not displayed */

)
View Source
const (
	HLSCircuitH = `#include <ap_float.h>

void circuit(unsigned int N, ap_float<32,8> *vectorState);

`
)
View Source
const (
	HLSMakefile = `` /* 227-byte string literal not displayed */

)
View Source
const (
	HLSPythonPynqComplex = `` /* 691-byte string literal not displayed */

)
View Source
const (
	HLSPythonPynqReal = `` /* 685-byte string literal not displayed */

)
View Source
const (
	HLSRunHlsTcl = `` /* 362-byte string literal not displayed */

)
View Source
const (
	PythonPynqComplex = `` /* 3322-byte string literal not displayed */

)
View Source
const (
	PythonPynqReal = `` /* 3299-byte string literal not displayed */

)
View Source
const (
	SeqHardcodedAddTreeComplex = `` /* 6660-byte string literal not displayed */

)
View Source
const (
	SeqHardcodedComplex = `` /* 4512-byte string literal not displayed */

)
View Source
const (
	SeqHardcodedReal = `` /* 3105-byte string literal not displayed */

)

Variables

View Source
var AppFlavors = map[string]string{
	"python_pynq_real":    PythonPynqReal,
	"python_pynq_complex": PythonPynqComplex,
	"c_pynqapi_real":      CPynqApiReal,
	"c_pynqapi_complex":   CPynqApiComplex,
	"cpp_opencl_real":     CppOpenCLReal,
	"cpp_opencl_complex":  CppOpenCLComplex,
}
View Source
var AppFlavorsTags = map[string][]string{
	"python_pynq_real":    {"real"},
	"python_pynq_complex": {"complex"},
	"c_pynqapi_real":      {"real"},
	"c_pynqapi_complex":   {"complex"},
	"cpp_opencl_real":     {"real"},
	"cpp_opencl_complex":  {"complex"},
}
View Source
var HLSFlavors = map[string]uint8{
	"seq_hardcoded_real":    HLSRealBundle,
	"seq_hardcoded_complex": HLSComplexBundle,
}
View Source
var HLSFlavorsTags = map[string][]string{
	"seq_hardcoded_real":    {"real"},
	"seq_hardcoded_complex": {"complex"},
}
View Source
var HardwareFlavors = map[string]string{
	"seq_hardcoded_real":            SeqHardcodedReal,
	"seq_hardcoded_complex":         SeqHardcodedComplex,
	"seq_hardcoded_addtree_complex": SeqHardcodedAddTreeComplex,
}
View Source
var HardwareFlavorsTags = map[string][]string{
	"seq_hardcoded_real":            {"real"},
	"seq_hardcoded_complex":         {"complex"},
	"seq_hardcoded_addtree_complex": {"complex"},
}

Functions

func StringInSlice

func StringInSlice(a string, list []string) bool

Types

type BmQSimulator

type BmQSimulator struct {
	Mtx     []*bmmatrix.BmMatrixSquareComplex
	Inputs  []StateArray
	Outputs []StateArray
	// contains filtered or unexported fields
}

func (*BmQSimulator) ApplyTemplate

func (sim *BmQSimulator) ApplyTemplate(mode string) (string, error)

func (*BmQSimulator) ApplyTemplateBundle

func (sim *BmQSimulator) ApplyTemplateBundle(flavor string, bundle string) error

func (*BmQSimulator) BmMatrixFromOperation

func (sim *BmQSimulator) BmMatrixFromOperation(op []*bmline.BasmLine) (*bmmatrix.BmMatrixSquareComplex, error)

func (*BmQSimulator) BmQSimulatorInit

func (sim *BmQSimulator) BmQSimulatorInit()

BmQSimulatorInit initializes the BmQSimulator

func (*BmQSimulator) Dump

func (sim *BmQSimulator) Dump() string

func (*BmQSimulator) EmitBMAPIMaps

func (sim *BmQSimulator) EmitBMAPIMaps(hwflavor string) (string, error)

func (*BmQSimulator) MatrixFromOp

func (sim *BmQSimulator) MatrixFromOp(line *bmline.BasmLine) (*bmmatrix.BmMatrixSquareComplex, error)

func (*BmQSimulator) P

func (*BmQSimulator) Phase

func (*BmQSimulator) QasmToBmMatrices

func (sim *BmQSimulator) QasmToBmMatrices(qasm *bmline.BasmBody) ([]*bmmatrix.BmMatrixSquareComplex, error)

QasmToBmMatrices converts a QASM file to a list of BmMatrixSquareComplex, the input is a BasmBody with all the metadata and the list of quantum instructions

func (*BmQSimulator) QbitsNum

func (sim *BmQSimulator) QbitsNum() int

func (*BmQSimulator) RX

func (*BmQSimulator) RY

func (*BmQSimulator) RZ

func (*BmQSimulator) RunSoftwareSimulation

func (sim *BmQSimulator) RunSoftwareSimulation() error

func (*BmQSimulator) SetDebug

func (sim *BmQSimulator) SetDebug()

func (*BmQSimulator) SetVerbose

func (sim *BmQSimulator) SetVerbose()

func (*BmQSimulator) StateSize

func (sim *BmQSimulator) StateSize() int

func (*BmQSimulator) SwapQbits

func (*BmQSimulator) VerifyConditions

func (sim *BmQSimulator) VerifyConditions(mode string) error

type IOmap

type IOmap struct {
	Assoc map[string]string
}

type StateArray

type StateArray struct {
	Vector []bmmatrix.Complex32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL