# MethodError: no method matching size

**URL:** https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815
**Category:** ITensor Julia Questions
**Created:** [June 18, 2024, 9:34am UTC](https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815 "2024-06-18T09:34:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![tibidabo](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@tibidabo](https://itensor.discourse.group/u/tibidabo)
#### Post date: [June 18, 2024, 9:34am UTC](https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815/1 "2024-06-18T09:34:05Z")

</div>

Hello ITensor team,  
When constructing an MPO with OpSum, shown in the example below, I get the following error, which I do not know how to debug. I am building an pretty unusual MPO, but in the minimal example, you can see the problem appearing in a minimal MPO. Could you give me a hint what the solution might be? Thank you very much in advance.

```auto
ERROR: MethodError: no method matching size(::StaticArraysCore.SVector{16, UInt16})

```

**Minimal working example**

```julia
using ITensors

function construct_id_operator_matrix(dim_charge_basis::Int=7, dim_harmonic_basis::Int=4)
    id_harmonic = I(dim_harmonic_basis)
    id_charge = I(dim_charge_basis)
    return kron(id_harmonic, id_charge)
end

dim_harmonic_basis = 4 
dim_charge_basis = 7
num_sites = 2

ITensors.op(::OpName"ID", ::SiteType"Boson", dim_charge_basis::Int, dim_harmonic_basis::Int) = construct_id_operator_matrix(dim_charge_basis, dim_harmonic_basis)
sites = siteinds("Boson", num_sites, dim=dim_harmonic_basis*dim_charge_basis)

os = OpSum()
os += 0.5, "ID", 1
H = MPO(os, sites)

```

**My Environment**

```bash
julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

```

```bash
(@v1.10) pkg> status
Status `~/.julia/environments/v1.10/Project.toml`
  [6e4b80f9] BenchmarkTools v1.5.0
  [336ed68f] CSV v0.10.14
  [a93c6f00] DataFrames v1.6.1
  [7073ff75] IJulia v1.24.2
  [0d1a4710] ITensorMPS v0.2.4
  [9136182c] ITensors v0.6.14
  [b964fa9f] LaTeXStrings v1.3.1
  [91a5bcdd] Plots v1.40.4
  [c3e4b0f8] Pluto v0.19.42
  [92933f4c] ProgressMeter v1.10.0
  [9ff05d80] TickTock v1.3.0

```

---

<div class="post-metadata">

### Author: ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)
#### Post date: [June 18, 2024, 12:58pm UTC](https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815/2 "2024-06-18T12:58:47Z")

</div>

First, your minimal example gives me a different error ( `LoadError: MethodError: no method matching op(::OpName{:ID}, ::SiteType{Qudit}, ::Int64)`)  
Second, here is what I needed to do to get things to run

```julia
using ITensors
using LinearAlgebra: I

function construct_id_operator_matrix(dimtot::Int, dim_charge_basis::Int=7, dim_harmonic_basis::Int=4)
    @assert dimtot == dim_charge_basis*dim_harmonic_basis
    id_harmonic = I(dim_harmonic_basis)
    id_charge = I(dim_charge_basis)
    return kron(id_harmonic, id_charge)
end

dim_harmonic_basis = 4
dim_charge_basis = 7
num_sites = 2

ITensors.op(::OpName"ID", ::SiteType"Boson", dim::Int) = construct_id_operator_matrix(dim)
sites = siteinds("Boson", num_sites, dim=dim_harmonic_basis*dim_charge_basis)

os = OpSum()
os += 0.5, "ID", 1
H = MPO(os, sites)

```

You’ll probably want to pass the two quantum numbers explicitly instead

---

<div class="post-metadata">

### Author: ![tibidabo](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@tibidabo](https://itensor.discourse.group/u/tibidabo)
#### Post date: [June 18, 2024, 1:15pm UTC](https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815/3 "2024-06-18T13:15:33Z")

</div>

Thank you very much! It’s working now, as expected. Sorry for not going through the ITensors.op documentation more carefully to avoid this question.

---

<div class="post-metadata">

### Author: ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)
#### Post date: [June 18, 2024, 4:45pm UTC](https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815/4 "2024-06-18T16:45:40Z")

</div>

Also, the name of the operator defined in ITensor is `"Id"`, not `"ID"`. So if you try `"Id"` in your code it should work for any site type. (Probably we should add `"ID"` as an alias and make sure that `"Id"` is documented better.)

---

<div class="post-metadata">

### Author: ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)
#### Post date: [June 18, 2024, 5:03pm UTC](https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815/5 "2024-06-18T17:03:22Z")

</div>

`"I"` can also be used as an alternative to `"Id"`. @miles I’m not sure if we want to support `"ID"`, `"I"`, and also `"Id"`, I think `"I"` and `"Id"` are sufficient (unless `"ID"` is commonly used in certain subfields).

---

<div class="post-metadata">

### Author: ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)
#### Post date: [June 19, 2024, 1:04am UTC](https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815/6 "2024-06-19T01:04:17Z")

</div>

Agreed. Maybe it’s just a documentation issue for the most part. I did list all the site type specific operators in the docs but the generic ones may be missing.

---

<div class="post-metadata">

### Author: ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)
#### Post date: [June 29, 2024, 1:05am UTC](https://itensor.discourse.group/t/methoderror-no-method-matching-size/1815/7 "2024-06-29T01:05:07Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
